Skip to content

Inconsistent test failures due to a race condition #251

@sarahec

Description

@sarahec

While building for nixpkgs, two tests are failing frequently -- but not consistently -- on aarch64-darwin (MacOS):

test_fritzmonitor.py::test_terminate_thread_on_failed_reconnection[data7-5-5-False] - assert True is False
test_fritzmonitor.py::test_restart_failed_monitor - assert True is False

The second failure appears to be tied to the first one (they only appear together).

It looks like a classic race condition where time.sleep(0.01) may not be long enough fr the socket to disconnect under some conditions.

=========================== short test summary info ============================
FAILED fritzconnection/tests/test_fritzmonitor.py::test_terminate_thread_on_failed_reconnection[data7-5-5-False] - assert True is False
FAILED fritzconnection/tests/test_fritzmonitor.py::test_restart_failed_monitor - assert True is False
================== 2 failed, 400 passed, 10 skipped in 1.96s ===================
error: builder for '/nix/store/kviik1lr4hcw6ns78v8i1lqp87k44zcs-python3.12-fritzconnection-1.15.0.drv' failed with exit code 1;
       last 25 log lines:
       >         started again. Starting the same instance twice does (and should)
       >         not work. See test_start_twice(). But after a failed reconnect (a
       >         lost connection) the same instance without calling stop()
       >         """
       >         socket = MockReconnectFailSocket(
       >             mock_data=["first\n", "", "second\n"], timeouts=16
       >         )  # just some timeouts
       >         fm = FritzMonitor()
       >         fm.start(
       >             sock=socket, reconnect_delay=0.001, reconnect_tries=5
       >         )  # set default explicit for clarity
       >         # give socket some time to lose connection:
       >         time.sleep(0.01)
       > >       assert fm.is_alive is False
       > E       assert True is False
       > E        +  where True = <fritzconnection.core.fritzmonitor.FritzMonitor object at 0x1058e5b50>.is_alive
       >
       > fm         = <fritzconnection.core.fritzmonitor.FritzMonitor object at 0x1058e5b50>
       > socket     = <fritzconnection.tests.test_fritzmonitor.MockReconnectFailSocket object at 0x1058e6bd0>
       >
       > /nix/var/nix/builds/nix-build-python3.12-fritzconnection-1.15.0.drv-0/b/source/fritzconnection/tests/test_fritzmonitor.py:385: AssertionError
       > =========================== short test summary info ============================
       > FAILED fritzconnection/tests/test_fritzmonitor.py::test_terminate_thread_on_failed_reconnection[data7-5-5-False] - assert True is False
       > FAILED fritzconnection/tests/test_fritzmonitor.py::test_restart_failed_monitor - assert True is False
       > ================== 2 failed, 400 passed, 10 skipped in 1.96s ===================
       For full logs, run 'nix log /nix/store/kviik1lr4hcw6ns78v8i1lqp87k44zcs-python3.12-fritzconnection-1.15.0.drv'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions