flexi_logger icon indicating copy to clipboard operation
flexi_logger copied to clipboard

Fix a race condition in test_multi_threaded_dates

Open sepeth opened this issue 5 months ago • 0 comments

Hi there,

This fixes a race condition in test_multi_threaded_dates.

If a worker thread takes less than 500 ms, this test fails due to missing MUST_BE_PRINTED lines. This is because the main thread sleeps 500 ms before setting a new spec for trace!.

XXXXX [2024-09-02 09:55:33.010986 +00:00] T["test_multi_threaded_dates"] INFO [tests/test_multi_threaded_dates.rs:41] create many log lines with a considerable number of threads, verify the log
XXXXX [2024-09-02 09:55:33.514113 +00:00] T["test_multi_threaded_dates"] INFO [tests/test_utils.rs:81] Task executed in 503 ms.
test test_multi_threaded_dates ... FAILED

failures:

---- test_multi_threaded_dates stdout ----
thread 'test_multi_threaded_dates' panicked at tests/test_multi_threaded_dates.rs:139:5:
assertion `left == right` failed
  left: 100003
 right: 100008

There is a race condition that can potentially happen but it is a lot less likely: if all of the worker threads finishes before the main thread configures the trace!. This is a lot less likely because the condvar will notify the main thread before the workers start doing IO loop, and main thread no longer sleeps once all worker threads initialized.

sepeth avatar Sep 02 '24 10:09 sepeth