Skip to content

Commit 2ac50b8

Browse files
bors[bot]curquiza
andauthored
Merge #148
148: Integrate wait_for_pending_update in test suite r=curquiza a=curquiza Remove all the `sleep` methods in test suite, and replace them by `wait_for_pending_update` that makes sure the task is over and make the test suite synchronous 🎉 Should be merged after #145 Co-authored-by: Clémentine Urquizar <[email protected]>
2 parents 71b042a + 3e360e9 commit 2ac50b8

15 files changed

+102
-101
lines changed

spec/meilisearch/index/documents_spec.rb

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
response = index.add_documents(documents)
3232
expect(response).to be_a(Hash)
3333
expect(response).to have_key('updateId')
34-
sleep(0.2)
34+
index.wait_for_pending_update(response['updateId'])
3535
expect(index.documents.count).to eq(documents.count)
3636
end
3737

@@ -45,10 +45,11 @@
4545
end
4646

4747
it 'create the index during document addition' do
48-
response = @client.index('newIndex').add_documents(documents)
48+
new_index = @client.index('newIndex')
49+
response = new_index.add_documents(documents)
4950
expect(response).to be_a(Hash)
5051
expect(response).to have_key('updateId')
51-
sleep(0.2)
52+
new_index.wait_for_pending_update(response['updateId'])
5253
expect(@client.index('newIndex').fetch_primary_key).to eq('objectId')
5354
expect(@client.index('newIndex').documents.count).to eq(documents.count)
5455
end
@@ -88,7 +89,7 @@
8889
response = index.update_documents(updated_documents)
8990
expect(response).to be_a(Hash)
9091
expect(response).to have_key('updateId')
91-
sleep(0.1)
92+
index.wait_for_pending_update(response['updateId'])
9293
doc1 = index.document(id1)
9394
doc2 = index.document(id2)
9495
expect(index.documents.count).to eq(documents.count)
@@ -102,7 +103,7 @@
102103
id = 123
103104
updated_document = { objectId: id, title: 'Emma' }
104105
response = index.update_documents(updated_document)
105-
sleep(0.1)
106+
index.wait_for_pending_update(response['updateId'])
106107
expect(response).to be_a(Hash)
107108
expect(response).to have_key('updateId')
108109
expect(index.documents.count).to eq(documents.count)
@@ -116,20 +117,20 @@
116117
title = 'Hamlet'
117118
new_doc = { objectId: id, title: title }
118119
response = index.add_documents(new_doc)
119-
sleep(0.1)
120+
index.wait_for_pending_update(response['updateId'])
120121
expect(response).to be_a(Hash)
121122
expect(response).to have_key('updateId')
122123
expect(index.documents.count).to eq(documents.count + 1)
123124
expect(index.document(id)['title']).to eq(title)
124-
index.delete_document(id)
125-
sleep(0.1)
125+
response = index.delete_document(id)
126+
index.wait_for_pending_update(response['updateId'])
126127
end
127128

128129
it 'update a document with new fields' do
129130
id = 2
130131
doc = { objectId: id, note: '8/10' }
131132
response = index.update_documents(doc)
132-
sleep(0.1)
133+
index.wait_for_pending_update(response['updateId'])
133134
expect(response).to be_a(Hash)
134135
expect(response).to have_key('updateId')
135136
expect(index.documents.count).to eq(documents.count)
@@ -144,7 +145,7 @@
144145
response = index.replace_documents(objectId: id, title: 'Pride & Prejudice', note: '8.5/10')
145146
expect(response).to be_a(Hash)
146147
expect(response).to have_key('updateId')
147-
sleep(0.1)
148+
index.wait_for_pending_update(response['updateId'])
148149
expect(index.documents.count).to eq(documents.count)
149150
doc = index.document(id)
150151
expect(doc['title']).to eq(new_title)
@@ -155,7 +156,7 @@
155156
it 'deletes one document from index' do
156157
id = 456
157158
response = index.delete_document(id)
158-
sleep(0.1)
159+
index.wait_for_pending_update(response['updateId'])
159160
expect(response).to be_a(Hash)
160161
expect(response).to have_key('updateId')
161162
expect(index.documents.size).to eq(documents.count - 1)
@@ -165,7 +166,7 @@
165166
it 'does nothing when trying to delete a document which does not exist' do
166167
id = 111
167168
response = index.delete_document(id)
168-
sleep(0.1)
169+
index.wait_for_pending_update(response['updateId'])
169170
expect(response).to be_a(Hash)
170171
expect(response).to have_key('updateId')
171172
expect(index.documents.size).to eq(documents.count - 1)
@@ -175,7 +176,7 @@
175176
it 'deletes one document from index (with delete-batch route)' do
176177
id = 2
177178
response = index.delete_documents(id)
178-
sleep(0.1)
179+
index.wait_for_pending_update(response['updateId'])
179180
expect(response).to be_a(Hash)
180181
expect(response).to have_key('updateId')
181182
expect(index.documents.size).to eq(documents.count - 2)
@@ -185,7 +186,7 @@
185186
it 'deletes one document from index (with delete-batch route as an array of one uid)' do
186187
id = 123
187188
response = index.delete_documents([id])
188-
sleep(0.1)
189+
index.wait_for_pending_update(response['updateId'])
189190
expect(response).to be_a(Hash)
190191
expect(response).to have_key('updateId')
191192
expect(index.documents.size).to eq(documents.count - 3)
@@ -195,31 +196,31 @@
195196
it 'deletes multiples documents from index' do
196197
docs_to_delete = [1, 4]
197198
response = index.delete_documents(docs_to_delete)
198-
sleep(0.1)
199+
index.wait_for_pending_update(response['updateId'])
199200
expect(response).to be_a(Hash)
200201
expect(response).to have_key('updateId')
201202
expect(index.documents.size).to eq(documents.count - 3 - docs_to_delete.count)
202203
end
203204

