test: fix race in Tor control reconnect check

bitcoin/bitcoin: PR #36937

1 suggestion

Optional improvements

Link

[suggestion] · The reconnect timing check includes work before the disconnect trigger

expect_disconnect includes pre-trigger work in its 0.5-second check, so a slow test thread could mask a shortened reconnect backoff; this is a coverage improvement, not an observed false pass.

Location: test/functional/feature_torcontrol.py:153 (head).

Details and suggested fix

start is captured before yield. In test_reconnect_backoff, the body sends a reply before calling shutdown(SHUT_WR). In test_overmany_lines, it sends 1000 continuation lines before the 1001st line triggers rejection. The node starts its backoff only after detecting the disconnect. Thus, for example, a 0.6-second scheduling pause before the trigger followed by a regressed 0.1-second backoff could satisfy both the elapsed-time assertion and the PROTOCOLINFO 1 check.

Let each context body record a timestamp immediately before its disconnect-inducing action, and compare last_accept_time against that timestamp. For these callers, that means immediately before shutdown(SHUT_WR) or the final, 1001st send. Keep the asynchronous accept timestamp and command check so reconnecting before the test thread resumes remains supported. The measurement would still include detection latency, but would exclude earlier test-side work.


Coverage details