Repository navigation
test: fix race in Tor control reconnect check - #36937
ANAMASGARD wants to merge 1 commit into
Conversation
Signed-off-by: Gaurav Chaudhary <[email protected]>
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
|
cACK |
|
tACK ba7734b Reproduced #36934. On master, Also checked the new assertion still fails when the backoff is genuinely missing. Set Clearly, almost all of the 0.5s threshold has to come from the node's actual wait. Ran |
| from contextlib import contextmanager | ||
| import socket | ||
| import threading | ||
| from time import monotonic |
There was a problem hiding this comment.
nit: this is the only from time import under test/functional. The other files use import time with time.monotonic()
There was a problem hiding this comment.
Agree that this is a bit nicer but not a blocker
| from contextlib import contextmanager | ||
| import socket | ||
| import threading | ||
| from time import monotonic |
There was a problem hiding this comment.
Agree that this is a bit nicer but not a blocker
| # Expect to receive a PROTOCOLINFO 1 on reconnect, bumping the received | ||
| # commands length. |
There was a problem hiding this comment.
There is no need to remove this comment since the line it refers to is unchanged.
| # The reconnect may already have happened while the test was sending data. | ||
| self.wait_until(lambda: len(mock_tor.received_commands) == initial_len + 1) | ||
| assert_equal(mock_tor.received_commands[initial_len], "PROTOCOLINFO 1") | ||
| # Allow a half-second margin on the initial one-second backoff. |
There was a problem hiding this comment.
I think this comment could be a bit clearer:
| # Allow a half-second margin on the initial one-second backoff. | |
| # No reconnect before the initial reconnect timeout of 1s has passed. | |
| # Measured from before the disconnect was triggered, so a slow test | |
| # can only increase the elapsed time. |
| self.wait_until(lambda: len(mock_tor.received_commands) == initial_len + 1) | ||
| assert_equal(mock_tor.received_commands[initial_len], "PROTOCOLINFO 1") | ||
| # Allow a half-second margin on the initial one-second backoff. | ||
| assert_greater_than_or_equal(mock_tor.last_accept_time - start, 0.5) |
There was a problem hiding this comment.
nit: I would have chosen 0.9s here
| ensure_for(duration=0.5, f=lambda: len(mock_tor.received_commands) == initial_len) | ||
| # Expect to receive a PROTOCOLINFO 1 on reconnect, bumping the received | ||
| # commands length. | ||
| # The reconnect may already have happened while the test was sending data. |
There was a problem hiding this comment.
This comment seems to explain why the test was changed from the old version. But reading it after the change has been made is confusing. I would suggest to remove it.
winterrdog
left a comment
There was a problem hiding this comment.
ACK ba7734b. code reviewed and tested
tested with the reproducer patch (with a 4s sleep): the merge base failed at ensure_for() as expected, while PR HEAD passed and correctly verified the reconnect behaviour and that at least 500ms had elapsed before the mock Tor server accepted the new connection
all the above was tested with g++-12.5.0 on NetBSD 11.0, targeting x86_64
once the outstanding suggestions are accurately addressed, i believe this will be ok to merge because the patchset's core approach already asserts both the reconnection behaviour and the elapsed-time threshold correctly

feature_torcontrol.pycan fail if the node reconnects before the test thread starts checking the backoff. This caused an intermittent CI failure on NetBSD even though the node observed the expected delay.Record when the mock Tor server accepts the new connection and compare that timestamp with the time just before triggering the disconnect. This preserves both checks: at least half a second must have elapsed, and the node must send
PROTOCOLINFO 1on reconnect.On Linux, the 1.5-second delay from the issue reproduced the original failure. The updated test passed both with and without that delay.
Fixes #36934.