Skip to content
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

Merged
merged 9 commits into from
Oct 9, 2018
Merged

Fix Flaky Tests #636

merged 9 commits into from
Oct 9, 2018

Conversation

rawfalafel
Copy link
Contributor

This fixes #377, as well as flaky tests in sync and rpc 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.

t.Fatalf("Failed to create BeaconNode: %v", err)
}

go node.Start()
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link

codecov bot commented Oct 9, 2018

Codecov Report

Merging #636 into master will decrease coverage by 0.17%.
The diff coverage is n/a.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
beacon-chain/node/node.go 48.46% <0%> (-3.07%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cd2073e...3cabce9. Read the comment docs.

@@ -262,9 +276,10 @@ func TestLatestAttestation(t *testing.T) {
<-exitRoutine
}(t)
rpcService.incomingAttestation <- attestation
testutil.AssertLogsContain(t, hook, "Sending attestation to RPC clients")
Copy link
Contributor Author

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
Copy link
Contributor Author

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.

@rauljordan rauljordan changed the title Fix flaky tests Fix Flaky Tests Oct 9, 2018
Copy link
Contributor

@rauljordan rauljordan left a comment

Choose a reason for hiding this comment

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

Amazing - thank you!

Copy link
Member

@terencechain terencechain left a comment

Choose a reason for hiding this comment

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

👍

@rauljordan rauljordan merged commit 3e8a450 into master Oct 9, 2018
@rawfalafel rawfalafel deleted the flakiness branch October 9, 2018 15:59
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.

Tests Fail With Race Detection
3 participants