From 003566ef6dc45c47e60b50e9312f2de27347d516 Mon Sep 17 00:00:00 2001 From: Matthew Sykes Date: Fri, 29 Jun 2018 14:29:05 -0400 Subject: [PATCH] [FAB-9160] fix data race in TestRecoverFromError 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 --- orderer/consensus/solo/consensus_test.go | 7 ++++--- orderer/mocks/common/blockcutter/blockcutter.go | 7 ++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/orderer/consensus/solo/consensus_test.go b/orderer/consensus/solo/consensus_test.go index 6e80538b54f..e827d8e5f45 100644 --- a/orderer/consensus/solo/consensus_test.go +++ b/orderer/consensus/solo/consensus_test.go @@ -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 { diff --git a/orderer/mocks/common/blockcutter/blockcutter.go b/orderer/mocks/common/blockcutter/blockcutter.go index 997ee75f0a4..fc44588eab2 100644 --- a/orderer/mocks/common/blockcutter/blockcutter.go +++ b/orderer/mocks/common/blockcutter/blockcutter.go @@ -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 @@ -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")