From cefacfafb9d93c4ec118f1a1f0b5663e400ae386 Mon Sep 17 00:00:00 2001 From: Josef Prochazka Date: Mon, 8 Dec 2025 16:25:36 +0100 Subject: [PATCH 1/3] Update test and try to stress test it in CI --- tests/unit/actor/test_actor_lifecycle.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/unit/actor/test_actor_lifecycle.py b/tests/unit/actor/test_actor_lifecycle.py index 4b33b3df..3142b80b 100644 --- a/tests/unit/actor/test_actor_lifecycle.py +++ b/tests/unit/actor/test_actor_lifecycle.py @@ -216,11 +216,11 @@ def on_event(event_type: Event) -> Callable: assert on_system_info_count == len(on_system_info) -async def test_actor_handles_migrating_event_correctly(monkeypatch: pytest.MonkeyPatch) -> None: +@pytest.mark.parametrize('_', range(1000)) +async def test_actor_handles_migrating_event_correctly(monkeypatch: pytest.MonkeyPatch, _: int) -> None: """Test that Actor handles MIGRATING events correctly by emitting PERSIST_STATE.""" # This should test whether when you get a MIGRATING event, # the Actor automatically emits the PERSIST_STATE event with data `{'isMigrating': True}` - monkeypatch.setenv(ApifyEnvVars.PERSIST_STATE_INTERVAL_MILLIS, '500') monkeypatch.setenv(ApifyEnvVars.IS_AT_HOME, '1') monkeypatch.setenv(ActorEnvVars.RUN_ID, 'asdf') @@ -285,7 +285,7 @@ async def handler(websocket: websockets.asyncio.server.ServerConnection) -> None await asyncio.sleep(1) - assert len(persist_state_events_data) >= 3 + assert len(persist_state_events_data) >= 2 print(persist_state_events_data) From 26991d841d245d5931b2b8297c5c6894a78a789a Mon Sep 17 00:00:00 2001 From: Josef Prochazka Date: Mon, 8 Dec 2025 17:02:50 +0100 Subject: [PATCH 2/3] Remove stress testing. It passed 1000x without error --- tests/unit/actor/test_actor_lifecycle.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/unit/actor/test_actor_lifecycle.py b/tests/unit/actor/test_actor_lifecycle.py index 3142b80b..ec3b387b 100644 --- a/tests/unit/actor/test_actor_lifecycle.py +++ b/tests/unit/actor/test_actor_lifecycle.py @@ -216,8 +216,7 @@ def on_event(event_type: Event) -> Callable: assert on_system_info_count == len(on_system_info) -@pytest.mark.parametrize('_', range(1000)) -async def test_actor_handles_migrating_event_correctly(monkeypatch: pytest.MonkeyPatch, _: int) -> None: +async def test_actor_handles_migrating_event_correctly(monkeypatch: pytest.MonkeyPatch) -> None: """Test that Actor handles MIGRATING events correctly by emitting PERSIST_STATE.""" # This should test whether when you get a MIGRATING event, # the Actor automatically emits the PERSIST_STATE event with data `{'isMigrating': True}` From e7d916ee943b2550b56f6e2de85e761a75b0c4ce Mon Sep 17 00:00:00 2001 From: Josef Prochazka Date: Tue, 9 Dec 2025 09:28:20 +0100 Subject: [PATCH 3/3] Add comment and remove print --- tests/unit/actor/test_actor_lifecycle.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/unit/actor/test_actor_lifecycle.py b/tests/unit/actor/test_actor_lifecycle.py index ec3b387b..2ece897b 100644 --- a/tests/unit/actor/test_actor_lifecycle.py +++ b/tests/unit/actor/test_actor_lifecycle.py @@ -284,10 +284,9 @@ async def handler(websocket: websockets.asyncio.server.ServerConnection) -> None await asyncio.sleep(1) + # It is enough to check the persist state event we send manually and the crawler final one. assert len(persist_state_events_data) >= 2 - print(persist_state_events_data) - # Expect last event to be is_migrating=False (persistence event on exiting EventManager) assert persist_state_events_data.pop() == EventPersistStateData(is_migrating=False) # Expect second last event to be is_migrating=True (emitted on MIGRATING event)