Skip to content

Commit

Permalink
find and fix error in tests (#4912)
Browse files Browse the repository at this point in the history
Signed-off-by: Fedor Partanskiy <[email protected]>
  • Loading branch information
pfi79 authored Jun 26, 2024
1 parent 3bc7244 commit 4473b56
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 20 deletions.
7 changes: 6 additions & 1 deletion integration/smartbft/mock_orderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,12 @@ func (mo *MockOrderer) deliverBlocks(
iterCh := make(chan struct{})
go func() {
if ledgerIdx > ledgerLastIdx {
time.Sleep(math.MaxInt64)
select {
case <-time.After(math.MaxInt64):
case <-ctx.Done():
close(iterCh)
return
}
}
block = mo.ledgerArray[ledgerIdx]
status = cb.Status_SUCCESS
Expand Down
12 changes: 6 additions & 6 deletions integration/smartbft/smartbft_block_deliverer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,14 @@ var _ = Describe("Smart BFT Block Deliverer", func() {

/* Create a network from the networkConfig */
network = nwo.New(networkConfig, testDir, client, StartPort(), components)
network.Profiles[0].SmartBFT = &nwo.SmartBFT{
LeaderHeartbeatTimeout: 10,
LeaderHeartbeatCount: 10,
}
network.GenerateConfigTree()
network.Bootstrap()

for _, orderer := range network.Orderers {
runner := network.OrdererRunner(orderer)
runner.Command.Env = append(runner.Command.Env, "FABRIC_LOGGING_SPEC=debug")
runner := network.OrdererRunner(orderer,
"FABRIC_LOGGING_SPEC=debug",
"ORDERER_GENERAL_BACKOFF_MAXDELAY=20s",
)
ordererRunners = append(ordererRunners, runner)
proc := ifrit.Invoke(runner)
ordererProcesses = append(ordererProcesses, proc)
Expand Down Expand Up @@ -363,6 +361,8 @@ var _ = Describe("Smart BFT Block Deliverer", func() {
By("Bring up the last orderer")
o4Runner := network.OrdererRunner(network.Orderers[3], "FABRIC_LOGGING_SPEC=debug")
o4Proc = ifrit.Invoke(o4Runner)
ordererProcesses[3] = o4Proc

Eventually(o4Proc.Ready(), network.EventuallyTimeout).Should(BeClosed())

By("Assert block censorship detected")
Expand Down
8 changes: 4 additions & 4 deletions orderer/consensus/smartbft/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ import (
"time"

"github.com/golang/protobuf/proto"
cb "github.com/hyperledger/fabric-protos-go/common"
"github.com/hyperledger/fabric-protos-go/msp"
"github.com/hyperledger/fabric/common/channelconfig"
"github.com/hyperledger/fabric/common/crypto/tlsgen"
"github.com/hyperledger/fabric/internal/configtxlator/update"
smartBFTMocks "github.com/hyperledger/fabric/orderer/consensus/smartbft/mocks"
"github.com/stretchr/testify/mock"

cb "github.com/hyperledger/fabric-protos-go/common"
"github.com/hyperledger/fabric-protos-go/msp"
"github.com/hyperledger/fabric/protoutil"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -361,6 +360,7 @@ func TestAddAndRemoveNodeWithoutStop(t *testing.T) {

// start a network
networkSetupInfo := NewNetworkSetupInfo(t, channelId, dir)
networkSetupInfo.configInfo.leaderHeartbeatTimeout = time.Minute
nodeMap := networkSetupInfo.CreateNodes(4)
networkSetupInfo.StartAllNodes()

Expand Down
20 changes: 11 additions & 9 deletions orderer/consensus/smartbft/util_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ import (
"testing"
"time"

"github.com/hyperledger/fabric-lib-go/common/flogging"

"github.com/golang/protobuf/proto"
"github.com/hyperledger-labs/SmartBFT/pkg/api"
"github.com/hyperledger-labs/SmartBFT/pkg/types"
"github.com/hyperledger-labs/SmartBFT/pkg/wal"
"github.com/hyperledger-labs/SmartBFT/smartbftprotos"
"github.com/hyperledger/fabric-lib-go/bccsp/sw"
"github.com/hyperledger/fabric-lib-go/common/flogging"
"github.com/hyperledger/fabric-lib-go/common/metrics/disabled"
cb "github.com/hyperledger/fabric-protos-go/common"
"github.com/hyperledger/fabric/common/channelconfig"
Expand All @@ -45,15 +44,15 @@ import (

// ConfigInfo stores the block numbers which are configuration blocks
type ConfigInfo struct {
t *testing.T
numsOfConfigBlocks []uint64
lock sync.RWMutex
t *testing.T
numsOfConfigBlocks []uint64
lock sync.RWMutex
leaderHeartbeatTimeout time.Duration
}

func NewConfigInfo(t *testing.T) *ConfigInfo {
return &ConfigInfo{
t: t,
numsOfConfigBlocks: []uint64{},
t: t,
}
}

Expand Down Expand Up @@ -410,7 +409,7 @@ func (ns *NodeState) GetLedgerHeight() int {
}

func (ns *NodeState) WaitLedgerHeightToBe(height int) {
require.Eventually(ns.t, func() bool { return ns.GetLedgerHeight() == height }, 60*time.Second, 100*time.Millisecond)
require.Eventually(ns.t, func() bool { return ns.GetLedgerHeight() == height }, 2*time.Minute, 200*time.Millisecond)
}

func (ns *NodeState) GetLedgerArray() []*cb.Block {
Expand Down Expand Up @@ -450,6 +449,9 @@ func createBFTChainUsingMocks(t *testing.T, node *Node, configInfo *ConfigInfo)
channelId := node.ChannelId

config := createBFTConfiguration(node)
if configInfo.leaderHeartbeatTimeout != 0 {
config.LeaderHeartbeatTimeout = configInfo.leaderHeartbeatTimeout
}

blockPuller := smartBFTMocks.NewBlockPuller(t)
blockPuller.EXPECT().Close().Maybe()
Expand Down Expand Up @@ -552,7 +554,7 @@ func createBFTChainUsingMocks(t *testing.T, node *Node, configInfo *ConfigInfo)
return
}
t.Logf("Node %d requested SendTransaction to node %d", node.NodeId, targetNodeId)
err := node.sendRequest(node.NodeId, targetNodeId, message)
err = node.sendRequest(node.NodeId, targetNodeId, message)
require.NoError(t, err)
}).Maybe()
egressCommMock.EXPECT().SendConsensus(mock.Anything, mock.Anything).Run(
Expand Down

0 comments on commit 4473b56

Please sign in to comment.