66
77from juju .model ._idle import CheckStatus , loop
88
9- # Missing tests
10- #
11- # FIXME hexanator idle period 1
12- # FIXME workload maintenance, idle period 0
13- # FIXME test exact count == 2
14- # FIXME test exact count != 2 (1, 3)
15- # FIXME exact count vs wait_for_units
16- # FIXME expected idle 1s below
17- # FIXME idle period 1
18- # FIXME sending status=None, meaning some apps are still missing
9+
10+ async def alist (agen ):
11+ return [v async for v in agen ]
12+
13+
14+ async def test_wait_for_apps ():
15+ async def checks ():
16+ yield None
17+ yield None
18+
19+ assert await alist (
20+ loop (
21+ checks (),
22+ apps = frozenset (["a" ]),
23+ wait_for_units = 0 ,
24+ idle_period = 0 ,
25+ )
26+ ) == [False , False ]
1927
2028
2129async def test_at_least_units ():
@@ -27,15 +35,14 @@ async def checks():
2735 )
2836
2937 with freeze_time ():
30- assert [
31- v
32- async for v in loop (
38+ assert await alist (
39+ loop (
3340 checks (),
3441 apps = frozenset (["u" ]),
3542 wait_for_units = 2 ,
3643 idle_period = 0 ,
3744 )
38- ] == [False , True , True ]
45+ ) == [False , True , True ]
3946
4047
4148async def test_for_exact_units ():
@@ -61,36 +68,49 @@ async def checks():
6168 yield too_many
6269 yield good
6370
64- assert [
65- v
66- async for v in loop (
71+ assert await alist (
72+ loop (
6773 checks (),
6874 apps = frozenset (["u" ]),
6975 wait_for_units = 1 ,
7076 wait_for_exact_units = 2 ,
7177 idle_period = 0 ,
7278 )
73- ] == [False , True , False , True ]
79+ ) == [False , True , False , True ]
7480
7581
76- async def test_ping_pong ():
77- good = CheckStatus ({"hexanator/0" }, {"hexanator/0" }, set () )
78- bad = CheckStatus ({"hexanator/0" }, set () , set ())
82+ async def test_idle_ping_pong ():
83+ good = CheckStatus ({"hexanator/0" }, {"hexanator/0" }, { "hexanator/0" } )
84+ bad = CheckStatus ({"hexanator/0" }, { "hexanator/0" } , set ())
7985
8086 async def checks ():
8187 with freeze_time () as clock :
82- for _ in range ( 3 ) :
83- yield good
88+ for status in [ good , bad , good , bad ] :
89+ yield status
8490 clock .tick (10 )
85- yield bad
91+
92+ assert await alist (
93+ loop (
94+ checks (),
95+ apps = frozenset (["hexanator" ]),
96+ wait_for_units = 1 ,
97+ idle_period = 15 ,
98+ )
99+ ) == [False , False , False , False ]
100+
101+
102+ async def test_idle_period ():
103+ async def checks ():
104+ with freeze_time () as clock :
105+ for _ in range (4 ):
106+ yield CheckStatus ({"hexanator/0" }, {"hexanator/0" }, {"hexanator/0" })
86107 clock .tick (10 )
87108
88- assert [
89- v
90- async for v in loop (
109+ assert await alist (
110+ loop (
91111 checks (),
92112 apps = frozenset (["hexanator" ]),
93113 wait_for_units = 1 ,
94114 idle_period = 15 ,
95115 )
96- ] == [False ] * 6
116+ ) == [False , False , True , True ]
0 commit comments