204205
it 'clears all documents from index' do
205206
response = index.delete_all_documents
206-
sleep(0.1)
207+
index.wait_for_pending_update(response['updateId'])
207208
expect(response).to be_a(Hash)
208209
expect(response).to have_key('updateId')
209210
expect(index.documents).to be_empty
210211
expect(index.documents.size).to eq(0)
211212
end
212213

213214
it 'fails to add document with bad primary-key format' do
214-
res = index.add_documents(objectId: 'toto et titi', title: 'Unknown')
215-
sleep(0.1)
216-
expect(index.get_update_status(res['updateId'])['status']).to eq('failed')
215+
response = index.add_documents(objectId: 'toto et titi', title: 'Unknown')
216+
index.wait_for_pending_update(response['updateId'])
217+
expect(index.get_update_status(response['updateId'])['status']).to eq('failed')
217218
end
218219

219220
it 'fails to add document with no primary-key' do
220-
res = index.add_documents(id: 0, title: 'Unknown')
221-
sleep(0.1)
222-
expect(index.get_update_status(res['updateId'])['status']).to eq('failed')
221+
response = index.add_documents(id: 0, title: 'Unknown')
222+
index.wait_for_pending_update(response['updateId'])
223+
expect(index.get_update_status(response['updateId'])['status']).to eq('failed')
223224
end
224225

225226
it 'works with method aliases' do
@@ -255,7 +256,7 @@
255256
response = index.add_documents(documents, 'unique')
256257
expect(response).to be_a(Hash)
257258
expect(response).to have_key('updateId')
258-
sleep(0.2)
259+
index.wait_for_pending_update(response['updateId'])
259260
expect(index.fetch_primary_key).to eq('unique')
260261
end
261262

@@ -267,7 +268,7 @@
267268
}, 'id')
268269
expect(response).to be_a(Hash)
269270
expect(response).to have_key('updateId')
270-
sleep(0.2)
271+
index.wait_for_pending_update(response['updateId'])
271272
expect(index.fetch_primary_key).to eq('unique')
272273
doc = index.document(3)
273274
expect(doc['unique']).to eq(3)
@@ -293,7 +294,7 @@
293294
response = index.update_documents(documents, 'objectId')
294295
expect(response).to be_a(Hash)
295296
expect(response).to have_key('updateId')
296-
sleep(0.2)
297+
index.wait_for_pending_update(response['updateId'])
297298
expect(index.fetch_primary_key).to be_nil
298299
expect(index.get_update_status(response['updateId'])['status']).to eq('failed')
299300
end
@@ -316,7 +317,7 @@
316317
response = index.add_documents(documents, 'title')
317318
expect(response).to be_a(Hash)
318319
expect(response).to have_key('updateId')
319-
sleep(0.2)
320+
index.wait_for_pending_update(response['updateId'])
320321
expect(index.fetch_primary_key).to be_nil
321322
expect(index.get_update_status(response['updateId'])['status']).to eq('failed')
322323
expect(index.documents.count).to eq(0)
@@ -360,7 +361,7 @@
360361
response = index.add_documents(documents, 'unique')
361362
expect(response).to be_a(Hash)
362363
expect(response).to have_key('updateId')
363-
sleep(0.2)
364+
index.wait_for_pending_update(response['updateId'])
364365
expect(index.fetch_primary_key).to eq('unique')
365366
expect(index.documents.count).to eq(1)
366367
end

spec/meilisearch/index/search/attributes_to_crop_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@
4747
client = MeiliSearch::Client.new($URL, $MASTER_KEY)
4848
clear_all_indexes(client)
4949
@index = client.create_index('books')
50-
@index.add_documents(@documents)
51-
sleep(0.1)
50+
response = @index.add_documents(@documents)
51+
@index.wait_for_pending_update(response['updateId'])
5252
end
5353

