Skip to content

Commit

Permalink
[FAB-5503] Reintroduce disabled test
Browse files Browse the repository at this point in the history
This integration test that checks that leader election yields and causes
the deliver service to shutdown at yield, and for another leader get elected
was brittle and was disabled.

I ran 200 interations of this version and both z and x86 jobs pass now.

Change-Id: Iac1f0b46661058096274317a21b3f0f02a3e5a8a
Signed-off-by: yacovm <yacovm@il.ibm.com>
  • Loading branch information
yacovm committed Nov 27, 2017
1 parent 0754678 commit 37d0755
Showing 1 changed file with 25 additions and 29 deletions.
54 changes: 25 additions & 29 deletions gossip/service/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,17 @@ SPDX-License-Identifier: Apache-2.0
package service

import (
"fmt"
"sync"
"testing"
"time"

"github.com/hyperledger/fabric/protos/ledger/rwset"

"github.com/hyperledger/fabric/core/deliverservice"
"github.com/hyperledger/fabric/core/deliverservice/blocksprovider"
"github.com/hyperledger/fabric/core/ledger"
"github.com/hyperledger/fabric/core/transientstore"
"github.com/hyperledger/fabric/gossip/api"
"github.com/hyperledger/fabric/gossip/election"
"github.com/hyperledger/fabric/gossip/state"
"github.com/hyperledger/fabric/gossip/util"
"github.com/hyperledger/fabric/protos/ledger/rwset"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
)
Expand All @@ -45,6 +42,8 @@ func (*transientStoreMock) PurgeByTxids(txids []string) error {
}

type embeddingDeliveryService struct {
startOnce sync.Once
stopOnce sync.Once
deliverclient.DeliverService
startSignal sync.WaitGroup
stopSignal sync.WaitGroup
Expand All @@ -68,12 +67,16 @@ func (eds *embeddingDeliveryService) waitForDeliveryServiceTermination() {
}

func (eds *embeddingDeliveryService) StartDeliverForChannel(chainID string, ledgerInfo blocksprovider.LedgerInfo, finalizer func()) error {
eds.startSignal.Done()
eds.startOnce.Do(func() {
eds.startSignal.Done()
})
return eds.DeliverService.StartDeliverForChannel(chainID, ledgerInfo, finalizer)
}

func (eds *embeddingDeliveryService) StopDeliverForChannel(chainID string) error {
eds.stopSignal.Done()
eds.stopOnce.Do(func() {
eds.stopSignal.Done()
})
return eds.DeliverService.StopDeliverForChannel(chainID)
}

Expand All @@ -91,11 +94,12 @@ func (edsf *embeddingDeliveryServiceFactory) Service(g GossipService, endpoints
}

func TestLeaderYield(t *testing.T) {
t.Skip()
// Scenario: Spawn 2 peers and wait for the first one to be the leader
// There isn't any orderer present so the leader peer won't be able to
// connect to the orderer, and should relinquish its leadership after a while.
// Make sure the other peer declares itself as the leader soon after.
takeOverMaxTimeout := time.Minute
viper.Set("peer.gossip.election.leaderAliveThreshold", time.Second*5)
viper.Set("peer.deliveryclient.reconnectTotalTimeThreshold", time.Second*5)
viper.Set("peer.gossip.useLeaderElection", true)
viper.Set("peer.gossip.orgLeader", false)
Expand All @@ -109,19 +113,10 @@ func TestLeaderYield(t *testing.T) {
addPeersToChannel(t, n, portPrefix, channelName, gossips, peerIndexes)
// Prime the membership view of the peers
waitForFullMembership(t, gossips, n, time.Second*30, time.Second*2)
mcs := &naiveCryptoService{}
// Helper function that creates a gossipService instance
newGossipService := func(i int) *gossipServiceImpl {
peerIdentity := api.PeerIdentityType(fmt.Sprintf("localhost:%d", portPrefix+i))
gs := &gossipServiceImpl{
mcs: mcs,
gossipSvc: gossips[i],
chains: make(map[string]state.GossipStateProvider),
leaderElection: make(map[string]election.LeaderElectionService),
deliveryFactory: &embeddingDeliveryServiceFactory{&deliveryFactoryImpl{}},
peerIdentity: peerIdentity,
secAdv: &secAdvMock{},
}
gs := gossips[i].(*gossipServiceImpl)
gs.deliveryFactory = &embeddingDeliveryServiceFactory{&deliveryFactoryImpl{}}
gossipServiceInstance = gs
gs.InitializeChannel(channelName, []string{"localhost:7050"}, Support{
Committer: &mockLedgerInfo{1},
Expand All @@ -141,8 +136,6 @@ func TestLeaderYield(t *testing.T) {
defer p1.lock.RUnlock()

if p0.leaderElection[channelName].IsLeader() {
// Ensure p1 isn't a leader at the same time
assert.False(t, p1.leaderElection[channelName].IsLeader())
return 0
}
if p1.leaderElection[channelName].IsLeader() {
Expand All @@ -152,7 +145,6 @@ func TestLeaderYield(t *testing.T) {
}

ds0 := p0.deliveryService[channelName].(*embeddingDeliveryService)
ds1 := p1.deliveryService[channelName].(*embeddingDeliveryService)

// Wait for p0 to connect to the ordering service
ds0.waitForDeliveryServiceActivation()
Expand All @@ -162,13 +154,17 @@ func TestLeaderYield(t *testing.T) {
// Wait for p0 to lose its leadership
ds0.waitForDeliveryServiceTermination()
t.Log("p0 stopped its delivery service")
// Ensure there is no leader
assert.Equal(t, -1, getLeader())
// Wait for p1 to take over
ds1.waitForDeliveryServiceActivation()
t.Log("p1 started its delivery service")
// Ensure it's a leader now
assert.Equal(t, 1, getLeader())
// Ensure p0 is not a leader
assert.NotEqual(t, 0, getLeader())
// Wait for p1 to take over. It should take over before time reaches timeLimit
timeLimit := time.Now().Add(takeOverMaxTimeout)
for getLeader() != 1 && time.Now().Before(timeLimit) {
time.Sleep(time.Second)
}
if time.Now().After(timeLimit) {
util.PrintStackTrace()
t.Fatalf("p1 hasn't taken over leadership within %v: %d", takeOverMaxTimeout, getLeader())
}
p0.chains[channelName].Stop()
p1.chains[channelName].Stop()
p0.deliveryService[channelName].Stop()
Expand Down

0 comments on commit 37d0755

Please sign in to comment.