22# Licensed under the Apache V2, see LICENCE file for details.
33from __future__ import annotations
44
5- import pytest
65from freezegun import freeze_time
76
87from juju .model ._idle import CheckStatus , loop
98
10-
119# Missing tests
1210#
1311# FIXME hexanator idle period 1
1816# FIXME expected idle 1s below
1917# FIXME idle period 1
2018# FIXME sending status=None, meaning some apps are still missing
21- #
22- @ pytest . mark . xfail ( reason = "FIXME I misunderstood what 'idle' means" )
19+
20+
2321async def test_at_least_units ():
2422 async def checks ():
25- yield CheckStatus ({"u/0" , "u/1" , "u/2" }, {"u/0" }, set ())
26- yield CheckStatus ({"u/0" , "u/1" , "u/2" }, {"u/0" , "u/1" }, set ())
27- yield CheckStatus ({"u/0" , "u/1" , "u/2" }, {"u/0" , "u/1" , "u/2" }, set ())
23+ yield CheckStatus ({"u/0" , "u/1" , "u/2" }, {"u/0" }, {"u/0" , "u/1" , "u/2" })
24+ yield CheckStatus ({"u/0" , "u/1" , "u/2" }, {"u/0" , "u/1" }, {"u/0" , "u/1" , "u/2" })
25+ yield CheckStatus (
26+ {"u/0" , "u/1" , "u/2" }, {"u/0" , "u/1" , "u/2" }, {"u/0" , "u/1" , "u/2" }
27+ )
2828
2929 with freeze_time ():
3030 assert [
@@ -38,6 +38,41 @@ async def checks():
3838 ] == [False , True , True ]
3939
4040
41+ async def test_for_exact_units ():
42+ good = CheckStatus (
43+ {"u/0" , "u/1" , "u/2" },
44+ {"u/1" , "u/2" },
45+ {"u/0" , "u/1" , "u/2" },
46+ )
47+ too_few = CheckStatus (
48+ {"u/0" , "u/1" , "u/2" },
49+ {"u/2" },
50+ {"u/0" , "u/1" , "u/2" },
51+ )
52+ too_many = CheckStatus (
53+ {"u/0" , "u/1" , "u/2" },
54+ {"u/1" , "u/2" , "u/0" },
55+ {"u/0" , "u/1" , "u/2" },
56+ )
57+
58+ async def checks ():
59+ yield too_few
60+ yield good
61+ yield too_many
62+ yield good
63+
64+ assert [
65+ v
66+ async for v in loop (
67+ checks (),
68+ apps = frozenset (["u" ]),
69+ wait_for_units = 1 ,
70+ wait_for_exact_units = 2 ,
71+ idle_period = 0 ,
72+ )
73+ ] == [False , True , False , True ]
74+
75+
4176async def test_ping_pong ():
4277 good = CheckStatus ({"hexanator/0" }, {"hexanator/0" }, set ())
4378 bad = CheckStatus ({"hexanator/0" }, set (), set ())
0 commit comments