Skip to content

Commit

Permalink
Merge "Use network.EventuallyTimeout for network polling"
Browse files Browse the repository at this point in the history
  • Loading branch information
sykesm authored and Gerrit Code Review committed Oct 25, 2019
2 parents 12383a2 + 2409de0 commit de8e681
Show file tree
Hide file tree
Showing 16 changed files with 96 additions and 104 deletions.
2 changes: 1 addition & 1 deletion integration/discovery/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ var _ = Describe("DiscoveryService", func() {

networkRunner := network.NetworkGroupRunner()
process = ifrit.Invoke(networkRunner)
Eventually(process.Ready()).Should(BeClosed())
Eventually(process.Ready(), network.EventuallyTimeout).Should(BeClosed())

orderer = network.Orderer("orderer")
network.CreateAndJoinChannel(orderer, "testchannel")
Expand Down
5 changes: 2 additions & 3 deletions integration/e2e/acl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"os"
"path/filepath"
"syscall"
"time"

docker "github.com/fsouza/go-dockerclient"
"github.com/golang/protobuf/proto"
Expand Down Expand Up @@ -208,12 +207,12 @@ var _ = Describe("EndToEndACL", func() {
By("evaluating " + policyName + " for a permitted subject")
sess, err := network.PeerAdminSession(org1Peer0, chaincodeQuery)
Expect(err).NotTo(HaveOccurred())
Eventually(sess, 30*time.Second).Should(gexec.Exit(0))
Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit(0))

By("evaluating " + policyName + " for a forbidden subject")
sess, err = network.PeerAdminSession(org2Peer0, chaincodeQuery)
Expect(err).NotTo(HaveOccurred())
Eventually(sess, 30*time.Second).Should(gexec.Exit())
Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit())
Expect(sess.Err).To(gbytes.Say(fmt.Sprintf(`access denied for \[%s\]\[%s\](.*)signature set did not satisfy policy`, operation, "testchannel")))
}

Expand Down
16 changes: 8 additions & 8 deletions integration/e2e/e2e_signal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,28 +67,28 @@ var _ = Describe("SignalHandling", func() {
It("handles signals", func() {
By("verifying SIGUSR1 to the peer dumps go routines")
peerProcess.Signal(syscall.SIGUSR1)
Eventually(peerRunner.Err()).Should(gbytes.Say("Received signal: "))
Eventually(peerRunner.Err()).Should(gbytes.Say(`Go routines report`))
Eventually(peerRunner.Err(), network.EventuallyTimeout).Should(gbytes.Say("Received signal: "))
Eventually(peerRunner.Err(), network.EventuallyTimeout).Should(gbytes.Say(`Go routines report`))

By("verifying SIGUSR1 to the orderer dumps go routines")
ordererProcess.Signal(syscall.SIGUSR1)
Eventually(ordererRunner.Err()).Should(gbytes.Say("Received signal: "))
Eventually(ordererRunner.Err()).Should(gbytes.Say(`Go routines report`))
Eventually(ordererRunner.Err(), network.EventuallyTimeout).Should(gbytes.Say("Received signal: "))
Eventually(ordererRunner.Err(), network.EventuallyTimeout).Should(gbytes.Say(`Go routines report`))

By("verifying SIGUSR1 does not terminate processes")
Consistently(peerProcess.Wait()).ShouldNot(Receive())
Consistently(ordererProcess.Wait()).ShouldNot(Receive())

By("verifying SIGTERM to the peer stops the process")
peerProcess.Signal(syscall.SIGTERM)
Eventually(peerRunner.Err()).Should(gbytes.Say("Received signal: "))
Eventually(peerProcess.Wait()).Should(Receive())
Eventually(peerRunner.Err(), network.EventuallyTimeout).Should(gbytes.Say("Received signal: "))
Eventually(peerProcess.Wait(), network.EventuallyTimeout).Should(Receive())
peerProcess = nil

By("verifying SIGTERM to the orderer stops the process")
ordererProcess.Signal(syscall.SIGTERM)
Eventually(ordererRunner.Err()).Should(gbytes.Say("Received signal: "))
Eventually(ordererProcess.Wait()).Should(Receive())
Eventually(ordererRunner.Err(), network.EventuallyTimeout).Should(gbytes.Say("Received signal: "))
Eventually(ordererProcess.Wait(), network.EventuallyTimeout).Should(Receive())
ordererProcess = nil
})
})
4 changes: 2 additions & 2 deletions integration/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ func RunRespondWith(n *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer, channe
WaitForEvent: true,
})
Expect(err).NotTo(HaveOccurred())
Eventually(sess, time.Minute).Should(gexec.Exit(0))
Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0))
Expect(sess.Err).To(gbytes.Say("Chaincode invoke successful. result: status:300"))

