Skip to content

Commit

Permalink
fix: async filter should output only one result for each input
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaqq committed Dec 18, 2024
1 parent 1951425 commit c6087a3
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 13 deletions.
8 changes: 4 additions & 4 deletions juju/model/_idle.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ async def loop(
wait_for_units,
)
yield False
continue
break

if (
wait_for_exact_units is not None
Expand All @@ -93,9 +93,9 @@ async def loop(
wait_for_exact_units,
)
yield False
continue

yield True
break
else:
yield True


def check(
Expand Down
2 changes: 1 addition & 1 deletion juju/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

DEFAULT_ARCHITECTURE = "amd64"

CLIENT_VERSION = "3.6.1.0rc3"
CLIENT_VERSION = "3.6.1.0rc4"
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "juju"
version = "3.6.1.0rc3" # Stop-gap until dynamic versioning is done; must be in sync with juju/version.py:CLIENT_VERSION
version = "3.6.1.0rc4" # Stop-gap until dynamic versioning is done; must be in sync with juju/version.py:CLIENT_VERSION
description = "Python library for Juju"
readme = "docs/readme.rst"
license = { file = "LICENSE" }
Expand Down
49 changes: 42 additions & 7 deletions tests/unit/test_idle_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
# Licensed under the Apache V2, see LICENCE file for details.
from __future__ import annotations

import pytest
from freezegun import freeze_time

from juju.model._idle import CheckStatus, loop


# Missing tests
#
# FIXME hexanator idle period 1
Expand All @@ -18,13 +16,15 @@
# FIXME expected idle 1s below
# FIXME idle period 1
# FIXME sending status=None, meaning some apps are still missing
#
@pytest.mark.xfail(reason="FIXME I misunderstood what 'idle' means")


async def test_at_least_units():
async def checks():
yield CheckStatus({"u/0", "u/1", "u/2"}, {"u/0"}, set())
yield CheckStatus({"u/0", "u/1", "u/2"}, {"u/0", "u/1"}, set())
yield CheckStatus({"u/0", "u/1", "u/2"}, {"u/0", "u/1", "u/2"}, set())
yield CheckStatus({"u/0", "u/1", "u/2"}, {"u/0"}, {"u/0", "u/1", "u/2"})
yield CheckStatus({"u/0", "u/1", "u/2"}, {"u/0", "u/1"}, {"u/0", "u/1", "u/2"})
yield CheckStatus(
{"u/0", "u/1", "u/2"}, {"u/0", "u/1", "u/2"}, {"u/0", "u/1", "u/2"}
)

with freeze_time():
assert [
Expand All @@ -38,6 +38,41 @@ async def checks():
] == [False, True, True]


async def test_for_exact_units():
good = CheckStatus(
{"u/0", "u/1", "u/2"},
{"u/1", "u/2"},
{"u/0", "u/1", "u/2"},
)
too_few = CheckStatus(
{"u/0", "u/1", "u/2"},
{"u/2"},
{"u/0", "u/1", "u/2"},
)
too_many = CheckStatus(
{"u/0", "u/1", "u/2"},
{"u/1", "u/2", "u/0"},
{"u/0", "u/1", "u/2"},
)

async def checks():
yield too_few
yield good
yield too_many
yield good

assert [
v
async for v in loop(
checks(),
apps=frozenset(["u"]),
wait_for_units=1,
wait_for_exact_units=2,
idle_period=0,
)
] == [False, True, False, True]


async def test_ping_pong():
good = CheckStatus({"hexanator/0"}, {"hexanator/0"}, set())
bad = CheckStatus({"hexanator/0"}, set(), set())
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ commands =
envdir = {toxworkdir}/py3
commands =
pytest \
--log-level=DEBUG \
--tb native \
-m 'not serial' \
{posargs} \
Expand Down

0 comments on commit c6087a3

Please sign in to comment.