Skip to content

Commit

Permalink
[FAB-5660] Improve UT coverage of solo consenter
Browse files Browse the repository at this point in the history
Add test cases to cover re-validation path in solo consenter.

Change-Id: Ic0b6e989e4c4ecac28fdffb66d9f870c5a178aba
Signed-off-by: Jay Guo <guojiannan1101@gmail.com>
  • Loading branch information
guoger committed Sep 25, 2017
1 parent 900850f commit 863d784
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions orderer/consensus/solo/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package solo

import (
"fmt"
"testing"
"time"

Expand Down Expand Up @@ -310,3 +311,79 @@ func TestRecoverFromError(t *testing.T) {
t.Fatalf("Expected block to be cut")
}
}

// This test checks that solo consenter re-validates message if config sequence has advanced
func TestRevalidation(t *testing.T) {
batchTimeout, _ := time.ParseDuration("1h")
support := &mockmultichannel.ConsenterSupport{
Blocks: make(chan *cb.Block),
BlockCutterVal: mockblockcutter.NewReceiver(),
SharedConfigVal: &mockconfig.Orderer{BatchTimeoutVal: batchTimeout},
SequenceVal: uint64(1),
}
defer close(support.BlockCutterVal.Block)
bs := newChain(support)
wg := goWithWait(bs.main)
defer bs.Halt()

t.Run("ConfigMsg", func(t *testing.T) {
support.ProcessConfigMsgVal = testMessage

t.Run("Valid", func(t *testing.T) {
assert.Nil(t, bs.Configure(testMessage, 0))

select {
case <-support.Blocks:
case <-time.After(time.Second):
t.Fatalf("Expected one block to be cut but never got it")
}
})

t.Run("Invalid", func(t *testing.T) {
support.ProcessConfigMsgErr = fmt.Errorf("Config message is not valid")
assert.Nil(t, bs.Configure(testMessage, 0))

select {
case <-support.Blocks:
t.Fatalf("Expected no block to be cut")
case <-time.After(100 * time.Millisecond):
}
})

})

t.Run("NormalMsg", func(t *testing.T) {
support.BlockCutterVal.CutNext = true

t.Run("Valid", func(t *testing.T) {
syncQueueMessage(testMessage, bs, support.BlockCutterVal)

select {
case <-support.Blocks:
case <-time.After(time.Second):
t.Fatalf("Expected one block to be cut but never got it")
}
})

t.Run("Invalid", func(t *testing.T) {
support.ProcessNormalMsgErr = fmt.Errorf("Normal message is not valid")
// We are not calling `syncQueueMessage` here because we don't expect
// `Ordered` to be invoked at all in this case, so we don't need to
// synchronize on `support.BlockCutterVal.Block`.
assert.Nil(t, bs.Order(testMessage, 0))

select {
case <-support.Blocks:
t.Fatalf("Expected no block to be cut")
case <-time.After(100 * time.Millisecond):
}
})
})

bs.Halt()
select {
case <-time.After(time.Second):
t.Fatalf("Should have exited")
case <-wg.done:
}
}

0 comments on commit 863d784

Please sign in to comment.