By("responding with a 400")
Expand All @@ -338,7 +338,7 @@ func RunRespondWith(n *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer, channe
WaitForEvent: true,
})
Expect(err).NotTo(HaveOccurred())
Eventually(sess, time.Minute).Should(gexec.Exit(1))
Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(1))
Expect(sess.Err).To(gbytes.Say(`Error: endorsement failure during invoke.`))
}

Expand Down
2 changes: 1 addition & 1 deletion integration/e2e/health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ var _ = Describe("Health", func() {

peerRunner := network.PeerRunner(peer)
process = ginkgomon.Invoke(peerRunner)
Eventually(process.Ready()).Should(BeClosed())
Eventually(process.Ready(), network.EventuallyTimeout).Should(BeClosed())

authClient, _ = PeerOperationalClients(network, peer)
healthURL = fmt.Sprintf("https://127.0.0.1:%d/healthz", network.PeerPort(peer, nwo.OperationsPort))
Expand Down
7 changes: 3 additions & 4 deletions integration/gossip/gossip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"io/ioutil"
"os"
"syscall"
"time"

docker "github.com/fsouza/go-dockerclient"
"github.com/hyperledger/fabric/integration/nwo"
Expand Down Expand Up @@ -114,7 +113,7 @@ var _ = Describe("Gossip Test", func() {
for _, peer := range []*nwo.Peer{peer0Org1, peer1Org1, peer0Org2, peer1Org2} {
Eventually(func() int {
return nwo.GetLedgerHeight(network, peer, channelName)
}).Should(BeNumerically(">=", 2))
}, network.EventuallyTimeout).Should(BeNumerically(">=", 2))
}

By("stop peers except peer0Org1 to make sure they cannot get blocks from orderer")
Expand Down Expand Up @@ -159,7 +158,7 @@ var _ = Describe("Gossip Test", func() {
Eventually(proc.Wait(), network.EventuallyTimeout).Should(Receive())

expectedMsg := "Stopped being a leader"
Eventually(peerRunners[id].Err(), time.Minute).Should(gbytes.Say(expectedMsg))
Eventually(peerRunners[id].Err(), network.EventuallyTimeout).Should(gbytes.Say(expectedMsg))

delete(peerProcesses, id)

Expand Down Expand Up @@ -215,6 +214,6 @@ func assertPeersLedgerHeight(n *nwo.Network, orderer *nwo.Orderer, peerList []*n
for _, peer := range peerList {
Eventually(func() int {
return nwo.GetLedgerHeight(n, peer, channelID)
}, time.Second*10).Should(Equal(expectedVal))
}, n.EventuallyTimeout).Should(Equal(expectedVal))
}
}
2 changes: 1 addition & 1 deletion integration/ledger/reset_rollback_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ func (nh *networkHelper) waitUntilEndorserEnabled(peer *nwo.Peer) {
Expect(err).NotTo(HaveOccurred())
Eventually(sess, nh.EventuallyTimeout).Should(gexec.Exit())
return sess.Buffer()
}, "60s", "2s").Should(gbytes.Say("Blockchain info"))
}, nh.EventuallyTimeout).Should(gbytes.Say("Blockchain info"))
}

