Skip to content

Commit

Permalink
Fix integration tests (#68)
Browse files Browse the repository at this point in the history
* fix integration tests

* mix agent versions
  • Loading branch information
zmraul committed Jun 14, 2023
1 parent 5b79600 commit 1c89860
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 35 deletions.
13 changes: 4 additions & 9 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ jobs:
uses: charmed-kubernetes/actions-operator@main
with:
provider: microk8s
# This is needed until https://bugs.launchpad.net/juju/+bug/1977582 is fixed
bootstrap-options: "--agent-version 2.9.29"
bootstrap-options: "--agent-version 2.9.43"
- name: Run integration tests
run: tox -e integration-charm

Expand All @@ -57,8 +56,7 @@ jobs:
uses: charmed-kubernetes/actions-operator@main
with:
provider: microk8s
# This is needed until https://bugs.launchpad.net/juju/+bug/1977582 is fixed
bootstrap-options: "--agent-version 2.9.29"
bootstrap-options: "--agent-version 2.9.43"
- name: Run integration tests
run: tox -e integration-relation

Expand All @@ -75,8 +73,7 @@ jobs:
uses: charmed-kubernetes/actions-operator@main
with:
provider: microk8s
# This is needed until https://bugs.launchpad.net/juju/+bug/1977582 is fixed
bootstrap-options: "--agent-version 2.9.29"
bootstrap-options: "--agent-version 2.9.43"
- name: Run integration tests
run: tox -e integration-relation -- --num-units 1

Expand All @@ -93,8 +90,7 @@ jobs:
uses: charmed-kubernetes/actions-operator@main
with:
provider: microk8s
# This is needed until https://bugs.launchpad.net/juju/+bug/1977582 is fixed
bootstrap-options: "--agent-version 2.9.29"
bootstrap-options: "--agent-version 2.9.43"
- name: Run integration tests
run: tox -e integration-password

Expand All @@ -111,7 +107,6 @@ jobs:
uses: charmed-kubernetes/actions-operator@main
with:
provider: microk8s
# This is needed until https://bugs.launchpad.net/juju/+bug/1977582 is fixed
bootstrap-options: "--agent-version 2.9.29"
- name: Run integration tests
run: tox -e integration-scaling
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright 2022 Canonical Ltd.
# See LICENSE file for licensing details.

ops~=1.5.0
ops~=2.3.0
redis~=4.3.4
jinja2==3.1.1
tenacity==8.0.1
32 changes: 20 additions & 12 deletions tests/integration/test_redis_relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,22 @@ async def test_build_and_deploy(ops_test: OpsTest, num_units: int):
FIRST_DISCOURSE_APP_NAME, application_name=FIRST_DISCOURSE_APP_NAME, series="focal"
),
ops_test.model.deploy(
POSTGRESQL_APP_NAME, application_name=POSTGRESQL_APP_NAME, series="focal"
POSTGRESQL_APP_NAME,
application_name=POSTGRESQL_APP_NAME,
channel="latest/stable",
series="focal",
),
)
await ops_test.model.wait_for_idle(
apps=[APP_NAME, POSTGRESQL_APP_NAME], status="active", timeout=3000
apps=[APP_NAME, POSTGRESQL_APP_NAME], status="active", idle_period=20, timeout=3000
)
# Discourse becomes blocked waiting for relations.
await ops_test.model.wait_for_idle(
apps=[FIRST_DISCOURSE_APP_NAME], status="blocked", timeout=3000
apps=[FIRST_DISCOURSE_APP_NAME], status="waiting", idle_period=20, timeout=3000
)

assert (
ops_test.model.applications[FIRST_DISCOURSE_APP_NAME].units[0].workload_status == "blocked"
ops_test.model.applications[FIRST_DISCOURSE_APP_NAME].units[0].workload_status == "waiting"
)
assert ops_test.model.applications[POSTGRESQL_APP_NAME].units[0].workload_status == "active"

