|
26 | 26 |
|
27 | 27 | from ..conftest import DefaultCollection |
28 | 28 |
|
29 | | -NUM_DOCS = 25 # keep this between 20 and 39 |
30 | | -NUM_DOCS_PAGINATION = 90 # keep this above 2 * (2 * 20) and below 2 * (3 * 20) |
| 29 | +PAGE_SIZE = 20 # TODO: set to 50, default as per Data API config after PR 2461 |
| 30 | +NUM_DOCS = 2 * PAGE_SIZE + 5 |
| 31 | +NUM_DOCS_PAGINATION = 2 * (2 * PAGE_SIZE) + 5 |
31 | 32 |
|
32 | 33 |
|
33 | 34 | @pytest.fixture |
@@ -159,16 +160,16 @@ def test_collection_cursors_started_properties_sync( |
159 | 160 | next(cur) |
160 | 161 | # now this has 19 items in buffer, one is consumed |
161 | 162 | assert cur.consumed == 1 |
162 | | - assert cur.buffered_count == 19 |
| 163 | + assert cur.buffered_count == PAGE_SIZE - 1 |
163 | 164 | assert len(cur.consume_buffer(3)) == 3 |
164 | 165 | assert cur.consumed == 4 |
165 | | - assert cur.buffered_count == 16 |
| 166 | + assert cur.buffered_count == PAGE_SIZE - 4 |
166 | 167 | # from time to time the buffer is empty: |
167 | | - for _ in range(16): |
| 168 | + for _ in range(PAGE_SIZE - 4): |
168 | 169 | next(cur) |
169 | 170 | assert cur.buffered_count == 0 |
170 | 171 | assert cur.consume_buffer(3) == [] |
171 | | - assert cur.consumed == 20 |
| 172 | + assert cur.consumed == PAGE_SIZE |
172 | 173 | assert cur.buffered_count == 0 |
173 | 174 |
|
174 | 175 | with pytest.raises(CursorException): |
@@ -211,12 +212,12 @@ def test_collection_cursors_has_next_sync( |
211 | 212 | assert curmf.has_next() |
212 | 213 | assert curmf.consumed == 2 |
213 | 214 | assert curmf.state == CursorState.STARTED |
214 | | - for _ in range(18): |
| 215 | + for _ in range(PAGE_SIZE - 2): |
215 | 216 | next(curmf) |
216 | 217 | assert curmf.has_next() |
217 | | - assert curmf.consumed == 20 |
| 218 | + assert curmf.consumed == PAGE_SIZE |
218 | 219 | assert curmf.state == CursorState.STARTED |
219 | | - assert curmf.buffered_count == NUM_DOCS - 20 |
| 220 | + assert curmf.buffered_count == PAGE_SIZE |
220 | 221 |
|
221 | 222 | cur0 = filled_collection.find() |
222 | 223 | cur0.close() |
@@ -417,26 +418,24 @@ def test_collection_cursors_initialpagestate_sync( |
417 | 418 | self, |
418 | 419 | filled_pagination_collection: DefaultCollection, |
419 | 420 | ) -> None: |
420 | | - page_size = 20 |
421 | | - |
422 | 421 | cur0 = filled_pagination_collection.find(filter={"even": True}) |
423 | | - ids0 = [doc["_id"] for _, doc in zip(range(page_size), cur0)] |
| 422 | + ids0 = [doc["_id"] for _, doc in zip(range(PAGE_SIZE), cur0)] |
424 | 423 | nps0 = cur0._next_page_state |
425 | 424 | assert isinstance(nps0, str) |
426 | 425 |
|
427 | 426 | cur1 = filled_pagination_collection.find( |
428 | 427 | filter={"even": True}, |
429 | 428 | initial_page_state=nps0, |
430 | 429 | ) |
431 | | - ids1 = [doc["_id"] for _, doc in zip(range(page_size), cur1)] |
| 430 | + ids1 = [doc["_id"] for _, doc in zip(range(PAGE_SIZE), cur1)] |
432 | 431 | nps1 = cur1._next_page_state |
433 | 432 | assert isinstance(nps1, str) |
434 | 433 |
|
435 | 434 | cur2 = filled_pagination_collection.find( |
436 | 435 | filter={"even": True}, |
437 | 436 | initial_page_state=nps1, |
438 | 437 | ) |
439 | | - ids2 = [doc["_id"] for _, doc in zip(range(page_size), cur2)] |
| 438 | + ids2 = [doc["_id"] for doc in cur2] |
440 | 439 | assert cur2._next_page_state is None |
441 | 440 |
|
442 | 441 | expected_ids = [i for i in range(NUM_DOCS_PAGINATION) if i % 2 == 0] |
|
0 commit comments