Skip to content

Commit

Permalink
add test for should exit
Browse files Browse the repository at this point in the history
  • Loading branch information
ekneg54 committed Sep 28, 2024
1 parent 9935c13 commit 6784019
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 23 deletions.
17 changes: 3 additions & 14 deletions tests/unit/framework/test_pipeline_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,6 @@ def test_restart_injects_healthcheck_functions(self):
pipeline_manager.restart()
pipeline_manager.prometheus_exporter.update_healthchecks.assert_called()

def test_restart_ensures_prometheus_exporter_is_running(self):
config = deepcopy(self.config)
config.metrics = MetricsConfig(enabled=True, port=666)
pipeline_manager = PipelineManager(config)
pipeline_manager.prometheus_exporter._prepare_multiprocessing = mock.MagicMock()
with mock.patch("logprep.util.http.ThreadingHTTPServer"):
pipeline_manager.restart()
pipeline_manager.prometheus_exporter.server.start.assert_called()

def test_reload_calls_set_count_twice(self):
with mock.patch.object(self.manager, "set_count") as mock_set_count:
self.manager.reload()
Expand All @@ -281,11 +272,9 @@ def test_should_exit_returns_bool_based_on_restart_count(self):
assert manager.should_exit()

def test_stop_calls_stop_on_loghandler(self):
self.config.error_output = {"dummy": {"type": "dummy_output"}}
with mock.patch("logprep.framework.pipeline_manager.ComponentQueueListener"):
manager = PipelineManager(self.config)
manager.loghandler = mock.MagicMock()
manager.stop()
manager = PipelineManager(self.config)
manager.loghandler = mock.MagicMock()
manager.stop()
manager.loghandler.stop.assert_called()


Expand Down
18 changes: 9 additions & 9 deletions tests/unit/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# pylint: disable=attribute-defined-outside-init
import re
import uuid
from functools import partial
from importlib.metadata import version
from pathlib import Path
from unittest import mock
Expand Down Expand Up @@ -131,6 +132,14 @@ def test_iteration_calls_run_pending(self, mock_run_pending, runner):
runner.start()
mock_run_pending.call_count = 3

def test_iteration_calls_should_exit(self, runner):
with mock.patch.object(runner, "_manager") as mock_manager:
mock_manager.restart_count = 0
mock_manager.should_exit.side_effect = [False, False, True]
with pytest.raises(SystemExit):
runner.start()
mock_manager.should_exit.call_count = 3

def test_reload_configuration_schedules_job_if_config_refresh_interval_is_set(
self, runner: Runner, configuration: Configuration, config_path: Path
):
Expand Down Expand Up @@ -309,12 +318,3 @@ def test_runner_exits_with_pipeline_error_exitcode_if_restart_count_exceeded(
mock_manager.restart_count = 5
with pytest.raises(SystemExit, match=str(EXITCODES.PIPELINE_ERROR.value)):
runner.start()

def test_runner_does_not_exits_on_negative_restart_count_parameter(self, runner: Runner):
with mock.patch.object(runner, "_manager") as mock_manager:
runner._keep_iterating = partial(mock_keep_iterating, 3)
mock_manager.restart_count = 5
runner._configuration.restart_count = -1
with pytest.raises(SystemExit, match=str(EXITCODES.SUCCESS.value)):
runner.start()
mock_manager.restart_failed_pipeline.call_count = 3

0 comments on commit 6784019

Please sign in to comment.