Skip to content

test: remove flaky cross-file timestamp ordering assertion in multiprocess rotation test #1334

Done

Description

@myakove

Problem

TestHelpers.test_get_logger_with_params_multiprocess_rotation_concurrency in webhook_server/tests/test_helpers.py fails intermittently under parallel CI runs (observed in PR #1333, check run 142150288731):

FAILED webhook_server/tests/test_helpers.py::TestHelpers::test_get_logger_with_params_multiprocess_rotation_concurrency
webhook_server/tests/test_helpers.py:729: AssertionError
assert datetime.datetime(2026, 11, 30, 20, 15, 43, 495486, tzinfo=datetime.timezone.utc) <= datetime.datetime(2026, 11, 30, 20, 15, 43, 492674, tzinfo=datetime.timezone.utc)

Root cause

In webhook_server/tests/test_helpers.py:711-730, the test collects (min(timestamps), max(timestamps)) per rotated log file (file_ts_bounds) and asserts strict ordering across consecutive files:

for earlier, later in zip(file_ts_bounds, file_ts_bounds[1:], strict=False):
    assert earlier[0] <= later[0]
    assert earlier[1] <= later[1]

Python's logging module captures LogRecord.created before MultiProcessRotatingFileHandler acquires its inter-process file lock and performs writes or rollovers. With 4 forked workers logging concurrently, one worker can construct a record, wait on the file lock while another worker constructs a newer record and rotates the file, and then flush its slightly older timestamp (here 2.8 ms older) into the newly rotated file.

Cross-file millisecond/microsecond timestamp ordering is not guaranteed across OS-scheduled processes, and the check is redundant because the same loop already verifies deterministic rotation order via per-worker sequence numbers (assert seq > last_msg_by_worker.get(w_id, -1)).

Proposed fix

Update test_get_logger_with_params_multiprocess_rotation_concurrency in webhook_server/tests/test_helpers.py:

  • Remove timestamps, file_ts_bounds, and the cross-file earlier[0] <= later[0] / earlier[1] <= later[1] assertions.
  • Keep non-empty file checks (assert lines), line format parsing (line_pattern), ISO-8601 timestamp parsing (datetime.fromisoformat(ts_str)), per-worker monotonic sequence checks across rotated files, backup size checks, and final marker checks.

Done

  • Remove cross-file file_ts_bounds timestamp assertions in webhook_server/tests/test_helpers.py
  • Verify uvx prek run --all-files and uvx tox pass
  • Run test_get_logger_with_params_multiprocess_rotation_concurrency repeatedly to confirm stability

Assisted-by: PI (gemini-4-neon)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions