Skip to content

Commit

Permalink
Merge pull request #34 from neptune-ai/rj/flaky-test-fix
Browse files Browse the repository at this point in the history
chore: Flaky test fixed of ErrorsMonitor
  • Loading branch information
kgodlewski authored Sep 3, 2024
2 parents 4f1b4e2 + 2ce4d1f commit 043036b
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions tests/unit/test_errors_monitor.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from threading import Event
from typing import Optional
from unittest.mock import Mock

from neptune_scale.core.components.errors_tracking import (
Expand All @@ -10,18 +12,28 @@ def test_errors_monitor():
# given
callback = Mock()

# Synchronization event
callback_called = Event()

# Modify the callback to set the event when called
def callback_with_event(exception: BaseException, last_called: Optional[float]) -> None:
callback(exception, last_called)
callback_called.set()

# and
errors_queue = ErrorsQueue()
errors_monitor = ErrorsMonitor(errors_queue=errors_queue, on_error_callback=callback)
errors_monitor = ErrorsMonitor(errors_queue=errors_queue, on_error_callback=callback_with_event)
errors_monitor.start()

# when
errors_queue.put(ValueError("error1"))
errors_queue.flush()

# and
errors_monitor.start()
errors_monitor.work()
errors_monitor.wake_up()

# then
assert callback_called.wait(timeout=5), "Callback was not called within the timeout"

# and - cleanup
errors_monitor.interrupt()
errors_monitor.join(timeout=5)

Expand Down

0 comments on commit 043036b

Please sign in to comment.