Skip to content

Improve mixclient test reliability#3651

Merged
davecgh merged 2 commits intodecred:masterfrom
jrick:mixclient_tests
Apr 4, 2026
Merged

Improve mixclient test reliability#3651
davecgh merged 2 commits intodecred:masterfrom
jrick:mixclient_tests

Conversation

@jrick
Copy link
Copy Markdown
Member

@jrick jrick commented Apr 1, 2026

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.

jrick added 2 commits April 1, 2026 13:39
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.
@jrick jrick force-pushed the mixclient_tests branch from 332b52c to 5aedf72 Compare April 1, 2026 13:39
@davecgh davecgh added this to the 2.2.0 milestone Apr 2, 2026
}()

c.testTick()
<-c.testWaiting
Copy link
Copy Markdown
Member

@davecgh davecgh Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")
}

@jholdstock
Copy link
Copy Markdown
Member

Haven't looked at the changes at all, but I've run the tests 10 times and the instability seems to be gone.

@davecgh davecgh merged commit bdfe3e7 into decred:master Apr 4, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants