Skip to content

Commit c6087a3

Browse files
committed
fix: async filter should output only one result for each input
1 parent 1951425 commit c6087a3

5 files changed

Lines changed: 49 additions & 13 deletions

File tree

juju/model/_idle.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ async def loop(
8080
wait_for_units,
8181
)
8282
yield False
83-
continue
83+
break
8484

8585
if (
8686
wait_for_exact_units is not None
@@ -93,9 +93,9 @@ async def loop(
9393
wait_for_exact_units,
9494
)
9595
yield False
96-
continue
97-
98-
yield True
96+
break
97+
else:
98+
yield True
9999

100100

101101
def check(

juju/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66

77
DEFAULT_ARCHITECTURE = "amd64"
88

9-
CLIENT_VERSION = "3.6.1.0rc3"
9+
CLIENT_VERSION = "3.6.1.0rc4"

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "juju"
3-
version = "3.6.1.0rc3" # Stop-gap until dynamic versioning is done; must be in sync with juju/version.py:CLIENT_VERSION
3+
version = "3.6.1.0rc4" # Stop-gap until dynamic versioning is done; must be in sync with juju/version.py:CLIENT_VERSION
44
description = "Python library for Juju"
55
readme = "docs/readme.rst"
66
license = { file = "LICENSE" }

tests/unit/test_idle_loop.py

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22
# Licensed under the Apache V2, see LICENCE file for details.
33
from __future__ import annotations
44

5-
import pytest
65
from freezegun import freeze_time
76

87
from juju.model._idle import CheckStatus, loop
98

10-
119
# Missing tests
1210
#
1311
# FIXME hexanator idle period 1
@@ -18,13 +16,15 @@
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+
2321
async 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+
4176
async def test_ping_pong():
4277
good = CheckStatus({"hexanator/0"}, {"hexanator/0"}, set())
4378
bad = CheckStatus({"hexanator/0"}, set(), set())

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ commands =
4343
envdir = {toxworkdir}/py3
4444
commands =
4545
pytest \
46+
--log-level=DEBUG \
4647
--tb native \
4748
-m 'not serial' \
4849
{posargs} \

0 commit comments

Comments
 (0)