Skip to content

Commit 6ee7e8e

Browse files
committed
all integration tests should be more stable
1 parent 346d53c commit 6ee7e8e

8 files changed

+299
-62
lines changed

tests/integration/test_actor_dataset.py

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
from .conftest import ActorFactory
1616

1717

18-
async def test_push_and_verify_data_in_default_dataset(make_actor: ActorFactory) -> None:
18+
async def test_push_and_verify_data_in_default_dataset(
19+
apify_client_async: ApifyClientAsync,
20+
make_actor: ActorFactory,
21+
) -> None:
1922
desired_item_count = 100 # Also change inside main() if you're changing this
2023

2124
async def main() -> None:
@@ -25,32 +28,48 @@ async def main() -> None:
2528

2629
actor = await make_actor('push-data', main_func=main)
2730

28-
run_result = await actor.call()
31+
call_result = await actor.call()
32+
assert call_result is not None
33+
34+
run_client = apify_client_async.run(call_result['id'])
35+
run_result = await run_client.wait_for_finish(wait_secs=300)
2936

3037
assert run_result is not None
3138
assert run_result['status'] == 'SUCCEEDED'
39+
3240
list_page = await actor.last_run().dataset().list_items()
3341
assert list_page.items[0]['id'] == 0
3442
assert list_page.items[-1]['id'] == desired_item_count - 1
3543
assert len(list_page.items) == list_page.count == desired_item_count
3644

3745

38-
async def test_push_large_data_chunks_over_9mb(make_actor: ActorFactory) -> None:
46+
async def test_push_large_data_chunks_over_9mb(
47+
apify_client_async: ApifyClientAsync,
48+
make_actor: ActorFactory,
49+
) -> None:
3950
async def main() -> None:
4051
async with Actor:
4152
await Actor.push_data([{'str': 'x' * 10000} for _ in range(5000)]) # ~50MB
4253

4354
actor = await make_actor('push-data-over-9mb', main_func=main)
4455

45-
run_result = await actor.call()
56+
call_result = await actor.call()
57+
assert call_result is not None
58+
59+
run_client = apify_client_async.run(call_result['id'])
60+
run_result = await run_client.wait_for_finish(wait_secs=300)
4661

4762
assert run_result is not None
4863
assert run_result['status'] == 'SUCCEEDED'
64+
4965
async for item in actor.last_run().dataset().iterate_items():
5066
assert item['str'] == 'x' * 10000
5167

5268

53-
async def test_same_references_in_default_dataset(make_actor: ActorFactory) -> None:
69+
async def test_same_references_in_default_dataset(
70+
apify_client_async: ApifyClientAsync,
71+
make_actor: ActorFactory,
72+
) -> None:
5473
async def main() -> None:
5574
async with Actor:
5675
dataset1 = await Actor.open_dataset()
@@ -59,12 +78,20 @@ async def main() -> None:
5978

6079
actor = await make_actor('dataset-same-ref-default', main_func=main)
6180

62-
run_result = await actor.call()
81+
call_result = await actor.call()
82+
assert call_result is not None
83+
84+
run_client = apify_client_async.run(call_result['id'])
85+
run_result = await run_client.wait_for_finish(wait_secs=300)
86+
6387
assert run_result is not None
6488
assert run_result['status'] == 'SUCCEEDED'
6589

6690

67-
async def test_same_references_in_named_dataset(make_actor: ActorFactory) -> None:
91+
async def test_same_references_in_named_dataset(
92+
apify_client_async: ApifyClientAsync,
93+
make_actor: ActorFactory,
94+
) -> None:
6895
dataset_name = generate_unique_resource_name('dataset')
6996

7097
async def main() -> None:
@@ -84,12 +111,20 @@ async def main() -> None:
84111

85112
actor = await make_actor('dataset-same-ref-named', main_func=main)
86113

87-
run_result = await actor.call(run_input={'datasetName': dataset_name})
114+
call_result = await actor.call(run_input={'datasetName': dataset_name})
115+
assert call_result is not None
116+
117+
run_client = apify_client_async.run(call_result['id'])
118+
run_result = await run_client.wait_for_finish(wait_secs=300)
119+
88120
assert run_result is not None
89121
assert run_result['status'] == 'SUCCEEDED'
90122

91123

92-
async def test_force_cloud(apify_client_async: ApifyClientAsync, monkeypatch: pytest.MonkeyPatch) -> None:
124+
async def test_force_cloud(
125+
apify_client_async: ApifyClientAsync,
126+
monkeypatch: pytest.MonkeyPatch,
127+
) -> None:
93128
assert apify_client_async.token is not None
94129
monkeypatch.setenv(ApifyEnvVars.TOKEN, apify_client_async.token)
95130

tests/integration/test_actor_events.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@
88
from apify import Actor
99

