|
6 | 6 |
|
7 | 7 | import pytest |
8 | 8 |
|
9 | | -from apify_client._models import Request as ClientRequest |
10 | 9 | from apify_client._models import RequestQueueHead, RequestQueueStats, RequestRegistration |
11 | 10 | from crawlee.storage_clients.models import RequestQueueMetadata |
12 | 11 |
|
@@ -145,49 +144,6 @@ async def test_list_head_limit(in_progress_count: int, expected_limit: int) -> N |
145 | 144 | api_client.list_head.assert_awaited_once_with(limit=expected_limit) |
146 | 145 |
|
147 | 146 |
|
148 | | -async def test_fetch_next_request_skips_already_handled() -> None: |
149 | | - """A request the platform reports as already handled must not be returned by `fetch_next_request`.""" |
150 | | - client, api_client = _make_single_client() |
151 | | - |
152 | | - unique_key = 'https://example.com' |
153 | | - request_id = unique_key_to_request_id(unique_key) |
154 | | - |
155 | | - # Head reconciliation returns nothing new. |
156 | | - api_client.list_head = AsyncMock( |
157 | | - return_value=RequestQueueHead( |
158 | | - limit=200, |
159 | | - queue_modified_at=datetime.now(tz=UTC), |
160 | | - had_multiple_clients=False, |
161 | | - items=[], |
162 | | - ) |
163 | | - ) |
164 | | - # The platform reports this request as already handled. |
165 | | - api_client.get_request = AsyncMock( |
166 | | - return_value=ClientRequest.model_validate( |
167 | | - { |
168 | | - 'id': request_id, |
169 | | - 'uniqueKey': unique_key, |
170 | | - 'url': unique_key, |
171 | | - 'method': 'GET', |
172 | | - 'headers': {}, |
173 | | - 'userData': {}, |
174 | | - 'retryCount': 0, |
175 | | - 'noRetry': False, |
176 | | - 'handledAt': datetime.now(tz=UTC), |
177 | | - } |
178 | | - ) |
179 | | - ) |
180 | | - |
181 | | - # Seed the local head estimate with the request id. |
182 | | - client._head_requests.append(request_id) |
183 | | - |
184 | | - result = await client.fetch_next_request() |
185 | | - |
186 | | - assert result is None, 'Already-handled request must not be fetched.' |
187 | | - assert request_id not in client._requests_in_progress, 'Handled request must not be left in progress.' |
188 | | - assert request_id in client._requests_already_handled, 'Handled request id should be cached for deduplication.' |
189 | | - |
190 | | - |
191 | 147 | @pytest.mark.parametrize( |
192 | 148 | 'make_client', |
193 | 149 | [_make_single_client, _make_shared_client], |
|
0 commit comments