Commit ea40d1c02e61ff90bba1e8a8218f50eed111282b
1 parent
479ac9ab
Exists in
master
and in
9 other branches
Improved reindex tests
Showing
2 changed files
with
85 additions
and
71 deletions
Show diff stats
test/callbacks_test.rb
@@ -1,59 +0,0 @@ | @@ -1,59 +0,0 @@ | ||
1 | -require_relative "test_helper" | ||
2 | - | ||
3 | -class CallbacksTest < Minitest::Test | ||
4 | - def test_true_create | ||
5 | - Searchkick.callbacks(true) do | ||
6 | - store_names ["Product A", "Product B"] | ||
7 | - end | ||
8 | - Product.searchkick_index.refresh | ||
9 | - assert_search "product", ["Product A", "Product B"] | ||
10 | - end | ||
11 | - | ||
12 | - def test_false_create | ||
13 | - Searchkick.callbacks(false) do | ||
14 | - store_names ["Product A", "Product B"] | ||
15 | - end | ||
16 | - Product.searchkick_index.refresh | ||
17 | - assert_search "product", [] | ||
18 | - end | ||
19 | - | ||
20 | - def test_bulk_create | ||
21 | - Searchkick.callbacks(:bulk) do | ||
22 | - store_names ["Product A", "Product B"] | ||
23 | - end | ||
24 | - Product.searchkick_index.refresh | ||
25 | - assert_search "product", ["Product A", "Product B"] | ||
26 | - end | ||
27 | - | ||
28 | - def test_queue | ||
29 | - skip unless defined?(ActiveJob) && defined?(Redis) | ||
30 | - | ||
31 | - reindex_queue = Product.searchkick_index.reindex_queue | ||
32 | - reindex_queue.clear | ||
33 | - | ||
34 | - Searchkick.callbacks(:queue) do | ||
35 | - store_names ["Product A", "Product B"] | ||
36 | - end | ||
37 | - Product.searchkick_index.refresh | ||
38 | - assert_search "product", [], load: false, conversions: false | ||
39 | - assert_equal 2, reindex_queue.length | ||
40 | - | ||
41 | - Searchkick::ProcessQueueJob.perform_later(class_name: "Product") | ||
42 | - Product.searchkick_index.refresh | ||
43 | - assert_search "product", ["Product A", "Product B"], load: false | ||
44 | - assert_equal 0, reindex_queue.length | ||
45 | - | ||
46 | - Searchkick.callbacks(:queue) do | ||
47 | - Product.where(name: "Product B").destroy_all | ||
48 | - Product.create!(name: "Product C") | ||
49 | - end | ||
50 | - Product.searchkick_index.refresh | ||
51 | - assert_search "product", ["Product A", "Product B"], load: false | ||
52 | - assert_equal 2, reindex_queue.length | ||
53 | - | ||
54 | - Searchkick::ProcessQueueJob.perform_later(class_name: "Product") | ||
55 | - Product.searchkick_index.refresh | ||
56 | - assert_search "product", ["Product A", "Product C"], load: false | ||
57 | - assert_equal 0, reindex_queue.length | ||
58 | - end | ||
59 | -end |
test/reindex_test.rb
1 | require_relative "test_helper" | 1 | require_relative "test_helper" |
2 | 2 | ||
3 | class ReindexTest < Minitest::Test | 3 | class ReindexTest < Minitest::Test |
4 | - def setup | ||
5 | - super | ||
6 | - Sku.destroy_all | 4 | + def test_record_inline |
5 | + Searchkick.callbacks(false) do | ||
6 | + store_names ["Product A", "Product B"] | ||
7 | + end | ||
8 | + assert_search "product", [] | ||
9 | + product = Product.find_by(name: "Product A") | ||
10 | + product.reindex(refresh: true) | ||
11 | + assert_search "product", ["Product A"] | ||
7 | end | 12 | end |
8 | 13 | ||
9 | - def test_scoped | 14 | + def test_record_async |
15 | + Searchkick.callbacks(false) do | ||
16 | + store_names ["Product A", "Product B"] | ||
17 | + end | ||
18 | + assert_search "product", [] | ||
19 | + product = Product.find_by(name: "Product A") | ||
20 | + product.reindex(mode: :async) | ||
21 | + Product.search_index.refresh | ||
22 | + assert_search "product", ["Product A"] | ||
23 | + end | ||
24 | + | ||
25 | + def test_record_queue | ||
26 | + skip unless defined?(ActiveJob) && defined?(Redis) | ||
27 | + | ||
28 | + reindex_queue = Product.searchkick_index.reindex_queue | ||
29 | + reindex_queue.clear | ||
30 | + | ||
31 | + Searchkick.callbacks(:queue) do | ||
32 | + store_names ["Product A", "Product B"] | ||
33 | + end | ||
34 | + Product.searchkick_index.refresh | ||
35 | + assert_search "product", [], load: false, conversions: false | ||
36 | + assert_equal 2, reindex_queue.length | ||
37 | + | ||
38 | + Searchkick::ProcessQueueJob.perform_later(class_name: "Product") | ||
39 | + Product.searchkick_index.refresh | ||
40 | + assert_search "product", ["Product A", "Product B"], load: false | ||
41 | + assert_equal 0, reindex_queue.length | ||
42 | + | ||
43 | + Searchkick.callbacks(:queue) do | ||
44 | + Product.where(name: "Product B").destroy_all | ||
45 | + Product.create!(name: "Product C") | ||
46 | + end | ||
47 | + Product.searchkick_index.refresh | ||
48 | + assert_search "product", ["Product A", "Product B"], load: false | ||
49 | + assert_equal 2, reindex_queue.length | ||
50 | + | ||
51 | + Searchkick::ProcessQueueJob.perform_later(class_name: "Product") | ||
52 | + Product.searchkick_index.refresh | ||
53 | + assert_search "product", ["Product A", "Product C"], load: false | ||
54 | + assert_equal 0, reindex_queue.length | ||
55 | + end | ||
56 | + | ||
57 | + def test_relation_inline | ||
10 | skip if nobrainer? || cequel? | 58 | skip if nobrainer? || cequel? |
11 | 59 | ||
12 | store_names ["Product A"] | 60 | store_names ["Product A"] |
@@ -17,7 +65,7 @@ class ReindexTest < Minitest::Test | @@ -17,7 +65,7 @@ class ReindexTest < Minitest::Test | ||
17 | assert_search "product", ["Product A", "Product B"] | 65 | assert_search "product", ["Product A", "Product B"] |
18 | end | 66 | end |
19 | 67 | ||
20 | - def test_associations | 68 | + def test_relation_associations |
21 | skip if nobrainer? || cequel? | 69 | skip if nobrainer? || cequel? |
22 | 70 | ||
23 | store_names ["Product A"] | 71 | store_names ["Product A"] |
@@ -27,7 +75,15 @@ class ReindexTest < Minitest::Test | @@ -27,7 +75,15 @@ class ReindexTest < Minitest::Test | ||
27 | assert_search "product", ["Product A", "Product B"] | 75 | assert_search "product", ["Product A", "Product B"] |
28 | end | 76 | end |
29 | 77 | ||
30 | - def test_async | 78 | + def test_relation_async |
79 | + skip "Not available yet" | ||
80 | + end | ||
81 | + | ||
82 | + def test_relation_queue | ||
83 | + skip "Not available yet" | ||
84 | + end | ||
85 | + | ||
86 | + def test_full_async | ||
31 | skip unless defined?(ActiveJob) | 87 | skip unless defined?(ActiveJob) |
32 | 88 | ||
33 | Searchkick.callbacks(false) do | 89 | Searchkick.callbacks(false) do |
@@ -48,7 +104,7 @@ class ReindexTest < Minitest::Test | @@ -48,7 +104,7 @@ class ReindexTest < Minitest::Test | ||
48 | assert_search "product", ["Product A"] | 104 | assert_search "product", ["Product A"] |
49 | end | 105 | end |
50 | 106 | ||
51 | - def test_async_wait | 107 | + def test_full_async_wait |
52 | skip unless defined?(ActiveJob) && defined?(Redis) | 108 | skip unless defined?(ActiveJob) && defined?(Redis) |
53 | 109 | ||
54 | Searchkick.callbacks(false) do | 110 | Searchkick.callbacks(false) do |
@@ -62,7 +118,7 @@ class ReindexTest < Minitest::Test | @@ -62,7 +118,7 @@ class ReindexTest < Minitest::Test | ||
62 | assert_search "product", ["Product A"] | 118 | assert_search "product", ["Product A"] |
63 | end | 119 | end |
64 | 120 | ||
65 | - def test_async_non_integer_pk | 121 | + def test_full_async_non_integer_pk |
66 | skip unless defined?(ActiveJob) | 122 | skip unless defined?(ActiveJob) |
67 | 123 | ||
68 | Sku.create(id: SecureRandom.hex, name: "Test") | 124 | Sku.create(id: SecureRandom.hex, name: "Test") |
@@ -72,9 +128,11 @@ class ReindexTest < Minitest::Test | @@ -72,9 +128,11 @@ class ReindexTest < Minitest::Test | ||
72 | index = Searchkick::Index.new(reindex[:index_name]) | 128 | index = Searchkick::Index.new(reindex[:index_name]) |
73 | index.refresh | 129 | index.refresh |
74 | assert_equal 1, index.total_docs | 130 | assert_equal 1, index.total_docs |
131 | + ensure | ||
132 | + Sku.destroy_all | ||
75 | end | 133 | end |
76 | 134 | ||
77 | - def test_refresh_interval | 135 | + def test_full_refresh_interval |
78 | reindex = Product.reindex(refresh_interval: "30s", async: true, import: false) | 136 | reindex = Product.reindex(refresh_interval: "30s", async: true, import: false) |
79 | index = Searchkick::Index.new(reindex[:index_name]) | 137 | index = Searchkick::Index.new(reindex[:index_name]) |
80 | assert_nil Product.search_index.refresh_interval | 138 | assert_nil Product.search_index.refresh_interval |
@@ -85,17 +143,32 @@ class ReindexTest < Minitest::Test | @@ -85,17 +143,32 @@ class ReindexTest < Minitest::Test | ||
85 | assert_equal "1s", Product.search_index.refresh_interval | 143 | assert_equal "1s", Product.search_index.refresh_interval |
86 | end | 144 | end |
87 | 145 | ||
88 | - def test_resume | 146 | + def test_full_resume |
89 | assert Product.reindex(resume: true) | 147 | assert Product.reindex(resume: true) |
90 | end | 148 | end |
91 | 149 | ||
92 | - def test_refresh_full_reindex | 150 | + def test_full_refresh |
93 | Product.reindex(refresh: true) | 151 | Product.reindex(refresh: true) |
94 | end | 152 | end |
95 | 153 | ||
96 | - def test_partial_async | 154 | + def test_full_partial_async |
97 | store_names ["Product A"] | 155 | store_names ["Product A"] |
98 | # warn for now | 156 | # warn for now |
99 | Product.reindex(:search_name, async: true) | 157 | Product.reindex(:search_name, async: true) |
100 | end | 158 | end |
159 | + | ||
160 | + def test_callbacks_false | ||
161 | + Searchkick.callbacks(false) do | ||
162 | + store_names ["Product A", "Product B"] | ||
163 | + end | ||
164 | + assert_search "product", [] | ||
165 | + end | ||
166 | + | ||
167 | + def test_callbacks_bulk | ||
168 | + Searchkick.callbacks(:bulk) do | ||
169 | + store_names ["Product A", "Product B"] | ||
170 | + end | ||
171 | + Product.search_index.refresh | ||
172 | + assert_search "product", ["Product A", "Product B"] | ||
173 | + end | ||
101 | end | 174 | end |