@@ -835,11 +835,40 @@ async def test_wait_for_idle_with_exact_units_scale_down(event_loop):
835835 await app .destroy_units (* two_units_to_remove )
836836
837837 # assert that the following wait is not returning instantaneously
838- starttime = time .time ()
838+ start_time = time .time ()
839839 await model .wait_for_idle (timeout = 5 * 60 , wait_for_exact_units = 1 )
840- endtime = time .time ()
840+ end_time = time .time ()
841841 # checking if waited more than 10ms
842- assert (endtime - starttime ) > 0.001
842+ assert (end_time - start_time ) > 0.001
843+
844+
845+ @base .bootstrapped
846+ @pytest .mark .asyncio
847+ async def test_wait_for_idle_with_exact_units_scale_down_zero (event_loop ):
848+ """Deploys 3 units, waits for them to be idle, then removes 3 of them,
849+ then waits for exactly 0 unit to be left.
850+
851+ """
852+ async with base .CleanModel () as model :
853+ app = await model .deploy (
854+ 'ubuntu' ,
855+ application_name = 'ubuntu' ,
856+ series = 'bionic' ,
857+ channel = 'stable' ,
858+ num_units = 3 ,
859+ )
860+ await model .wait_for_idle (timeout = 5 * 60 , wait_for_exact_units = 3 )
861+
862+ units_to_remove = [u .name for u in app .units ]
863+ # Remove all the units
864+ await app .destroy_units (* units_to_remove )
865+
866+ # assert that the following wait is not returning instantaneously
867+ start_time = time .time ()
868+ await model .wait_for_idle (timeout = 5 * 60 , wait_for_exact_units = 0 )
869+ end_time = time .time ()
870+ # checking if waited more than 10ms
871+ assert (end_time - start_time ) > 0.001
843872
844873
845874@base .bootstrapped
0 commit comments