Commit b4954f7b authored by yacovm's avatar yacovm Committed by Yacov Manevich
Browse files

[FAB-12944] Pulling system chain failure should panic



This change set makes a failure pulling the system chain to panic.

Tests have been modified to accomodate:

- TestReplicateChainsFailures in replication_test now panics in all cases
  because it invokes ReplicateChains which invokes PullChannel indirectly.

- TestReplicateIfNeeded in onboarding_test now panics in the last test case
  because all we care about (to test) is the fact that we successfully attempt
  to pull from the orderer, and not whether the blocks actually arive from it,
  which is tested in the cluster tests.

Change-Id: Ied21201e693536935eaa708dc3692b76a49d1c61
Signed-off-by: default avataryacovm <yacovm@il.ibm.com>
parent 2e9fbe46
......@@ -110,7 +110,9 @@ func (r *Replicator) ReplicateChains() {
r.PullChannel(channel)
}
// Last, pull the system chain
r.PullChannel(r.SystemChannel)
if err := r.PullChannel(r.SystemChannel); err != nil {
r.Logger.Panicf("Failed pulling system channel: %v", err)
}
r.LedgerFactory.Close()
}
......
......@@ -87,8 +87,7 @@ func TestIsReplicationNeeded(t *testing.T) {
func TestReplicateChainsFailures(t *testing.T) {
for _, testCase := range []struct {
name string
blocks []*common.Block
expectedError string
isProbeResponseDelayed bool
latestBlockSeqInOrderer uint64
ledgerFactoryError error
appendBlockError error
......@@ -96,18 +95,21 @@ func TestReplicateChainsFailures(t *testing.T) {
mutateBlocks func([]*common.Block)
}{
{
name: "no block received",
expectedError: "failed obtaining the latest block for channel system",
name: "no block received",
expectedPanic: "Failed pulling system channel: " +
"failed obtaining the latest block for channel system",
},
{
name: "latest block seq is less than boot block seq",
expectedError: "latest height found among system channel(system) orderers is 19," +
expectedPanic: "Failed pulling system channel: " +
"latest height found among system channel(system) orderers is 19," +
" but the boot block's sequence is 21",
latestBlockSeqInOrderer: 18,
},
{
name: "hash chain mismatch",
expectedError: "block header mismatch on sequence 11, " +
expectedPanic: "Failed pulling system channel: " +
"block header mismatch on sequence 11, " +
"expected 9cd61b7e9a5ea2d128cc877e5304e7205888175a8032d40b97db7412dca41d9e, got 010203",
latestBlockSeqInOrderer: 21,
mutateBlocks: func(systemChannelBlocks []*common.Block) {
......@@ -136,6 +138,13 @@ func TestReplicateChainsFailures(t *testing.T) {
appendBlockError: errors.New("IO error"),
expectedPanic: "Failed to write block 0: IO error",
},
{
name: "failure pulling the system chain",
latestBlockSeqInOrderer: 21,
expectedPanic: "Failed pulling system channel: " +
"failed obtaining the latest block for channel system",
isProbeResponseDelayed: true,
},
} {
t.Run(testCase.name, func(t *testing.T) {
systemChannelBlocks := createBlockChain(0, 21)
......@@ -156,18 +165,25 @@ func TestReplicateChainsFailures(t *testing.T) {
bp := newBlockPuller(dialer, osn.srv.Address())
bp.FetchTimeout = time.Millisecond * 100
cl := &mocks.ChannelLister{}
cl.On("Channels").Return(nil)
cl.On("Close")
r := cluster.Replicator{
Logger: flogging.MustGetLogger("test"),
BootBlock: systemChannelBlocks[21],
SystemChannel: "system",
LedgerFactory: lf,
Puller: bp,
ChannelLister: cl,
}
if !testCase.isProbeResponseDelayed {
osn.enqueueResponse(testCase.latestBlockSeqInOrderer)
osn.enqueueResponse(testCase.latestBlockSeqInOrderer)
}
osn.addExpectProbeAssert()
osn.enqueueResponse(testCase.latestBlockSeqInOrderer)
osn.addExpectProbeAssert()
osn.enqueueResponse(testCase.latestBlockSeqInOrderer)
osn.addExpectPullAssert(0)
for _, block := range systemChannelBlocks {
osn.blockResponses <- &orderer.DeliverResponse{
......@@ -175,15 +191,7 @@ func TestReplicateChainsFailures(t *testing.T) {
}
}
if testCase.expectedPanic == "" {
err := r.PullChannel("system")
assert.EqualError(t, err, testCase.expectedError)
} else {
assert.PanicsWithValue(t, testCase.expectedPanic, func() {
r.PullChannel("system")
})
}
assert.PanicsWithValue(t, testCase.expectedPanic, r.ReplicateChains)
bp.Close()
dialer.assertAllConnectionsClosed(t)
})
......
......@@ -236,12 +236,15 @@ func TestReplicateIfNeeded(t *testing.T) {
},
},
{
name: "Replication is needed",
name: "Replication is needed, but pulling fails",
panicValue: "Failed pulling system channel: " +
"failed obtaining the latest block for channel system",
shouldConnect: true,
systemLedgerHeight: 10,
bootBlock: bootBlock,
conf: &localconfig.TopLevel{
General: localconfig.General{
SystemChannel: "system",
Cluster: localconfig.Cluster{
ReplicationPullTimeout: time.Millisecond * 100,
DialTimeout: time.Millisecond * 100,
......@@ -257,13 +260,6 @@ func TestReplicateIfNeeded(t *testing.T) {
UseTLS: true,
ServerRootCAs: [][]byte{caCert},
},
zapHooks: []func(entry zapcore.Entry) error{
func(entry zapcore.Entry) error {
hooksActivated = true
assert.Equal(t, entry.Message, "Will now replicate chains")
return nil
},
},
},
} {
t.Run(testCase.name, func(t *testing.T) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment