Skip to content

Commit

Permalink
feat: add one more testcase for DAQJobHealthcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
furkan-bilgin committed Oct 14, 2024
1 parent dc3eae6 commit c3ad6df
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/tests/test_healthcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,35 @@ def test_handle_checks_should_not_alert_twice_in_a_row(self, mock_send_alert):
self.daq_job_healthcheck.handle_checks()
mock_send_alert.assert_not_called()

@patch("daq.jobs.healthcheck.DAQJobHealthcheck.send_alert")
def test_handle_checks_should_alert_then_not_alert_then_alert_again(
self, mock_send_alert
):
mock_stats = MagicMock()
mock_stats.message_out_stats.last_updated = datetime.now() - timedelta(
minutes=10
)
self.daq_job_healthcheck._current_stats = {DAQJobTest: mock_stats}

# First check should trigger an alert
self.daq_job_healthcheck.handle_checks()
mock_send_alert.assert_called_once_with(self.healthcheck_item)

# Reset mock to check for second call
mock_send_alert.reset_mock()

# Update stats to a recent time, should not trigger an alert
mock_stats.message_out_stats.last_updated = datetime.now()
self.daq_job_healthcheck.handle_checks()
mock_send_alert.assert_not_called()

# Update stats to an old time again, should trigger an alert
mock_stats.message_out_stats.last_updated = datetime.now() - timedelta(
minutes=10
)
self.daq_job_healthcheck.handle_checks()
mock_send_alert.assert_called_once_with(self.healthcheck_item)

def test_parse_interval(self):
self.assertEqual(self.healthcheck_item.parse_interval(), timedelta(minutes=5))

Expand Down

0 comments on commit c3ad6df

Please sign in to comment.