From 31bd582f8c33dfb7958e69134ee9e9ecebcb4b72 Mon Sep 17 00:00:00 2001 From: "Mathias L. Baumann" Date: Tue, 21 Jan 2025 18:27:04 +0100 Subject: [PATCH 1/2] Fix test_env in test that re-created it This particular test restarted the background dispatch service, which means all receivers were invalidated and had to be recreated. Signed-off-by: Mathias L. Baumann --- tests/test_frequenz_dispatch.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/tests/test_frequenz_dispatch.py b/tests/test_frequenz_dispatch.py index 41f4c9b..82802c1 100644 --- a/tests/test_frequenz_dispatch.py +++ b/tests/test_frequenz_dispatch.py @@ -426,7 +426,7 @@ async def test_dispatch_new_but_finished( generator: DispatchGenerator, fake_time: time_machine.Coordinates, ) -> None: - """Test that a dispatch that is already finished is not started.""" + """Test that a finished dispatch is not started at startup.""" # Generate a dispatch that is already finished finished_dispatch = generator.generate_dispatch() finished_dispatch = replace( @@ -437,10 +437,25 @@ async def test_dispatch_new_but_finished( recurrence=RecurrenceRule(), type="TEST_TYPE", ) - # Create an old dispatch + # Inject an old dispatch test_env.client.set_dispatches(test_env.microgrid_id, [finished_dispatch]) await test_env.service.stop() test_env.service.start() + test_env = replace( + test_env, + lifecycle_events=test_env.service.new_lifecycle_events_receiver("TEST_TYPE"), + running_state_change=( + await test_env.service.new_running_state_event_receiver( + "TEST_TYPE", unify_running_intervals=False + ) + ), + ) + + fake_time.shift(timedelta(seconds=1)) + # Process the lifecycle event caused by the old dispatch at startup + await test_env.lifecycle_events.receive() + + await asyncio.sleep(1) # Create another dispatch the normal way new_dispatch = generator.generate_dispatch() @@ -452,8 +467,7 @@ async def test_dispatch_new_but_finished( recurrence=RecurrenceRule(), type="TEST_TYPE", ) - # Consume one lifecycle_updates event - await test_env.lifecycle_events.receive() + new_dispatch = await _test_new_dispatch_created(test_env, new_dispatch) # Advance time to when the new dispatch should still not start From 30b99e15b6f9bc5743032c9ab61001ea4f32ada9 Mon Sep 17 00:00:00 2001 From: "Mathias L. Baumann" Date: Tue, 21 Jan 2025 19:03:44 +0100 Subject: [PATCH 2/2] Use dispatch-client version with flakey-tests fix Signed-off-by: Mathias L. Baumann --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index f72f392..0dcc6b8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,7 +40,7 @@ dependencies = [ # plugins.mkdocstrings.handlers.python.import) "frequenz-sdk >= 1.0.0-rc1302, < 1.0.0-rc1500", "frequenz-channels >= 1.3.0, < 2.0.0", - "frequenz-client-dispatch >= 0.8.2, < 0.9.0", + "frequenz-client-dispatch >= 0.8.4, < 0.9.0", ] dynamic = ["version"]