Skip to content

Commit

Permalink
silence_test: better unit test to detect deadlocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Corentin Chary committed Sep 27, 2017
1 parent b00a48c commit 37b31be
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion silence/silence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,22 @@ func TestSilencesSetSilence(t *testing.T) {
s.gossip = &mockGossip{
broadcast: func(d mesh.GossipData) {
data, ok := d.(*gossipData)

// Double check that we can take a lock on s.mtx here.
s.mtx.Lock()
defer s.mtx.Unlock()

require.True(t, ok, "gossip data of unknown type")
require.Equal(t, want, data, "unexpected gossip broadcast data")
require.Equal(t, want.data, data.data, "unexpected gossip broadcast data")
close(done)
},
}

// setSilence() is always called with s.mtx locked()
s.mtx.Lock()
require.NoError(t, s.setSilence(sil))
s.mtx.Unlock()

require.Equal(t, want.data, s.st.data, "Unexpected silence state")

// GossipBroadcast is called in a goroutine.
Expand Down

0 comments on commit 37b31be

Please sign in to comment.