Skip to content

Commit

Permalink
Combined the two scheduled event test
Browse files Browse the repository at this point in the history
  • Loading branch information
yhaliaw committed Sep 7, 2023
1 parent e44d992 commit dbe55b1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 26 deletions.
2 changes: 1 addition & 1 deletion tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ async def app_scheduled_events(
"virtual-machines": 0,
"denylist": "10.10.0.0/16",
"test-mode": "insecure",
"reconcile-interval": 3,
"reconcile-interval": 10,
},
)
await model.wait_for_idle(status=ACTIVE_STATUS_NAME)
Expand Down
34 changes: 9 additions & 25 deletions tests/integration/test_charm_scheduled_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@ async def test_update_interval(model: Model, app_scheduled_events: Application)
"""
arrange: An working application with one runner.
act:
1. Remove runner binary.
2. Wait for 3 minutes.
1. a. Remove runner binary.
b. Crash the one runner
2. Wait for 3 minutes, and then wait for ActiveStatus.
assert:
1. No runner binary exists.
3. Runner binary exists.
1. a. No runner binary exists.
b. No runner exists.
2. a. Runner binary exists.
b. One runner exists. The runner name should not be the same as the starting one.
This tests whether the reconcile-runner event is triggered, and updates the dependencies.
The reconciliation logic is tested with the reconcile-runners action.
Expand All @@ -44,35 +47,16 @@ async def test_update_interval(model: Model, app_scheduled_events: Application)
await run_in_unit(unit, f"rm -f {RunnerManager.runner_bin_path}")
assert not await check_runner_binary_exists(unit)

await sleep(3 * 60 + 5)

await model.wait_for_idle(status=ACTIVE_STATUS_NAME)
assert await check_runner_binary_exists(unit)


@pytest.mark.asyncio
@pytest.mark.abort_on_fail
async def test_reconcile_interval(model: Model, app_scheduled_events: Application) -> None:
"""
arrange: An working application with one runner.
act:
1. Crash the one runner
2. Wait for 3 minutes, and then wait for ActiveStatus.
assert:
1. No runner exists.
2. One runner exists. The runner name should not be the same as the starting one.
"""
unit = app_scheduled_events.units[0]

runner_names = await get_runner_names(unit)
assert len(runner_names) == 1
runner_name = runner_names[0]
await run_in_unit(unit, f"lxc stop --force {runner_name}")
await wait_till_num_of_runners(unit, 0)

await sleep(3 * 60 + 5)
await sleep(10 * 60 + 5)

await model.wait_for_idle(status=ACTIVE_STATUS_NAME)
assert await check_runner_binary_exists(unit)

runner_names = await get_runner_names(unit)
assert len(runner_names) == 1
Expand Down

0 comments on commit dbe55b1

Please sign in to comment.