Skip to content

chore: Flaky test fixed of ErrorsMonitor #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading