Skip to content

Commit

Permalink
Fix Flaky Tests (#636)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yutaro Mori authored and rauljordan committed Oct 9, 2018
1 parent cd2073e commit 3e8a450
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 34 deletions.
1 change: 0 additions & 1 deletion beacon-chain/blockchain/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ go_test(
name = "go_default_test",
srcs = ["service_test.go"],
embed = [":go_default_library"],
race = "off", # TODO(#412): fix issues with tests failing with race on.
deps = [
"//beacon-chain/db:go_default_library",
"//beacon-chain/params:go_default_library",
Expand Down
1 change: 0 additions & 1 deletion beacon-chain/casper/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ go_test(
"validator_test.go",
],
embed = [":go_default_library"],
race = "off", # TODO(#434): fix issues with tests failing with race on.
deps = [
"//beacon-chain/params:go_default_library",
"//proto/beacon/p2p/v1:go_default_library",
Expand Down
21 changes: 0 additions & 21 deletions beacon-chain/node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,6 @@ func TestNodeValidator_Builds(t *testing.T) {
}
}

// Test that beacon chain node can start.
func TestNodeStart(t *testing.T) {
app := cli.NewApp()
set := flag.NewFlagSet("test", 0)
set.String("web3provider", "ws//127.0.0.1:8546", "web3 provider ws or IPC endpoint")
tmp := fmt.Sprintf("%s/datadir", os.TempDir())
set.String("datadir", tmp, "node data directory")
set.Bool("enable-powchain", false, "no powchain service")
set.Bool("demo-config", true, "demo configuration")

context := cli.NewContext(app, set, nil)

node, err := NewBeaconNode(context)
if err != nil {
t.Fatalf("Failed to create BeaconNode: %v", err)
}

go node.Start()
os.RemoveAll(tmp)
}

// Test that beacon chain node can close.
func TestNodeClose(t *testing.T) {
hook := logTest.NewGlobal()
Expand Down
25 changes: 20 additions & 5 deletions beacon-chain/rpc/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,7 @@ func TestLatestAttestationContextClosed(t *testing.T) {
testutil.AssertLogsContain(t, hook, "RPC context closed, exiting goroutine")
}

func TestLatestAttestation(t *testing.T) {
hook := logTest.NewGlobal()
func TestLatestAttestationFaulty(t *testing.T) {
attestationService := &mockAttestationService{}
rpcService := NewRPCService(context.Background(), &Config{
Port: "8777",
Expand All @@ -250,10 +249,25 @@ func TestLatestAttestation(t *testing.T) {
}(t)

rpcService.incomingAttestation <- attestation
rpcService.cancel()
exitRoutine <- true
}

mockStream = internal.NewMockBeaconService_LatestAttestationServer(ctrl)
mockStream.EXPECT().Send(attestation.Proto()).Return(nil)
func TestLatestAttestation(t *testing.T) {
hook := logTest.NewGlobal()
attestationService := &mockAttestationService{}
rpcService := NewRPCService(context.Background(), &Config{
Port: "8777",
SubscriptionBuf: 0,
AttestationService: attestationService,
})
ctrl := gomock.NewController(t)
defer ctrl.Finish()

exitRoutine := make(chan bool)
attestation := &types.Attestation{}
mockStream := internal.NewMockBeaconService_LatestAttestationServer(ctrl)
mockStream.EXPECT().Send(attestation.Proto()).Return(nil)
// Tests a good stream.
go func(tt *testing.T) {
if err := rpcService.LatestAttestation(&empty.Empty{}, mockStream); err != nil {
Expand All @@ -262,9 +276,10 @@ func TestLatestAttestation(t *testing.T) {
<-exitRoutine
}(t)
rpcService.incomingAttestation <- attestation
testutil.AssertLogsContain(t, hook, "Sending attestation to RPC clients")
rpcService.cancel()
exitRoutine <- true

testutil.AssertLogsContain(t, hook, "Sending attestation to RPC clients")
}

func TestValidatorSlotAndResponsibility(t *testing.T) {
Expand Down
1 change: 0 additions & 1 deletion beacon-chain/sync/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ go_test(
name = "go_default_test",
srcs = ["service_test.go"],
embed = [":go_default_library"],
race = "off", # TODO(#377): fix issues with race detection testing.
deps = [
"//beacon-chain/db:go_default_library",
"//beacon-chain/types:go_default_library",
Expand Down
22 changes: 19 additions & 3 deletions beacon-chain/sync/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func TestBlockRequestErrors(t *testing.T) {

go func() {
ss.run()
exitRoutine <- true
<-exitRoutine
}()

malformedRequest := &pb.BeaconBlockHashAnnounce{
Expand All @@ -265,7 +265,22 @@ func TestBlockRequestErrors(t *testing.T) {
}

ss.blockRequestBySlot <- invalidmsg
ss.cancel()
exitRoutine <- true
testutil.AssertLogsContain(t, hook, "Received malformed beacon block request p2p message")
}

func TestBlockRequest(t *testing.T) {
hook := logTest.NewGlobal()

ss := setupService(t)

exitRoutine := make(chan bool)

go func() {
ss.run()
<-exitRoutine
}()

request1 := &pb.BeaconBlockRequestBySlotNumber{
SlotNumber: 20,
Expand All @@ -278,9 +293,10 @@ func TestBlockRequestErrors(t *testing.T) {
}

ss.blockRequestBySlot <- msg1
testutil.AssertLogsDoNotContain(t, hook, "Sending requested block to peer")
hook.Reset()
ss.cancel()
exitRoutine <- true

testutil.AssertLogsDoNotContain(t, hook, "Sending requested block to peer")
}

func TestReceiveAttestation(t *testing.T) {
Expand Down
1 change: 0 additions & 1 deletion beacon-chain/types/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ go_test(
"crystallized_state_test.go",
],
embed = [":go_default_library"],
race = "off", # TODO(#604): fix issues with tests failing with race on.
deps = [
"//beacon-chain/params:go_default_library",
"//proto/beacon/p2p/v1:go_default_library",
Expand Down
1 change: 0 additions & 1 deletion contracts/sharding-manager-contract/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ go_test(
name = "go_default_test",
srcs = ["sharding_manager_test.go"],
embed = [":go_default_library"],
race = "off",
tags = ["manual"],
deps = [
"@com_github_ethereum_go_ethereum//accounts/abi/bind:go_default_library",
Expand Down

0 comments on commit 3e8a450

Please sign in to comment.