@@ -426,7 +426,7 @@ async def test_dispatch_new_but_finished(
426
426
generator : DispatchGenerator ,
427
427
fake_time : time_machine .Coordinates ,
428
428
) -> None :
429
- """Test that a dispatch that is already finished is not started."""
429
+ """Test that a finished dispatch is not started at startup ."""
430
430
# Generate a dispatch that is already finished
431
431
finished_dispatch = generator .generate_dispatch ()
432
432
finished_dispatch = replace (
@@ -437,10 +437,25 @@ async def test_dispatch_new_but_finished(
437
437
recurrence = RecurrenceRule (),
438
438
type = "TEST_TYPE" ,
439
439
)
440
- # Create an old dispatch
440
+ # Inject an old dispatch
441
441
test_env .client .set_dispatches (test_env .microgrid_id , [finished_dispatch ])
442
442
await test_env .service .stop ()
443
443
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 )
444
459
445
460
# Create another dispatch the normal way
446
461
new_dispatch = generator .generate_dispatch ()
@@ -452,8 +467,7 @@ async def test_dispatch_new_but_finished(
452
467
recurrence = RecurrenceRule (),
453
468
type = "TEST_TYPE" ,
454
469
)
455
- # Consume one lifecycle_updates event
456
- await test_env .lifecycle_events .receive ()
470
+
457
471
new_dispatch = await _test_new_dispatch_created (test_env , new_dispatch )
458
472
459
473
# Advance time to when the new dispatch should still not start
0 commit comments