|
31 | 31 | response = index.add_documents(documents) |
32 | 32 | expect(response).to be_a(Hash) |
33 | 33 | expect(response).to have_key('updateId') |
34 | | - sleep(0.2) |
| 34 | + index.wait_for_pending_update(response['updateId']) |
35 | 35 | expect(index.documents.count).to eq(documents.count) |
36 | 36 | end |
37 | 37 |
|
|
45 | 45 | end |
46 | 46 |
|
47 | 47 | 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) |
49 | 50 | expect(response).to be_a(Hash) |
50 | 51 | expect(response).to have_key('updateId') |
51 | | - sleep(0.2) |
| 52 | + new_index.wait_for_pending_update(response['updateId']) |
52 | 53 | expect(@client.index('newIndex').fetch_primary_key).to eq('objectId') |
53 | 54 | expect(@client.index('newIndex').documents.count).to eq(documents.count) |
54 | 55 | end |
|
88 | 89 | response = index.update_documents(updated_documents) |
89 | 90 | expect(response).to be_a(Hash) |
90 | 91 | expect(response).to have_key('updateId') |
91 | | - sleep(0.1) |
| 92 | + index.wait_for_pending_update(response['updateId']) |
92 | 93 | doc1 = index.document(id1) |
93 | 94 | doc2 = index.document(id2) |
94 | 95 | expect(index.documents.count).to eq(documents.count) |
|
102 | 103 | id = 123 |
103 | 104 | updated_document = { objectId: id, title: 'Emma' } |
104 | 105 | response = index.update_documents(updated_document) |
105 | | - sleep(0.1) |
| 106 | + index.wait_for_pending_update(response['updateId']) |
106 | 107 | expect(response).to be_a(Hash) |
107 | 108 | expect(response).to have_key('updateId') |
108 | 109 | expect(index.documents.count).to eq(documents.count) |
|
116 | 117 | title = 'Hamlet' |
117 | 118 | new_doc = { objectId: id, title: title } |
118 | 119 | response = index.add_documents(new_doc) |
119 | | - sleep(0.1) |
| 120 | + index.wait_for_pending_update(response['updateId']) |
120 | 121 | expect(response).to be_a(Hash) |
121 | 122 | expect(response).to have_key('updateId') |
122 | 123 | expect(index.documents.count).to eq(documents.count + 1) |
123 | 124 | 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']) |
126 | 127 | end |
127 | 128 |
|
128 | 129 | it 'update a document with new fields' do |
129 | 130 | id = 2 |
130 | 131 | doc = { objectId: id, note: '8/10' } |
131 | 132 | response = index.update_documents(doc) |
132 | | - sleep(0.1) |
| 133 | + index.wait_for_pending_update(response['updateId']) |
133 | 134 | expect(response).to be_a(Hash) |
134 | 135 | expect(response).to have_key('updateId') |
135 | 136 | expect(index.documents.count).to eq(documents.count) |
|
144 | 145 | response = index.replace_documents(objectId: id, title: 'Pride & Prejudice', note: '8.5/10') |
145 | 146 | expect(response).to be_a(Hash) |
146 | 147 | expect(response).to have_key('updateId') |
147 | | - sleep(0.1) |
| 148 | + index.wait_for_pending_update(response['updateId']) |
148 | 149 | expect(index.documents.count).to eq(documents.count) |
149 | 150 | doc = index.document(id) |
150 | 151 | expect(doc['title']).to eq(new_title) |
|
155 | 156 | it 'deletes one document from index' do |
156 | 157 | id = 456 |
157 | 158 | response = index.delete_document(id) |
158 | | - sleep(0.1) |
| 159 | + index.wait_for_pending_update(response['updateId']) |
159 | 160 | expect(response).to be_a(Hash) |
160 | 161 | expect(response).to have_key('updateId') |
161 | 162 | expect(index.documents.size).to eq(documents.count - 1) |
|
165 | 166 | it 'does nothing when trying to delete a document which does not exist' do |
166 | 167 | id = 111 |
167 | 168 | response = index.delete_document(id) |
168 | | - sleep(0.1) |
| 169 | + index.wait_for_pending_update(response['updateId']) |
169 | 170 | expect(response).to be_a(Hash) |
170 | 171 | expect(response).to have_key('updateId') |
171 | 172 | expect(index.documents.size).to eq(documents.count - 1) |
|
175 | 176 | it 'deletes one document from index (with delete-batch route)' do |
176 | 177 | id = 2 |
177 | 178 | response = index.delete_documents(id) |
178 | | - sleep(0.1) |
| 179 | + index.wait_for_pending_update(response['updateId']) |
179 | 180 | expect(response).to be_a(Hash) |
180 | 181 | expect(response).to have_key('updateId') |
181 | 182 | expect(index.documents.size).to eq(documents.count - 2) |
|
185 | 186 | it 'deletes one document from index (with delete-batch route as an array of one uid)' do |
186 | 187 | id = 123 |
187 | 188 | response = index.delete_documents([id]) |
188 | | - sleep(0.1) |
| 189 | + index.wait_for_pending_update(response['updateId']) |
189 | 190 | expect(response).to be_a(Hash) |
190 | 191 | expect(response).to have_key('updateId') |
191 | 192 | expect(index.documents.size).to eq(documents.count - 3) |
|
195 | 196 | it 'deletes multiples documents from index' do |
196 | 197 | docs_to_delete = [1, 4] |
197 | 198 | response = index.delete_documents(docs_to_delete) |
198 | | - sleep(0.1) |
| 199 | + index.wait_for_pending_update(response['updateId']) |
199 | 200 | expect(response).to be_a(Hash) |
200 | 201 | expect(response).to have_key('updateId') |
201 | 202 | expect(index.documents.size).to eq(documents.count - 3 - docs_to_delete.count) |
202 | 203 | end |
203 | 204 |
|
204 | 205 | it 'clears all documents from index' do |
205 | 206 | response = index.delete_all_documents |
206 | | - sleep(0.1) |
| 207 | + index.wait_for_pending_update(response['updateId']) |
207 | 208 | expect(response).to be_a(Hash) |
208 | 209 | expect(response).to have_key('updateId') |
209 | 210 | expect(index.documents).to be_empty |
210 | 211 | expect(index.documents.size).to eq(0) |
211 | 212 | end |
212 | 213 |
|
213 | 214 | 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') |
217 | 218 | end |
218 | 219 |
|
219 | 220 | 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') |
223 | 224 | end |
224 | 225 |
|
225 | 226 | it 'works with method aliases' do |
|
255 | 256 | response = index.add_documents(documents, 'unique') |
256 | 257 | expect(response).to be_a(Hash) |
257 | 258 | expect(response).to have_key('updateId') |
258 | | - sleep(0.2) |
| 259 | + index.wait_for_pending_update(response['updateId']) |
259 | 260 | expect(index.fetch_primary_key).to eq('unique') |
260 | 261 | end |
261 | 262 |
|
|
267 | 268 | }, 'id') |
268 | 269 | expect(response).to be_a(Hash) |
269 | 270 | expect(response).to have_key('updateId') |
270 | | - sleep(0.2) |
| 271 | + index.wait_for_pending_update(response['updateId']) |
271 | 272 | expect(index.fetch_primary_key).to eq('unique') |
272 | 273 | doc = index.document(3) |
273 | 274 | expect(doc['unique']).to eq(3) |
|
293 | 294 | response = index.update_documents(documents, 'objectId') |
294 | 295 | expect(response).to be_a(Hash) |
295 | 296 | expect(response).to have_key('updateId') |
296 | | - sleep(0.2) |
| 297 | + index.wait_for_pending_update(response['updateId']) |
297 | 298 | expect(index.fetch_primary_key).to be_nil |
298 | 299 | expect(index.get_update_status(response['updateId'])['status']).to eq('failed') |
299 | 300 | end |
|
316 | 317 | response = index.add_documents(documents, 'title') |
317 | 318 | expect(response).to be_a(Hash) |
318 | 319 | expect(response).to have_key('updateId') |
319 | | - sleep(0.2) |
| 320 | + index.wait_for_pending_update(response['updateId']) |
320 | 321 | expect(index.fetch_primary_key).to be_nil |
321 | 322 | expect(index.get_update_status(response['updateId'])['status']).to eq('failed') |
322 | 323 | expect(index.documents.count).to eq(0) |
|
360 | 361 | response = index.add_documents(documents, 'unique') |
361 | 362 | expect(response).to be_a(Hash) |
362 | 363 | expect(response).to have_key('updateId') |
363 | | - sleep(0.2) |
| 364 | + index.wait_for_pending_update(response['updateId']) |
364 | 365 | expect(index.fetch_primary_key).to eq('unique') |
365 | 366 | expect(index.documents.count).to eq(1) |
366 | 367 | end |
|
0 commit comments