queue: Fix a race condition in monitoring after queue stops being idle.

The race condition is described in the comment block removed by this
commit. This leaves room for another, remaining race condition
that should be virtually impossible, but nevertheless it seems
worthwhile to have it documented in the code, so we put a new comment
describing it.
As a final note, this is not a new race condition,
it was hypothetically possible with the old code as well.
This commit is contained in:
Mateusz Mandera
2020-09-06 18:26:27 +02:00
committed by Tim Abbott
parent a72e9476ee
commit 2365a53496
3 changed files with 27 additions and 10 deletions

View File

@@ -10,12 +10,8 @@ class AnalyzeQueueStatsTests(TestCase):
self.assertEqual(result['status'], UNKNOWN)
def test_queue_stuck(self) -> None:
"""Last update > 5 minutes ago and there's events in the queue.
"""Last update > 5 minutes ago and there's events in the queue."""
In theory, we could be having bad luck with a race where in
the last (event_handing_time * 50) a burst was added, but it's
unlikely and shouldn't fail 2 in a row for Nagios anyway.
"""
result = analyze_queue_stats('name', {'update_time': time.time() - 301}, 100)
self.assertEqual(result['status'], CRITICAL)
self.assertIn('queue appears to be stuck', result['message'])