Skip to content

Commit

Permalink
Add sync.WaitGroup to the payloads buffer test
Browse files Browse the repository at this point in the history
In order to prevent payloads buffer tests fail intermitently
added syncronization to make sure assertion won't happen before
message appears in the channel.

Change-Id: I141492f87c58cbcecb82b8aa21feafce3da83785
Signed-off-by: Artem Barger <[email protected]>
  • Loading branch information
C0rWin committed Dec 12, 2016
1 parent 37a662f commit 11f3d0c
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion gossip/state/payloads_buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,13 @@ func TestPayloadsBufferImpl_ConcurrentPush(t *testing.T) {
var errors []error

ready := int32(0)
readyWG := sync.WaitGroup{}
readyWG.Add(1)
go func() {

// Wait for next expected block to arrive
<-buffer.Ready()
atomic.AddInt32(&ready, 1)
readyWG.Done()
}()

for i := 0; i < concurrency; i++ {
Expand All @@ -171,6 +173,7 @@ func TestPayloadsBufferImpl_ConcurrentPush(t *testing.T) {
}
}

readyWG.Wait()
assert.Equal(t, int32(1), atomic.LoadInt32(&ready))
assert.Equal(t, 1, success)
// Buffer size has to be only one
Expand Down

0 comments on commit 11f3d0c

Please sign in to comment.