Skip to content

Commit 4d24320

Browse files
authored
Fix flakey tests (#99)
- **Fix test_env in test that re-created it** - **Use dispatch-client version with flakey-tests fix**
2 parents 57204b6 + 30b99e1 commit 4d24320

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ dependencies = [
4040
# plugins.mkdocstrings.handlers.python.import)
4141
"frequenz-sdk >= 1.0.0-rc1302, < 1.0.0-rc1500",
4242
"frequenz-channels >= 1.3.0, < 2.0.0",
43-
"frequenz-client-dispatch >= 0.8.2, < 0.9.0",
43+
"frequenz-client-dispatch >= 0.8.4, < 0.9.0",
4444
]
4545
dynamic = ["version"]
4646

tests/test_frequenz_dispatch.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ async def test_dispatch_new_but_finished(
426426
generator: DispatchGenerator,
427427
fake_time: time_machine.Coordinates,
428428
) -> None:
429-
"""Test that a dispatch that is already finished is not started."""
429+
"""Test that a finished dispatch is not started at startup."""
430430
# Generate a dispatch that is already finished
431431
finished_dispatch = generator.generate_dispatch()
432432
finished_dispatch = replace(
@@ -437,10 +437,25 @@ async def test_dispatch_new_but_finished(
437437
recurrence=RecurrenceRule(),
438438
type="TEST_TYPE",
439439
)
440-
# Create an old dispatch
440+
# Inject an old dispatch
441441
test_env.client.set_dispatches(test_env.microgrid_id, [finished_dispatch])
442442
await test_env.service.stop()
443443
test_env.service.start()
444+
test_env = replace(
445+
test_env,
446+
lifecycle_events=test_env.service.new_lifecycle_events_receiver("TEST_TYPE"),
447+
running_state_change=(
448+
await test_env.service.new_running_state_event_receiver(
449+
"TEST_TYPE", unify_running_intervals=False
450+
)
451+
),
452+
)
453+
454+
fake_time.shift(timedelta(seconds=1))
455+
# Process the lifecycle event caused by the old dispatch at startup
456+
await test_env.lifecycle_events.receive()
457+
458+
await asyncio.sleep(1)
444459

445460
# Create another dispatch the normal way
446461
new_dispatch = generator.generate_dispatch()
@@ -452,8 +467,7 @@ async def test_dispatch_new_but_finished(
452467
recurrence=RecurrenceRule(),
453468
type="TEST_TYPE",
454469
)
455-
# Consume one lifecycle_updates event
456-
await test_env.lifecycle_events.receive()
470+
457471
new_dispatch = await _test_new_dispatch_created(test_env, new_dispatch)
458472

459473
# Advance time to when the new dispatch should still not start

0 commit comments

Comments
 (0)