Commit 5f9515a4271813906d95a3ee92e03fa34aa9d585
1 parent
ea40d1c0
Exists in
master
and in
9 other branches
Better queue test [skip ci]
Showing
1 changed file
with
43 additions
and
20 deletions
Show diff stats
test/reindex_test.rb
... | ... | @@ -6,6 +6,7 @@ class ReindexTest < Minitest::Test |
6 | 6 | store_names ["Product A", "Product B"] |
7 | 7 | end |
8 | 8 | assert_search "product", [] |
9 | + | |
9 | 10 | product = Product.find_by(name: "Product A") |
10 | 11 | product.reindex(refresh: true) |
11 | 12 | assert_search "product", ["Product A"] |
... | ... | @@ -16,6 +17,7 @@ class ReindexTest < Minitest::Test |
16 | 17 | store_names ["Product A", "Product B"] |
17 | 18 | end |
18 | 19 | assert_search "product", [] |
20 | + | |
19 | 21 | product = Product.find_by(name: "Product A") |
20 | 22 | product.reindex(mode: :async) |
21 | 23 | Product.search_index.refresh |
... | ... | @@ -28,30 +30,19 @@ class ReindexTest < Minitest::Test |
28 | 30 | reindex_queue = Product.searchkick_index.reindex_queue |
29 | 31 | reindex_queue.clear |
30 | 32 | |
31 | - Searchkick.callbacks(:queue) do | |
33 | + Searchkick.callbacks(false) do | |
32 | 34 | store_names ["Product A", "Product B"] |
33 | 35 | 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 | |
36 | + assert_search "product", [] | |
42 | 37 | |
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 | |
38 | + product = Product.find_by(name: "Product A") | |
39 | + product.reindex(mode: :queue) | |
40 | + Product.search_index.refresh | |
41 | + assert_search "product", [] | |
50 | 42 | |
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 | |
43 | + Searchkick::ProcessQueueJob.perform_now(class_name: "Product") | |
44 | + Product.search_index.refresh | |
45 | + assert_search "product", ["Product A"] | |
55 | 46 | end |
56 | 47 | |
57 | 48 | def test_relation_inline |
... | ... | @@ -171,4 +162,36 @@ class ReindexTest < Minitest::Test |
171 | 162 | Product.search_index.refresh |
172 | 163 | assert_search "product", ["Product A", "Product B"] |
173 | 164 | end |
165 | + | |
166 | + def test_callbacks_queue | |
167 | + skip unless defined?(ActiveJob) && defined?(Redis) | |
168 | + | |
169 | + reindex_queue = Product.searchkick_index.reindex_queue | |
170 | + reindex_queue.clear | |
171 | + | |
172 | + Searchkick.callbacks(:queue) do | |
173 | + store_names ["Product A", "Product B"] | |
174 | + end | |
175 | + Product.searchkick_index.refresh | |
176 | + assert_search "product", [], load: false, conversions: false | |
177 | + assert_equal 2, reindex_queue.length | |
178 | + | |
179 | + Searchkick::ProcessQueueJob.perform_later(class_name: "Product") | |
180 | + Product.searchkick_index.refresh | |
181 | + assert_search "product", ["Product A", "Product B"], load: false | |
182 | + assert_equal 0, reindex_queue.length | |
183 | + | |
184 | + Searchkick.callbacks(:queue) do | |
185 | + Product.where(name: "Product B").destroy_all | |
186 | + Product.create!(name: "Product C") | |
187 | + end | |
188 | + Product.searchkick_index.refresh | |
189 | + assert_search "product", ["Product A", "Product B"], load: false | |
190 | + assert_equal 2, reindex_queue.length | |
191 | + | |
192 | + Searchkick::ProcessQueueJob.perform_later(class_name: "Product") | |
193 | + Product.searchkick_index.refresh | |
194 | + assert_search "product", ["Product A", "Product C"], load: false | |
195 | + assert_equal 0, reindex_queue.length | |
196 | + end | |
174 | 197 | end | ... | ... |