Skip to content

Commit

Permalink
Fix solo batch timer bug and add additional tests
Browse files Browse the repository at this point in the history
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 <jyellick@us.ibm.com>
  • Loading branch information
Jason Yellick authored and gaborh-da committed Nov 24, 2016
1 parent 9cd44a1 commit c432a19
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
3 changes: 3 additions & 0 deletions orderer/solo/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 37 additions & 0 deletions orderer/solo/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit c432a19

Please sign in to comment.