Improve mixclient test reliability#3651
Merged
davecgh merged 2 commits intodecred:masterfrom Apr 4, 2026
Merged
Conversation
The cleanup function returned by useTestLogger must disable writes to the backend to prevent client goroutines still running after the test finishes from writing to the old *testing.T logger and panicking.
Tests run on an increased schedule by artifically ticking the epoch. This would occasionally result in a disruption tests hanging due to the two clients involved being ticked at roughly the same time but continuing with a different Unix epoch. There was a roughly 50% chance that when this happened, the test would hang, depending on which of the two clients contained the misbehaving peer. Test reliability has been improved by passing same time.Time value with the intended epoch to the testTickC channel by the test function. Client code also signals to the tests when it is waiting for a test epoch, allowing the test to wait for all clients before proceeding with the current time as the epoch.
davecgh
approved these changes
Apr 2, 2026
| }() | ||
|
|
||
| c.testTick() | ||
| <-c.testWaiting |
Member
There was a problem hiding this comment.
Nothing to hold this PR up over, but one of the things I have noticed over time with the tests (and especially more recently when working on the connection manager bits) is that naked channel waits like this often end up making tests hang when things aren't working properly.
I have found that ensuring that all channel waits in tests select across a timeout channel works well to prevent hangs when things aren't working as intended.
For example, something like:
select {
case <-c.testWaiting:
case <-time.After(time.Second): // or whatever is a reasonable timeout for the expected scenarios
t.Fatal("test synchronization timeout")
}
Member
|
Haven't looked at the changes at all, but I've run the tests 10 times and the instability seems to be gone. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
mixclient: Disable logs to backend after test finish
The cleanup function returned by useTestLogger must disable writes to the
backend to prevent client goroutines still running after the test finishes
from writing to the old *testing.T logger and panicking.
mixclient: Avoid test hangs caused by epoch ticker
Tests run on an increased schedule by artifically ticking the epoch. This
would occasionally result in a disruption tests hanging due to the two clients
involved being ticked at roughly the same time but continuing with a different
Unix epoch. There was a roughly 50% chance that when this happened, the test
would hang, depending on which of the two clients contained the misbehaving
peer.
Test reliability has been improved by passing same time.Time value with the
intended epoch to the testTickC channel by the test function. Client code
also signals to the tests when it is waiting for a test epoch, allowing the
test to wait for all clients before proceeding with the current time as the
epoch.