Skip to content

Commit a69c2e4

Browse files
committed
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 <[email protected]>
1 parent 636b887 commit a69c2e4

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

Diff for: pyproject.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +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",
44-
"frequenz-client-dispatch @ git+https://github.com/frequenz-floss/frequenz-client-dispatch-python.git@refs/pull/124/head",
43+
"frequenz-client-dispatch >= 0.8.2, < 0.9.0",
4544
]
4645
dynamic = ["version"]
4746

@@ -95,6 +94,8 @@ dev-pytest = [
9594
"pytest-asyncio == 0.25.1",
9695
"async-solipsism == 0.7",
9796
"time-machine == 2.16.0",
97+
# For testing we require at least this version of the client
98+
"frequenz-client-dispatch >= 0.8.4, < 0.9.0",
9899
]
99100
dev = [
100101
"frequenz-dispatch[dev-mkdocs,dev-flake8,dev-formatting,dev-mkdocs,dev-mypy,dev-noxfile,dev-pylint,dev-pytest]",

Diff for: tests/test_frequenz_dispatch.py

+18-4
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)