-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Flaky Tests #636
Fix Flaky Tests #636
Conversation
t.Fatalf("Failed to create BeaconNode: %v", err) | ||
} | ||
|
||
go node.Start() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem here is that this goroutine is still running during execution of the next test. This isn't actually testing anything, so I just deleted it.
@@ -250,10 +249,25 @@ func TestLatestAttestation(t *testing.T) { | |||
}(t) | |||
|
|||
rpcService.incomingAttestation <- attestation | |||
rpcService.cancel() | |||
exitRoutine <- true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue here is that the test isn't waiting for the goroutine to finish.
Codecov Report
@@ Coverage Diff @@
## master #636 +/- ##
==========================================
- Coverage 73.14% 72.96% -0.18%
==========================================
Files 52 52
Lines 3459 3459
==========================================
- Hits 2530 2524 -6
- Misses 706 713 +7
+ Partials 223 222 -1
Continue to review full report at Codecov.
|
@@ -262,9 +276,10 @@ func TestLatestAttestation(t *testing.T) { | |||
<-exitRoutine | |||
}(t) | |||
rpcService.incomingAttestation <- attestation | |||
testutil.AssertLogsContain(t, hook, "Sending attestation to RPC clients") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. The assertion needs to come after exitRoutine <- true
.
Another issue is that this test originally combined two tests that should have been separated.
func TestBadExample(t *testing.T) {
go func() {
testSomething(testChan)
<-exitRoutine
}
testChan <- struct{}{}
assertSomething()
go func() {
testSomething(testChan)
<-exitRoutine
}
testChan <- struct{}{}
exitRoutine <- true
assertSomethingElse()
}
The above is a race condition on assertSomething()
. The fix is to separate into two tests:
func TestSomething(t *testing.T) {
go func() {
testSomething(testChan)
<-exitRoutine
}
testChan <- struct{}{}
exitRountine <- true
assertSomething()
}
fun TestSomethingElse(t *testing.T){
go func() {
testSomething(testChan)
<-exitRoutine
}
testChan <- struct{}{}
exitRoutine <- true
assertSomethingElse()
}
In general, each test should assert one case anyways. Long tests that sequentially assert multiple cases are hard to read/debug.
@@ -265,7 +265,22 @@ func TestBlockRequestErrors(t *testing.T) { | |||
} | |||
|
|||
ss.blockRequestBySlot <- invalidmsg | |||
ss.cancel() | |||
exitRoutine <- true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test had the same issue. They need to be separated, and the exitRoutine
check was missing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing - thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
This fixes #377, as well as flaky tests in
sync
andrpc
that were reproduced on buildkite but haven't been reported on GitHub.I didn't find any race conditions for
blockchain
,casper
,types
, so I re-enabled race there as well.