Expand All @@ -98,8 +101,13 @@ async def test_discourse_relation(ops_test: OpsTest):
"""

await ops_test.model.block_until(
lambda: check_application_status(ops_test, "discourse-k8s") == "active",
timeout=600,
lambda: check_application_status(ops_test, FIRST_DISCOURSE_APP_NAME) == "active",
timeout=900,
wait_period=5,
)
await ops_test.model.block_until(
lambda: check_application_status(ops_test, POSTGRESQL_APP_NAME) == "active",
timeout=900,
wait_period=5,
)

Expand All @@ -113,9 +121,7 @@ async def test_discourse_request(ops_test: OpsTest):
assert response.status == 200


async def test_delete_redis_pod(
ops_test: OpsTest,
):
async def test_delete_redis_pod(ops_test: OpsTest):
"""Delete the leader redis-k8s pod.
Check relation data updated with the new redis-k8s pod IP after pod revived by juju.
Expand All @@ -127,16 +133,18 @@ async def test_delete_redis_pod(

client = AsyncClient(namespace=ops_test.model.info.name)
await client.delete(Pod, name=f"{APP_NAME}-{leader_unit_num}")
await ops_test.model.wait_for_idle(status="active")
# Wait for `upgrade_charm` sequence
await ops_test.model.wait_for_idle(
apps=[APP_NAME], status="active", timeout=1000, idle_period=60
)
await ops_test.model.block_until(
lambda: check_application_status(ops_test, FIRST_DISCOURSE_APP_NAME) == "active",
timeout=600,
wait_period=5,
)

redis_ip_after = await get_address(ops_test, app_name=APP_NAME, unit_num=leader_unit_num)
# discourse restarted, unit_num += 1
discourse_ip = await get_address(ops_test, app_name=FIRST_DISCOURSE_APP_NAME, unit_num=1)
discourse_ip = await get_address(ops_test, app_name=FIRST_DISCOURSE_APP_NAME)
url = f"http://{discourse_ip}:3000/site.json"
response = query_url(url)

Expand Down
2 changes: 2 additions & 0 deletions tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def setUp(self):

self.harness = Harness(RedisK8sCharm)
self.addCleanup(self.harness.cleanup)
self.harness.set_can_connect("redis", True)
self.harness.set_can_connect("sentinel", True)
self.harness.begin()
self.harness.add_relation(self._peer_relation, self.harness.charm.app.name)

Expand Down
21 changes: 8 additions & 13 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,10 @@ commands =
description = Run integration tests
deps =
pytest
# This is needed because of https://github.com/juju/python-libjuju/pull/698
juju==2.9.11
juju==2.9.42.4
pytest-operator
pytest-order
lightkube==0.10.0
lightkube==0.13.0
-r{toxinidir}/requirements.txt
commands =
pytest -vv --tb native --ignore={[vars]tst_path}unit --log-cli-level=INFO -s {posargs} --durations=0
Expand All @@ -82,10 +81,9 @@ commands =
description = Run charm integration tests
deps =
pytest
# This is needed because of https://github.com/juju/python-libjuju/pull/698
juju==2.9.11
juju==2.9.42.4
pytest-operator
lightkube==0.10.0
lightkube==0.13.0
-r{toxinidir}/requirements.txt
commands =
pytest {[vars]tst_path}/integration/test_charm.py -vv --tb native --ignore={[vars]tst_path}unit --log-cli-level=INFO -s {posargs} --durations=0
Expand All @@ -94,8 +92,7 @@ commands =
description = Run scaling integration tests
deps =
pytest
# This is needed because of https://github.com/juju/python-libjuju/pull/698
juju==2.9.11
juju==2.9.42.4
pytest-operator
pytest-order
-r{toxinidir}/requirements.txt
Expand All @@ -106,8 +103,7 @@ commands =
description = Run password integration tests
deps =
pytest
# This is needed because of https://github.com/juju/python-libjuju/pull/698
juju==2.9.11
juju==2.9.42.4
pytest-operator
-r{toxinidir}/requirements.txt
commands =
Expand All @@ -117,10 +113,9 @@ commands =
description = Run integration tests for redis relation
deps =
pytest
# This is needed because of https://github.com/juju/python-libjuju/pull/698
juju==2.9.11
juju==2.9.42.4
pytest-operator
lightkube==0.10.0
lightkube==0.13.0
-r{toxinidir}/requirements.txt
commands =
pytest {[vars]tst_path}/integration/test_redis_relation.py -vv --tb native --ignore={[vars]tst_path}unit --log-cli-level=INFO -s {posargs} --durations=0

0 comments on commit 1c89860

Please sign in to comment.