Skip to content

Commit 11944b7

Browse files
authored
chore: add test for wait_time_between_batches option for RequestQueue.add_requests (#1492)
### Description - add test for `wait_time_between_batches` option for `RequestQueue.add_requests` ### Issues - Closes: #188
1 parent e2beda1 commit 11944b7

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

tests/unit/storages/test_request_queue.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from __future__ import annotations
55

66
import asyncio
7+
from datetime import timedelta
78
from typing import TYPE_CHECKING
89

910
import pytest
@@ -421,6 +422,36 @@ async def test_is_empty(rq: RequestQueue) -> None:
421422
assert await rq.is_empty() is True
422423

423424

425+
@pytest.mark.parametrize(
426+
('wait_for_all'),
427+
[
428+
pytest.param(True, id='wait for all'),
429+
pytest.param(False, id='don`t wait for all'),
430+
],
431+
)
432+
async def test_add_requests_wait_for_all(rq: RequestQueue, *, wait_for_all: bool) -> None:
433+
"""Test adding requests with wait_for_all_requests_to_be_added option."""
434+
urls = [f'https://example.com/{i}' for i in range(15)]
435+
436+
# Add requests without waiting
437+
await rq.add_requests(
438+
urls,
439+
batch_size=5,
440+
wait_for_all_requests_to_be_added=wait_for_all,
441+
wait_time_between_batches=timedelta(milliseconds=100),
442+
)
443+
444+
if not wait_for_all:
445+
# Immediately after adding, the total count may be less than 15 due to background processing
446+
assert await rq.get_total_count() <= 15
447+
448+
# Wait a 250 milliseconds for background tasks to complete
449+
await asyncio.sleep(0.25)
450+
451+
# Verify all requests were added
452+
assert await rq.get_total_count() == 15
453+
454+
424455
async def test_is_finished(rq: RequestQueue) -> None:
425456
"""Test checking if a request queue is finished."""
426457
# Initially the queue should be finished (empty and no background tasks)

0 commit comments

Comments
 (0)