5454
after(:all) do

spec/meilisearch/index/search/attributes_to_highlight.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
client = MeiliSearch::Client.new($URL, $MASTER_KEY)
1515
clear_all_indexes(client)
1616
@index = client.create_index('books')
17-
@index.add_documents(@documents)
18-
sleep(0.1)
17+
response = @index.add_documents(@documents)
18+
@index.wait_for_pending_update(response['updateId'])
1919
end
2020

2121
after(:all) do

spec/meilisearch/index/search/attributes_to_retrieve_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
client = MeiliSearch::Client.new($URL, $MASTER_KEY)
1515
clear_all_indexes(client)
1616
@index = client.create_index('books')
17-
@index.add_documents(@documents)
18-
sleep(0.1)
17+
response = @index.add_documents(@documents)
18+
@index.wait_for_pending_update(response['updateId'])
1919
end
2020

2121
after(:all) do

spec/meilisearch/index/search/facet_filters_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
client = MeiliSearch::Client.new($URL, $MASTER_KEY)
1616
clear_all_indexes(client)
1717
@index = client.create_index('books')
18-
@index.add_documents(@documents)
18+
response = @index.add_documents(@documents)
1919
@index.update_attributes_for_faceting(['genre', 'year'])
20-
sleep(0.1)
20+
@index.wait_for_pending_update(response['updateId'])
2121
end
2222

2323
after(:all) do

spec/meilisearch/index/search/facets_distribution_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@
6969
client = MeiliSearch::Client.new($URL, $MASTER_KEY)
7070
clear_all_indexes(client)
7171
@index = client.create_index('books')
72-
@index.add_documents(@documents)
72+
response = @index.add_documents(@documents)
7373
@index.update_attributes_for_faceting(['genre', 'year', 'author'])
74-
sleep(0.1)
74+
@index.wait_for_pending_update(response['updateId'])
7575
end
7676

7777
after(:all) do

spec/meilisearch/index/search/filters_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@
6969
client = MeiliSearch::Client.new($URL, $MASTER_KEY)
7070
clear_all_indexes(client)
7171
@index = client.create_index('books')
72-
@index.add_documents(@documents)
73-
sleep(0.1)
72+
response = @index.add_documents(@documents)
73+
@index.wait_for_pending_update(response['updateId'])
7474
end
7575

7676
after(:all) do

spec/meilisearch/index/search/limit_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
client = MeiliSearch::Client.new($URL, $MASTER_KEY)
1515
clear_all_indexes(client)
1616
@index = client.create_index('books')
17-
@index.add_documents(@documents)
18-
sleep(0.1)
17+
response = @index.add_documents(@documents)
18+
@index.wait_for_pending_update(response['updateId'])
1919
end
2020

2121
after(:all) do

spec/meilisearch/index/search/matches_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
client = MeiliSearch::Client.new($URL, $MASTER_KEY)
1515
clear_all_indexes(client)
1616
@index = client.create_index('books')
17-
@index.add_documents(@documents)
18-
sleep(0.1)
17+
response = @index.add_documents(@documents)
18+
@index.wait_for_pending_update(response['updateId'])
1919
end
2020

2121
after(:all) do

spec/meilisearch/index/search/multi_params_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
client = MeiliSearch::Client.new($URL, $MASTER_KEY)
1515
clear_all_indexes(client)
1616
@index = client.create_index('books')
17-
@index.add_documents(@documents)
18-
sleep(0.1)
17+
response = @index.add_documents(@documents)
18+
@index.wait_for_pending_update(response['updateId'])
1919
end
2020

2121
after(:all) do
@@ -59,8 +59,8 @@
5959
end
6060

6161
it 'does a custom search with facetFilters, attributesToRetrieve and attributesToHighlight' do
62-
@index.update_attributes_for_faceting(['genre'])
63-
sleep(0.1)
62+
response = @index.update_attributes_for_faceting(['genre'])
63+
@index.wait_for_pending_update(response['updateId'])
6464
response = @index.search('prinec',
6565
{
6666
facetFilters: ['genre: fantasy'],
@@ -77,8 +77,8 @@
7777
end
7878

7979
it 'does a custom search with facetsDistribution and limit' do
80-
@index.update_attributes_for_faceting(['genre'])
81-
sleep(0.1)
80+
response = @index.update_attributes_for_faceting(['genre'])
81+
@index.wait_for_pending_update(response['updateId'])
8282
response = @index.search('prinec', facetsDistribution: ['genre'], limit: 1)
8383
expect(response.keys).to contain_exactly(
8484
*$DEFAULT_SEARCH_RESPONSE_KEYS,

0 commit comments

Comments
 (0)