Skip to content

Commit

Permalink
[FAB-9160] fix data race in TestRecoverFromError
Browse files Browse the repository at this point in the history
Clearing CurBatch after syncQueueMessage resulted in a race. Added a
flag to the mock to skip the append to CurBatch instead of explicitly
clearing it.

Change-Id: Ie599c0d4953ae371904aec5bafd5dc43ff088a5d
Signed-off-by: Matthew Sykes <[email protected]>
  • Loading branch information
sykesm committed Jul 2, 2018
1 parent 7a3001a commit 003566e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 4 additions & 3 deletions orderer/consensus/solo/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,18 +291,19 @@ func TestRecoverFromError(t *testing.T) {
}
defer close(support.BlockCutterVal.Block)
bs := newChain(support)
_ = goWithWait(bs.main)
go bs.main()
defer bs.Halt()

support.BlockCutterVal.SkipAppendCurBatch = true
syncQueueMessage(testMessage, bs, support.BlockCutterVal)
support.BlockCutterVal.CurBatch = nil

select {
case <-support.Blocks:
t.Fatalf("Expected no invocations of Append")
case <-time.After(2 * time.Millisecond):
case <-time.After(100 * time.Millisecond):
}

support.BlockCutterVal.SkipAppendCurBatch = false
support.BlockCutterVal.CutNext = true
syncQueueMessage(testMessage, bs, support.BlockCutterVal)
select {
Expand Down
7 changes: 6 additions & 1 deletion orderer/mocks/common/blockcutter/blockcutter.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ type Receiver struct {
// CutNext causes Ordered returns [][]{append(curBatch, newTx)}, false when set to true
CutNext bool

// SkipAppendCurBatch causes Ordered to skip appending to CurBatch
SkipAppendCurBatch bool

// CurBatch is the currently outstanding messages in the batch
CurBatch []*cb.Envelope

Expand Down Expand Up @@ -79,7 +82,9 @@ func (mbc *Receiver) Ordered(env *cb.Envelope) ([][]*cb.Envelope, bool) {
return res, true
}

mbc.CurBatch = append(mbc.CurBatch, env)
if !mbc.SkipAppendCurBatch {
mbc.CurBatch = append(mbc.CurBatch, env)
}

if mbc.CutNext {
logger.Debugf("Receiver: Returning regular batch")
Expand Down

0 comments on commit 003566e

Please sign in to comment.