5
5
6
6
from ._utils import generate_unique_resource_name
7
7
from apify import Actor , Request
8
+ from apify ._models import ActorRun
8
9
9
10
if TYPE_CHECKING :
10
11
from apify_client import ApifyClientAsync
@@ -157,6 +158,7 @@ async def test_request_queue_had_multiple_clients_local(
157
158
158
159
# Check that it is correctly in the RequestQueueClient metadata
159
160
assert (await request_queue_force_cloud .get_metadata ()).had_multiple_clients is True
161
+
160
162
# Check that it is correctly in the API
161
163
api_response = await api_client .get ()
162
164
assert api_response
@@ -174,6 +176,7 @@ async def test_request_queue_not_had_multiple_clients_local(
174
176
175
177
# Check that it is correctly in the RequestQueueClient metadata
176
178
assert (await request_queue_force_cloud .get_metadata ()).had_multiple_clients is False
179
+
177
180
# Check that it is correctly in the API
178
181
api_client = apify_client_async .request_queue (request_queue_id = request_queue_force_cloud .id )
179
182
api_response = await api_client .get ()
@@ -185,8 +188,9 @@ async def test_request_queue_had_multiple_clients_platform(
185
188
make_actor : MakeActorFunction ,
186
189
run_actor : RunActorFunction ,
187
190
) -> None :
191
+ """Test that `RequestQueue` clients created with different `client_key` appear as distinct clients."""
192
+
188
193
async def main () -> None :
189
- """`RequestQueue` clients created with different `client_key` should appear as distinct clients."""
190
194
from apify_client import ApifyClientAsync
191
195
192
196
async with Actor :
@@ -199,7 +203,6 @@ async def main() -> None:
199
203
)
200
204
await api_client .list_head ()
201
205
202
- # Check that it is correctly in the RequestQueueClient metadata
203
206
assert (await rq_1 .get_metadata ()).had_multiple_clients is True
204
207
205
208
actor = await make_actor (label = 'rq-had-multiple-clients' , main_func = main )
@@ -212,18 +215,54 @@ async def test_request_queue_not_had_multiple_clients_platform(
212
215
make_actor : MakeActorFunction ,
213
216
run_actor : RunActorFunction ,
214
217
) -> None :
218
+ """Test that same `RequestQueue` created from Actor does not act as multiple clients."""
219
+
215
220
async def main () -> None :
216
- """Test that same `RequestQueue` created from Actor does not act as multiple clients."""
217
221
async with Actor :
218
222
rq_1 = await Actor .open_request_queue ()
219
- # Two calls to API to create situation where different `client_key` can set `had_multiple_clients` to True
223
+ # Two calls to API to create situation where unset `client_key` can cause `had_multiple_clients` to True
220
224
await rq_1 .fetch_next_request ()
221
225
await rq_1 .fetch_next_request ()
222
226
223
- # Check that it is correctly in the RequestQueueClient metadata
224
227
assert (await rq_1 .get_metadata ()).had_multiple_clients is False
225
228
226
229
actor = await make_actor (label = 'rq-not-had-multiple-clients' , main_func = main )
227
230
run_result = await run_actor (actor )
228
231
229
232
assert run_result .status == 'SUCCEEDED'
233
+
234
+
235
+ async def test_request_queue_not_had_multiple_clients_platform_resurrection (
236
+ make_actor : MakeActorFunction ,
237
+ run_actor : RunActorFunction ,
238
+ apify_client_async : ApifyClientAsync ,
239
+ ) -> None :
240
+ """Test `RequestQueue` created from Actor does not act as multiple clients even after resurrection."""
241
+
242
+ async def main () -> None :
243
+ async with Actor :
244
+ rq_1 = await Actor .open_request_queue ()
245
+ Actor .log .info (f'Used client key = { rq_1 ._client ._api_client .client_key } , request queue ID = { rq_1 .id } ' )
246
+ metadata = await rq_1 .get_metadata ()
247
+ Actor .log .info (metadata )
248
+
249
+ assert metadata .had_multiple_clients is False , 'Not accessed yet, should be False'
250
+
251
+ await rq_1 .fetch_next_request ()
252
+
253
+ assert (await rq_1 .get_metadata ()).had_multiple_clients is False , (
254
+ 'Accessed with same client, should be False'
255
+ )
256
+
257
+ actor = await make_actor (label = 'rq-multiple-clients-resurrection' , main_func = main )
258
+ run_result = await run_actor (actor )
259
+ assert run_result .status == 'SUCCEEDED'
260
+
261
+ # Resurrect the run, the RequestQueue should still use same client key and thus not have multiple clients.
262
+ run_client = apify_client_async .run (run_id = run_result .id )
263
+ # Redirect logs even from the resurrected run
264
+ streamed_log = await run_client .get_streamed_log (from_start = False )
265
+ await run_client .resurrect ()
266
+ async with streamed_log :
267
+ run_result = ActorRun .model_validate (await run_client .wait_for_finish (wait_secs = 600 ))
268
+ assert run_result .status == 'SUCCEEDED'
0 commit comments