1010
if TYPE_CHECKING:
11+
from apify_client import ApifyClientAsync
12+
1113
from .conftest import ActorFactory
1214

1315

14-
async def test_emit_and_capture_interval_events(make_actor: ActorFactory) -> None:
16+
async def test_emit_and_capture_interval_events(
17+
apify_client_async: ApifyClientAsync,
18+
make_actor: ActorFactory,
19+
) -> None:
1520
async def main() -> None:
1621
import os
1722
from datetime import datetime
@@ -54,10 +59,15 @@ async def log_event(data: Any) -> None:
5459

5560
actor = await make_actor('actor-interval-events', main_func=main)
5661

57-
run_result = await actor.call()
62+
call_result = await actor.call()
63+
assert call_result is not None
64+
65+
run_client = apify_client_async.run(call_result['id'])
66+
run_result = await run_client.wait_for_finish(wait_secs=300)
5867

5968
assert run_result is not None
6069
assert run_result['status'] == 'SUCCEEDED'
70+
6171
dataset_items_page = await actor.last_run().dataset().list_items()
6272
persist_state_events = [
6373
item for item in dataset_items_page.items if item['event_type'] == ActorEventTypes.PERSIST_STATE
@@ -69,7 +79,10 @@ async def log_event(data: Any) -> None:
6979
assert len(system_info_events) > 0
7080

7181

72-
async def test_event_listener_can_be_removed_successfully(make_actor: ActorFactory) -> None:
82+
async def test_event_listener_can_be_removed_successfully(
83+
apify_client_async: ApifyClientAsync,
84+
make_actor: ActorFactory,
85+
) -> None:
7386
async def main() -> None:
7487
import os
7588

@@ -96,7 +109,11 @@ def count_event(data): # type: ignore # noqa: ANN202, ANN001
96109

97110
actor = await make_actor('actor-off-event', main_func=main)
98111

99-
run = await actor.call()
112+
call_result = await actor.call()
113+
assert call_result is not None
100114

101-
assert run is not None
102-
assert run['status'] == 'SUCCEEDED'
115+
run_client = apify_client_async.run(call_result['id'])
116+
run_result = await run_client.wait_for_finish(wait_secs=300)
117+
118+
assert run_result is not None
119+
assert run_result['status'] == 'SUCCEEDED'

tests/integration/test_actor_key_value_store.py

Lines changed: 71 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
from .conftest import ActorFactory
1616

1717

18-
async def test_same_references_in_default_kvs(make_actor: ActorFactory) -> None:
18+
async def test_same_references_in_default_kvs(
19+
apify_client_async: ApifyClientAsync,
20+
make_actor: ActorFactory,
21+
) -> None:
1922
async def main() -> None:
2023
async with Actor:
2124
kvs1 = await Actor.open_key_value_store()
@@ -24,12 +27,20 @@ async def main() -> None:
2427

2528
actor = await make_actor('kvs-same-ref-default', main_func=main)
2629

27-
run_result = await actor.call()
30+
call_result = await actor.call()
31+
assert call_result is not None
32+
33+
run_client = apify_client_async.run(call_result['id'])
34+
run_result = await run_client.wait_for_finish(wait_secs=300)
35+
2836
assert run_result is not None
2937
assert run_result['status'] == 'SUCCEEDED'
3038

3139

32-
async def test_same_references_in_named_kvs(make_actor: ActorFactory) -> None:
40+
async def test_same_references_in_named_kvs(
41+
apify_client_async: ApifyClientAsync,
42+
make_actor: ActorFactory,
43+
) -> None:
3344
kvs_name = generate_unique_resource_name('key-value-store')
3445

3546
async def main() -> None:
@@ -49,12 +60,20 @@ async def main() -> None:
4960

5061
actor = await make_actor('kvs-same-ref-named', main_func=main)
5162

52-
run_result = await actor.call(run_input={'kvsName': kvs_name})
63+
call_result = await actor.call(run_input={'kvsName': kvs_name})
64+
assert call_result is not None
65+
66+
run_client = apify_client_async.run(call_result['id'])
67+
run_result = await run_client.wait_for_finish(wait_secs=300)
68+
5369
assert run_result is not None
5470
assert run_result['status'] == 'SUCCEEDED'
5571

5672

57-
async def test_force_cloud(apify_client_async: ApifyClientAsync, monkeypatch: pytest.MonkeyPatch) -> None:
73+
async def test_force_cloud(
74+
apify_client_async: ApifyClientAsync,
75+
monkeypatch: pytest.MonkeyPatch,
76+
) -> None:
5877
assert apify_client_async.token is not None
5978
monkeypatch.setenv(ApifyEnvVars.TOKEN, apify_client_async.token)
6079

@@ -80,7 +99,10 @@ async def test_force_cloud(apify_client_async: ApifyClientAsync, monkeypatch: py
8099
await key_value_store_client.delete()
81100

82101

83-
async def test_set_and_get_value_in_same_run(make_actor: ActorFactory) -> None:
102+
async def test_set_and_get_value_in_same_run(
103+
apify_client_async: ApifyClientAsync,
104+
make_actor: ActorFactory,
105+
) -> None:
84106
async def main() -> None:
85107
async with Actor:
86108
await Actor.set_value('test', {'number': 123, 'string': 'a string', 'nested': {'test': 1}})
@@ -91,21 +113,35 @@ async def main() -> None:
91113

92114
actor = await make_actor('actor-get-set-value', main_func=main)
93115

94-
run_result = await actor.call()
116+
call_result = await actor.call()
117+
assert call_result is not None
118+
119+
run_client = apify_client_async.run(call_result['id'])
120+
run_result = await run_client.wait_for_finish(wait_secs=300)
121+
95122
assert run_result is not None
96123
assert run_result['status'] == 'SUCCEEDED'
97124

98125

99-
async def test_set_value_in_one_run_and_get_value_in_another(make_actor: ActorFactory) -> None:
126+
async def test_set_value_in_one_run_and_get_value_in_another(
127+
apify_client_async: ApifyClientAsync,
128+
make_actor: ActorFactory,
129+
) -> None:
100130
async def main_set() -> None:
101131
async with Actor:
102132
await Actor.set_value('test', {'number': 123, 'string': 'a string', 'nested': {'test': 1}})
103133

104134
actor_set = await make_actor('actor-set-value', main_func=main_set)
105135

106-
run_result_set = await actor_set.call()
136+
call_result_set = await actor_set.call()
137+
assert call_result_set is not None
138+
139+
run_client_set = apify_client_async.run(call_result_set['id'])
140+
run_result_set = await run_client_set.wait_for_finish(wait_secs=300)
141+
107142
assert run_result_set is not None
108143
assert run_result_set['status'] == 'SUCCEEDED'
144+
109145
# Externally check if the value is present in key-value store
110146
test_record = await actor_set.last_run().key_value_store().get_record('test')
111147
assert test_record is not None
@@ -128,12 +164,20 @@ async def main_get() -> None:
128164
default_kvs_info = await actor_set.last_run().key_value_store().get()
129165
assert default_kvs_info is not None
130166

131-
run_result_get = await actor_get.call(run_input={'kvs-id': default_kvs_info['id']})
167+
call_result_get = await actor_get.call(run_input={'kvs-id': default_kvs_info['id']})
168+
assert call_result_get is not None
169+
170+
run_client_get = apify_client_async.run(call_result_get['id'])
171+
run_result_get = await run_client_get.wait_for_finish(wait_secs=300)
172+
132173
assert run_result_get is not None
133174
assert run_result_get['status'] == 'SUCCEEDED'
134175

135176

136-
async def test_actor_get_input_from_run(make_actor: ActorFactory) -> None:
177+
async def test_actor_get_input_from_run(
178+
apify_client_async: ApifyClientAsync,
179+
make_actor: ActorFactory,
180+
) -> None:
137181
actor_source_files = {
138182
'INPUT_SCHEMA.json': """
139183
{
@@ -168,19 +212,27 @@ async def main():
168212
}
169213
actor = await make_actor('actor-get-input', source_files=actor_source_files)
170214

171-
run_result = await actor.call(
215+
call_result = await actor.call(
172216
run_input={
173217
'number': 123,
174218
'string': 'a string',
175219
'nested': {'test': 1},
176220
'password': 'very secret',
177221
}
178222
)
223+
assert call_result is not None
224+
225+
run_client = apify_client_async.run(call_result['id'])
226+
run_result = await run_client.wait_for_finish(wait_secs=300)
227+
179228
assert run_result is not None
180229
assert run_result['status'] == 'SUCCEEDED'
181230

182231

183-
async def test_generate_public_url_for_kvs_record(make_actor: ActorFactory) -> None:
232+
async def test_generate_public_url_for_kvs_record(
233+
apify_client_async: ApifyClientAsync,
234+
make_actor: ActorFactory,
235+
) -> None:
184236
async def main() -> None:
185237
from typing import cast
186238

@@ -198,6 +250,11 @@ async def main() -> None:
198250

199251
actor = await make_actor('kvs-get-public-url', main_func=main)
200252

201-
run_result = await actor.call()
253+
call_result = await actor.call()
254+
assert call_result is not None
255+
256+
run_client = apify_client_async.run(call_result['id'])
257+
run_result = await run_client.wait_for_finish(wait_secs=300)
258+
202259
assert run_result is not None
203260
assert run_result['status'] == 'SUCCEEDED'

0 commit comments

Comments
 (0)