|
21 | 21 | ) |
22 | 22 | from ..exceptions import NoWorkingDeviceConnectionError |
23 | 23 | from ..signals import is_working_changed |
24 | | -from ..tasks import _TASK_NAME, update_config |
| 24 | +from ..tasks import _TASK_NAME, _is_update_in_progress, update_config |
25 | 25 | from .utils import CreateConnectionsMixin |
26 | 26 |
|
27 | 27 | Config = load_model("config", "Config") |
@@ -1047,6 +1047,25 @@ def test_device_update_config_in_progress( |
1047 | 1047 | mocked_get_working_connection.assert_not_called() |
1048 | 1048 | update_config.assert_not_called() |
1049 | 1049 |
|
| 1050 | + def test_update_in_progress_ignores_current_task(self): |
| 1051 | + """Regression test: _is_update_in_progress must not match the |
| 1052 | + currently running task, which would cause it to skip itself.""" |
| 1053 | + conf = self._prepare_conf_object() |
| 1054 | + with mock.patch("celery.app.control.Inspect.active") as mocked_active: |
| 1055 | + mocked_active.return_value = { |
| 1056 | + "worker1": [ |
| 1057 | + { |
| 1058 | + "name": _TASK_NAME, |
| 1059 | + "args": [str(conf.device.pk)], |
| 1060 | + "id": "current-task-id", |
| 1061 | + } |
| 1062 | + ] |
| 1063 | + } |
| 1064 | + result = _is_update_in_progress( |
| 1065 | + conf.device.pk, current_task_id="current-task-id" |
| 1066 | + ) |
| 1067 | + self.assertFalse(result) |
| 1068 | + |
1050 | 1069 | @mock.patch("time.sleep") |
1051 | 1070 | @mock.patch.object(DeviceConnection, "update_config") |
1052 | 1071 | @mock.patch.object(DeviceConnection, "get_working_connection") |
|
0 commit comments