Skip to content

Commit

Permalink
fix: Use busy flush on stop (#414)
Browse files Browse the repository at this point in the history
* use busy flush on stop

* add unit test

* generate src-docs

* add changelog
  • Loading branch information
cbartz authored Dec 5, 2024
1 parent 2fd5437 commit 20b6513
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

### 2024-12-04

- Clean up corresponding OpenStack runner resources when a unit of the charm is removed.

### 2024-11-27

- Fix "Available Runners" dashboard panel to work for multiple flavors.
Expand Down
2 changes: 1 addition & 1 deletion github-runner-manager/src-docs/reactive.consumer.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Log the job details and acknowledge the message. If the job details are invalid,

---

<a href="../../reactive/consumer/signal_handler#L234"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../../reactive/consumer/signal_handler#L238"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>function</kbd> `signal_handler`

Expand Down
2 changes: 1 addition & 1 deletion src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ def _on_stop(self, _: StopEvent) -> None:

if state.instance_type == InstanceType.OPENSTACK:
runner_scaler = self._get_runner_scaler(state)
runner_scaler.flush()
runner_scaler.flush(FlushMode.FLUSH_BUSY)
return

runner_manager = self._get_runner_manager(state)
Expand Down
19 changes: 19 additions & 0 deletions tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import pytest
import yaml
from github_runner_manager.errors import ReconcileError
from github_runner_manager.manager.runner_manager import FlushMode
from github_runner_manager.manager.runner_scaler import RunnerScaler
from github_runner_manager.types_.github import GitHubOrg, GitHubRepo, GitHubRunnerStatus
from ops.model import ActiveStatus, BlockedStatus, MaintenanceStatus, StatusBase, WaitingStatus
Expand Down Expand Up @@ -392,6 +393,24 @@ def test_on_reconcile_runners_reconcile_error(harness: Harness, monkeypatch: pyt
assert harness.charm.unit.status.message == ACTIVE_STATUS_RECONCILIATION_FAILED_MSG


def test_on_stop_busy_flush(harness: Harness, monkeypatch: pytest.MonkeyPatch):
"""
arrange: Set up charm with Openstack mode and runner scaler mock.
act: Trigger stop event.
assert: Runner scaler mock flushes the runners using busy mode.
"""
state_mock = MagicMock()
state_mock.instance_type = InstanceType.OPENSTACK
harness.charm._setup_state = MagicMock(return_value=state_mock)
runner_scaler_mock = MagicMock(spec=RunnerScaler)
harness.charm._get_runner_scaler = MagicMock(return_value=runner_scaler_mock)
mock_event = MagicMock()

harness.charm._on_stop(mock_event)

runner_scaler_mock.flush.assert_called_once_with(FlushMode.FLUSH_BUSY)


@pytest.mark.parametrize(
"hook",
[
Expand Down

0 comments on commit 20b6513

Please sign in to comment.