From c432a19811c409c66d5c4b9ca16b2fc7967db816 Mon Sep 17 00:00:00 2001 From: Jason Yellick Date: Thu, 24 Nov 2016 02:19:13 -0500 Subject: [PATCH] Fix solo batch timer bug and add additional tests There was a bug fix by https://gerrit.hyperledger.org/r/#/c/2741/ This changeset includes a test for the bug fixed in 2741, as well as another bug fix where the timer was no longer appropriately stopped after batch creation and an accompanying test case. Change-Id: I87e2a034caf817e3a3bd701780db4ebf50dd2b25 Signed-off-by: Jason Yellick --- orderer/solo/consensus.go | 3 +++ orderer/solo/consensus_test.go | 37 ++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/orderer/solo/consensus.go b/orderer/solo/consensus.go index a1c4bac2bd0..81a31aa5df3 100644 --- a/orderer/solo/consensus.go +++ b/orderer/solo/consensus.go @@ -86,6 +86,9 @@ func (bs *consenter) main() { for _, batch := range batches { bs.rl.Append(batch, nil) } + if len(batches) > 0 { + timer = nil + } case <-timer: //clear the timer timer = nil diff --git a/orderer/solo/consensus_test.go b/orderer/solo/consensus_test.go index fddb32419b1..262943ecae2 100644 --- a/orderer/solo/consensus_test.go +++ b/orderer/solo/consensus_test.go @@ -141,9 +141,46 @@ func TestBatchTimer(t *testing.T) { select { case <-it.ReadyChan(): + it.Next() case <-time.After(time.Second): t.Fatalf("Expected a block to be cut because of batch timer expiration but did not") } + + bs.sendChan <- &cb.Envelope{Payload: []byte("Some bytes")} + select { + case <-it.ReadyChan(): + case <-time.After(time.Second): + t.Fatalf("Did not create the second batch, indicating that the timer was not appopriately reset") + } +} + +func TestBatchTimerHaltOnFilledBatch(t *testing.T) { + filters, cm := getFiltersAndConfig() + batchSize := 2 + rl := ramledger.New(10, genesisBlock) + bs := NewConsenter(batchSize, time.Hour, rl, filters, cm) + defer bs.halt() + it, _ := rl.Iterator(ab.SeekInfo_SPECIFIED, 1) + + bs.sendChan <- &cb.Envelope{Payload: []byte("Some bytes")} + bs.sendChan <- &cb.Envelope{Payload: []byte("Some bytes")} + + select { + case <-it.ReadyChan(): + it.Next() + case <-time.After(time.Second): + t.Fatalf("Expected a block to be cut because the batch was filled, but did not") + } + + // Change the batch timeout to be near instant + bs.batchTimeout = time.Millisecond + + bs.sendChan <- &cb.Envelope{Payload: []byte("Some bytes")} + select { + case <-it.ReadyChan(): + case <-time.After(time.Second): + t.Fatalf("Did not create the second batch, indicating that the old timer was still running") + } } func TestFilledBatch(t *testing.T) {