type testHelper struct {
Expand Down
4 changes: 1 addition & 3 deletions integration/nwo/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,7 @@ func CheckCommitReadinessUntilReady(n *Network, channel string, chaincode Chainc
for _, org := range checkOrgs {
keys[org.MSPID] = BeTrue()
}
Eventually(checkCommitReadiness(n, p, channel, chaincode), n.EventuallyTimeout).Should(
MatchKeys(IgnoreExtras, keys),
)
Eventually(checkCommitReadiness(n, p, channel, chaincode), n.EventuallyTimeout).Should(MatchKeys(IgnoreExtras, keys))
}
}

Expand Down
2 changes: 1 addition & 1 deletion integration/nwo/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func DiscoverPeers(n *Network, p *Peer, user, channelName string) func() []Disco
}
sess, err := n.Discover(peers)
Expect(err).NotTo(HaveOccurred())
Eventually(sess).Should(gexec.Exit(0))
Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0))

var discovered []DiscoveredPeer
err = json.Unmarshal(sess.Out.Contents(), &discovered)
Expand Down
4 changes: 2 additions & 2 deletions integration/pluggable/pluggable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ var _ = Describe("EndToEnd", func() {

networkRunner := network.NetworkGroupRunner()
process = ifrit.Invoke(networkRunner)
Eventually(process.Ready()).Should(BeClosed())
Eventually(process.Ready(), network.EventuallyTimeout).Should(BeClosed())

chaincode = nwo.Chaincode{
Name: "mycc",
Expand All @@ -102,7 +102,7 @@ var _ = Describe("EndToEnd", func() {
AfterEach(func() {
// stop the network
process.Signal(syscall.SIGTERM)
Eventually(process.Wait()).Should(Receive())
Eventually(process.Wait(), network.EventuallyTimeout).Should(Receive())

// cleanup the network artifacts
network.Cleanup()
Expand Down
6 changes: 3 additions & 3 deletions integration/pvtdata/pvtdata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ func initThreeOrgsSetup() (string, *nwo.Network, ifrit.Process, *nwo.Orderer, []

networkRunner := n.NetworkGroupRunner()
process := ifrit.Invoke(networkRunner)
Eventually(process.Ready()).Should(BeClosed())
Eventually(process.Ready(), n.EventuallyTimeout).Should(BeClosed())

orderer := n.Orderer("orderer")
n.CreateAndJoinChannel(orderer, "testchannel")
Expand Down Expand Up @@ -891,12 +891,12 @@ type deliverEvent struct {
// getEventFromDeliverService send a request to DeliverWithPrivateData grpc service
// and receive the response
func getEventFromDeliverService(network *nwo.Network, peer *nwo.Peer, channelID string, signingIdentity msp.SigningIdentity, blockNum uint64) *deliverEvent {
ctx, cancelFunc1 := context.WithTimeout(context.Background(), 30*time.Second)
ctx, cancelFunc1 := context.WithTimeout(context.Background(), network.EventuallyTimeout)
defer cancelFunc1()
eventCh, conn := registerForDeliverEvent(ctx, network, peer, channelID, signingIdentity, blockNum)
defer conn.Close()
event := &deliverEvent{}
Eventually(eventCh, 30*time.Second).Should(Receive(event))
Eventually(eventCh, network.EventuallyTimeout).Should(Receive(event))
Expect(event.Err).NotTo(HaveOccurred())
return event
}
Expand Down
46 changes: 22 additions & 24 deletions integration/raft/cft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ var _ = Describe("EndToEnd Crash Fault Tolerance", func() {

o1Proc = ifrit.Invoke(o1Runner)
ordererProc = ifrit.Invoke(ordererGroup)
Eventually(o1Proc.Ready()).Should(BeClosed())
Eventually(ordererProc.Ready()).Should(BeClosed())
Eventually(o1Proc.Ready(), network.EventuallyTimeout).Should(BeClosed())
Eventually(ordererProc.Ready(), network.EventuallyTimeout).Should(BeClosed())

findLeader([]*ginkgomon.Runner{o1Runner})

Expand Down Expand Up @@ -126,7 +126,7 @@ var _ = Describe("EndToEnd Crash Fault Tolerance", func() {
By("restarting orderer1")
o1Runner = network.OrdererRunner(o1)
o1Proc = ifrit.Invoke(o1Runner)
Eventually(o1Proc.Ready()).Should(BeClosed())
Eventually(o1Proc.Ready(), network.EventuallyTimeout).Should(BeClosed())
findLeader([]*ginkgomon.Runner{o1Runner})

By("broadcasting envelope to restarted orderer")
Expand Down Expand Up @@ -164,7 +164,7 @@ var _ = Describe("EndToEnd Crash Fault Tolerance", func() {

By("Starting 2/3 of cluster")
ordererProc = ifrit.Invoke(ordererGroup)
Eventually(ordererProc.Ready()).Should(BeClosed())
Eventually(ordererProc.Ready(), network.EventuallyTimeout).Should(BeClosed())

By("Creating testchannel")
channelID := "testchannel"
Expand Down Expand Up @@ -202,7 +202,7 @@ var _ = Describe("EndToEnd Crash Fault Tolerance", func() {
}
ordererGroup = grouper.NewParallel(syscall.SIGTERM, orderers)
ordererProc = ifrit.Invoke(ordererGroup)
Eventually(ordererProc.Ready()).Should(BeClosed())
Eventually(ordererProc.Ready(), network.EventuallyTimeout).Should(BeClosed())

o1SnapDir := path.Join(network.RootDir, "orderers", o1.ID(), "etcdraft", "snapshot")

Expand Down Expand Up @@ -251,9 +251,9 @@ var _ = Describe("EndToEnd Crash Fault Tolerance", func() {
o2Proc = ifrit.Invoke(o2Runner)
o3Proc = ifrit.Invoke(o3Runner)

Eventually(o1Proc.Ready()).Should(BeClosed())
Eventually(o2Proc.Ready()).Should(BeClosed())
Eventually(o3Proc.Ready()).Should(BeClosed())
Eventually(o1Proc.Ready(), network.EventuallyTimeout).Should(BeClosed())
Eventually(o2Proc.Ready(), network.EventuallyTimeout).Should(BeClosed())
Eventually(o3Proc.Ready(), network.EventuallyTimeout).Should(BeClosed())

By("Waiting for them to elect a leader")
ordererProcesses := []ifrit.Process{o1Proc, o2Proc, o3Proc}
Expand Down Expand Up @@ -295,9 +295,9 @@ var _ = Describe("EndToEnd Crash Fault Tolerance", func() {
o2Proc = ifrit.Invoke(o2Runner)
o3Proc = ifrit.Invoke(o3Runner)

Eventually(o1Proc.Ready()).Should(BeClosed())
Eventually(o2Proc.Ready()).Should(BeClosed())
Eventually(o3Proc.Ready()).Should(BeClosed())
Eventually(o1Proc.Ready(), network.EventuallyTimeout).Should(BeClosed())
Eventually(o2Proc.Ready(), network.EventuallyTimeout).Should(BeClosed())
Eventually(o3Proc.Ready(), network.EventuallyTimeout).Should(BeClosed())

By("Waiting for them to elect a leader")
ordererProcesses := []ifrit.Process{o1Proc, o2Proc, o3Proc}
Expand Down Expand Up @@ -398,14 +398,14 @@ var _ = Describe("EndToEnd Crash Fault Tolerance", func() {
o2Proc = ifrit.Invoke(o2Runner)
o3Proc = ifrit.Invoke(o3Runner)

Eventually(o1Proc.Ready()).Should(BeClosed())
Eventually(o2Proc.Ready()).Should(BeClosed())
Eventually(o3Proc.Ready()).Should(BeClosed())
Eventually(o1Proc.Ready(), network.EventuallyTimeout).Should(BeClosed())
Eventually(o2Proc.Ready(), network.EventuallyTimeout).Should(BeClosed())
Eventually(o3Proc.Ready(), network.EventuallyTimeout).Should(BeClosed())

By("Waiting for TLS handshakes to fail")
Eventually(o1Runner.Err(), time.Minute, time.Second).Should(gbytes.Say("tls: bad certificate"))
Eventually(o2Runner.Err(), time.Minute, time.Second).Should(gbytes.Say("tls: bad certificate"))
Eventually(o3Runner.Err(), time.Minute, time.Second).Should(gbytes.Say("tls: bad certificate"))
Eventually(o1Runner.Err(), network.EventuallyTimeout).Should(gbytes.Say("tls: bad certificate"))
Eventually(o2Runner.Err(), network.EventuallyTimeout).Should(gbytes.Say("tls: bad certificate"))
Eventually(o3Runner.Err(), network.EventuallyTimeout).Should(gbytes.Say("tls: bad certificate"))

By("Killing orderers")
o1Proc.Signal(syscall.SIGTERM)
Expand All @@ -431,9 +431,9 @@ var _ = Describe("EndToEnd Crash Fault Tolerance", func() {
o2Proc = ifrit.Invoke(o2Runner)
o3Proc = ifrit.Invoke(o3Runner)

Eventually(o1Proc.Ready()).Should(BeClosed())
Eventually(o2Proc.Ready()).Should(BeClosed())
Eventually(o3Proc.Ready()).Should(BeClosed())
Eventually(o1Proc.Ready(), network.EventuallyTimeout).Should(BeClosed())
Eventually(o2Proc.Ready(), network.EventuallyTimeout).Should(BeClosed())
Eventually(o3Proc.Ready(), network.EventuallyTimeout).Should(BeClosed())

By("Waiting for a leader to be elected")
findLeader([]*ginkgomon.Runner{o1Runner, o2Runner, o3Runner})
Expand All @@ -451,14 +451,12 @@ var _ = Describe("EndToEnd Crash Fault Tolerance", func() {
orderer := network.Orderer("orderer")

ordererDomain := network.Organization(orderer.Organization).Domain
ordererCAKeyPath := filepath.Join(network.RootDir, "crypto", "ordererOrganizations",
ordererDomain, "ca", "priv_sk")
ordererCAKeyPath := filepath.Join(network.RootDir, "crypto", "ordererOrganizations", ordererDomain, "ca", "priv_sk")

ordererCAKey, err := ioutil.ReadFile(ordererCAKeyPath)
Expect(err).NotTo(HaveOccurred())

ordererCACertPath := filepath.Join(network.RootDir, "crypto", "ordererOrganizations",
ordererDomain, "ca", fmt.Sprintf("ca.%s-cert.pem", ordererDomain))
ordererCACertPath := filepath.Join(network.RootDir, "crypto", "ordererOrganizations", ordererDomain, "ca", fmt.Sprintf("ca.%s-cert.pem", ordererDomain))
ordererCACert, err := ioutil.ReadFile(ordererCACertPath)
Expect(err).NotTo(HaveOccurred())

Expand Down
2 changes: 1 addition & 1 deletion integration/raft/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ func FetchBlock(n *nwo.Network, o *nwo.Orderer, seq uint64, channel string) *com
Expect(denv).NotTo(BeNil())

var blk *common.Block
var err error
Eventually(func() error {
var err error
blk, err = Deliver(n, o, denv)
return err
}, n.EventuallyTimeout).ShouldNot(HaveOccurred())
Expand Down
Loading

0 comments on commit de8e681

Please sign in to comment.