@@ -1649,43 +1649,23 @@ async def flaky_save(module, filename, data, **kwargs):
16491649 print (" ✓ A failed control state save is retried" )
16501650
16511651
1652- def test_control_state_load_returning_nothing_is_retried_then_given_up ():
1653- """Storage returns None for a failed read as well as a missing file, so a None is retried a few times."""
1654- storage = _storage_with_paused ("101" )
1655- real_load = storage .load
1656- answers = [None ]
1652+ def test_control_state_with_nothing_saved_is_read_once ():
1653+ """An empty answer from Storage means nothing is saved: it is read once, as the other components do."""
1654+ storage = _Storage ()
16571655 calls = []
16581656
1659- async def flaky_load (module , filename ):
1660- """Return None once, as a failed read does, then the real data."""
1661- calls .append (filename )
1662- if answers :
1663- return answers .pop ()
1664- return await real_load (module , filename )
1665-
1666- storage .load = flaky_load
1667- component = _make_component ({101 : _status (status_id = 178 , power = 0 )}, wallbox_control = False )
1668- component .base .components = _Components (storage )
1669- run_async (component .run (0 , True ))
1670- assert component .transport .count ("resume" ) == 0
1671- run_async (component .run (120 , False ))
1672- assert component .transport .count ("resume" ) == 1 , "The saved charger was released once the read worked"
1673-
1674- empty = _Storage ()
1675- empty_calls = []
1676-
16771657 async def counting_load (module , filename ):
16781658 """Always empty, counting the reads."""
1679- empty_calls .append (filename )
1659+ calls .append (filename )
16801660 return None
16811661
1682- empty .load = counting_load
1662+ storage .load = counting_load
16831663 component = _make_component ()
1684- component .base .components = _Components (empty )
1685- for cycle in range (12 ):
1664+ component .base .components = _Components (storage )
1665+ for cycle in range (6 ):
16861666 run_async (component .run (cycle * 60 , cycle == 0 ))
1687- assert 1 < len (empty_calls ) <= 5 , "A file that is simply absent is not read forever : {}" .format (len (empty_calls ))
1688- print (" ✓ An empty control state read is retried a few times, then left " )
1667+ assert len (calls ) == 1 , "Read once, not on every cycle : {}" .format (len (calls ))
1668+ print (" ✓ With nothing saved, the control state is read once " )
16891669
16901670
16911671def test_schedule_restoration_is_retried_after_a_failure ():
@@ -1798,7 +1778,7 @@ def test_wallbox(my_predbat=None):
17981778 test_account_wide_errors_still_stop_the_control_loop ()
17991779 test_pause_is_persisted_before_it_is_sent ()
18001780 test_failed_control_state_save_is_retried ()
1801- test_control_state_load_returning_nothing_is_retried_then_given_up ()
1781+ test_control_state_with_nothing_saved_is_read_once ()
18021782 test_schedule_restoration_is_retried_after_a_failure ()
18031783 print ("=" * 70 )
18041784 return False
0 commit comments