Skip to content

Commit c432a19

Browse files
Jason Yellickgaborh-da
Jason Yellick
authored andcommitted
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 <[email protected]>
1 parent 9cd44a1 commit c432a19

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

orderer/solo/consensus.go

+3
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ func (bs *consenter) main() {
8686
for _, batch := range batches {
8787
bs.rl.Append(batch, nil)
8888
}
89+
if len(batches) > 0 {
90+
timer = nil
91+
}
8992
case <-timer:
9093
//clear the timer
9194
timer = nil

orderer/solo/consensus_test.go

+37
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,46 @@ func TestBatchTimer(t *testing.T) {
141141

142142
select {
143143
case <-it.ReadyChan():
144+
it.Next()
144145
case <-time.After(time.Second):
145146
t.Fatalf("Expected a block to be cut because of batch timer expiration but did not")
146147
}
148+
149+
bs.sendChan <- &cb.Envelope{Payload: []byte("Some bytes")}
150+
select {
151+
case <-it.ReadyChan():
152+
case <-time.After(time.Second):
153+
t.Fatalf("Did not create the second batch, indicating that the timer was not appopriately reset")
154+
}
155+
}
156+
157+
func TestBatchTimerHaltOnFilledBatch(t *testing.T) {
158+
filters, cm := getFiltersAndConfig()
159+
batchSize := 2
160+
rl := ramledger.New(10, genesisBlock)
161+
bs := NewConsenter(batchSize, time.Hour, rl, filters, cm)
162+
defer bs.halt()
163+
it, _ := rl.Iterator(ab.SeekInfo_SPECIFIED, 1)
164+
165+
bs.sendChan <- &cb.Envelope{Payload: []byte("Some bytes")}
166+
bs.sendChan <- &cb.Envelope{Payload: []byte("Some bytes")}
167+
168+
select {
169+
case <-it.ReadyChan():
170+
it.Next()
171+
case <-time.After(time.Second):
172+
t.Fatalf("Expected a block to be cut because the batch was filled, but did not")
173+
}
174+
175+
// Change the batch timeout to be near instant
176+
bs.batchTimeout = time.Millisecond
177+
178+
bs.sendChan <- &cb.Envelope{Payload: []byte("Some bytes")}
179+
select {
180+
case <-it.ReadyChan():
181+
case <-time.After(time.Second):
182+
t.Fatalf("Did not create the second batch, indicating that the old timer was still running")
183+
}
147184
}
148185

149186
func TestFilledBatch(t *testing.T) {

0 commit comments

Comments
 (0)