Skip to content

Commit

Permalink
[FAB-12180] use network.EventuallyTimeout
Browse files Browse the repository at this point in the history
Addresses flake in CI related to process exit completion taking longer
than 1 second.

Applied the pattern via rewrite across all integration packages.

Change-Id: Ia2b2ce0f97acad66ade61b71c836a3a3ad418ad7
Signed-off-by: Matthew Sykes <sykesmat@us.ibm.com>
  • Loading branch information
sykesm committed Sep 28, 2018
1 parent 7f0ea80 commit e193798
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 60 deletions.
27 changes: 13 additions & 14 deletions integration/discovery/discovery_test.go
Expand Up @@ -13,7 +13,6 @@ import (
"os"
"path/filepath"
"syscall"
"time"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -74,7 +73,7 @@ var _ = Describe("DiscoveryService", func() {
AfterEach(func() {
if process != nil {
process.Signal(syscall.SIGTERM)
Eventually(process.Wait(), time.Minute).Should(Receive())
Eventually(process.Wait(), network.EventuallyTimeout).Should(Receive())
}
if network != nil {
network.Cleanup()
Expand All @@ -98,7 +97,7 @@ var _ = Describe("DiscoveryService", func() {
}
sess, err := network.Discover(endorsers)
Expect(err).NotTo(HaveOccurred())
Eventually(sess).Should(gexec.Exit(1))
Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit(1))
Expect(sess.Err).To(gbytes.Say(`failed constructing descriptor for chaincodes:<name:"mycc"`))

By("installing and instantiating chaincode on org1.peer0")
Expand All @@ -114,15 +113,15 @@ var _ = Describe("DiscoveryService", func() {
By("discovering endorsers for chaincode that has not been installed to enough orgs to satisy endorsement policy")
sess, err = network.Discover(endorsers)
Expect(err).NotTo(HaveOccurred())
Eventually(sess).Should(gexec.Exit(1))
Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit(1))
Expect(sess.Err).To(gbytes.Say(`failed constructing descriptor for chaincodes:<name:"mycc"`))

By("installing chaincode to enough organizations to satisfy the endorsement policy")
nwo.InstallChaincode(network, chaincode, org2Peer0)

By("discovering endorsers for chaincode that has been installed to some orgs")
de := discoverEndorsers(network, endorsers)
Eventually(endorsersByGroups(de), time.Minute).Should(ConsistOf(
Eventually(endorsersByGroups(de), network.EventuallyTimeout).Should(ConsistOf(
[]DiscoveredPeer{toDiscoveredPeer(network, org1Peer0)},
[]DiscoveredPeer{toDiscoveredPeer(network, org2Peer0)},
))
Expand All @@ -135,7 +134,7 @@ var _ = Describe("DiscoveryService", func() {
nwo.InstallChaincode(network, chaincode, org3Peer0)

By("discovering endorsers for chaincode that has been installed to all orgs")
Eventually(endorsersByGroups(de), time.Minute).Should(ConsistOf(
Eventually(endorsersByGroups(de), network.EventuallyTimeout).Should(ConsistOf(
[]DiscoveredPeer{toDiscoveredPeer(network, org1Peer0)},
[]DiscoveredPeer{toDiscoveredPeer(network, org2Peer0)},
[]DiscoveredPeer{toDiscoveredPeer(network, org3Peer0)},
Expand All @@ -150,7 +149,7 @@ var _ = Describe("DiscoveryService", func() {
By("discovering endorsers for chaincode with a private collection")
endorsers.Collection = "mycc:collectionMarbles"
de = discoverEndorsers(network, endorsers)
Eventually(endorsersByGroups(de), time.Minute).Should(ConsistOf(
Eventually(endorsersByGroups(de), network.EventuallyTimeout).Should(ConsistOf(
[]DiscoveredPeer{toDiscoveredPeer(network, org1Peer0)},
[]DiscoveredPeer{toDiscoveredPeer(network, org2Peer0)},
))
Expand All @@ -169,7 +168,7 @@ var _ = Describe("DiscoveryService", func() {
endorsers.Collection = ""
endorsers.Chaincode = "mycc2"
de = discoverEndorsers(network, endorsers)
Eventually(endorsersByGroups(de), time.Minute).Should(ConsistOf(
Eventually(endorsersByGroups(de), network.EventuallyTimeout).Should(ConsistOf(
ConsistOf(toDiscoveredPeer(network, org1Peer0), toDiscoveredPeer(network, network.Peer("org1", "peer1"))),
ConsistOf(toDiscoveredPeer(network, org2Peer0), toDiscoveredPeer(network, network.Peer("org2", "peer1"))),
ConsistOf(toDiscoveredPeer(network, org3Peer0), toDiscoveredPeer(network, network.Peer("org3", "peer1"))),
Expand All @@ -196,15 +195,15 @@ var _ = Describe("DiscoveryService", func() {
}
sess, err = network.Discover(endorsers)
Expect(err).NotTo(HaveOccurred())
Eventually(sess).Should(gexec.Exit(1))
Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit(1))
Expect(sess.Err).To(gbytes.Say(`access denied`))
})

It("discovers peer membership", func() {
org1Peer0 := network.Peer("org1", "peer0")

By("discovering peers")
Eventually(discoverPeers(network, org1Peer0, "User1", "testchannel"), time.Minute).Should(ConsistOf(
Eventually(discoverPeers(network, org1Peer0, "User1", "testchannel"), network.EventuallyTimeout).Should(ConsistOf(
toDiscoveredPeer(network, network.Peer("org1", "peer0")),
toDiscoveredPeer(network, network.Peer("org1", "peer1")),
toDiscoveredPeer(network, network.Peer("org2", "peer0")),
Expand All @@ -225,7 +224,7 @@ var _ = Describe("DiscoveryService", func() {

By("discovering peers after installing and instantiating chaincode on a peer")
dp := discoverPeers(network, org1Peer0, "User1", "testchannel")
Eventually(peersWithChaincode(dp, "mycc"), time.Minute).Should(HaveLen(1))
Eventually(peersWithChaincode(dp, "mycc"), network.EventuallyTimeout).Should(HaveLen(1))
peersWithCC := peersWithChaincode(dp, "mycc")()
Expect(peersWithCC).To(ConsistOf(toDiscoveredPeer(network, org1Peer0, "mycc")))
})
Expand All @@ -243,7 +242,7 @@ var _ = Describe("DiscoveryService", func() {
}
sess, err := network.Discover(config)
Expect(err).NotTo(HaveOccurred())
Eventually(sess).Should(gexec.Exit(0))
Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit(0))

By("unmarshaling the response")
discoveredConfig := &discovery.ConfigResult{}
Expand Down Expand Up @@ -294,7 +293,7 @@ func discoverPeers(n *nwo.Network, p *nwo.Peer, user, channelName string) func()
}
sess, err := n.Discover(peers)
Expect(err).NotTo(HaveOccurred())
Eventually(sess).Should(gexec.Exit(0))
Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0))

discovered := []DiscoveredPeer{}
err = json.Unmarshal(sess.Out.Contents(), &discovered)
Expand All @@ -313,7 +312,7 @@ func discoverEndorsers(n *nwo.Network, command commands.Endorsers) func() []Chai
return func() []ChaincodeEndorsers {
sess, err := n.Discover(command)
Expect(err).NotTo(HaveOccurred())
Eventually(sess).Should(gexec.Exit())
Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit())
if sess.ExitCode() != 0 {
return nil
}
Expand Down
14 changes: 7 additions & 7 deletions integration/e2e/acl_test.go
Expand Up @@ -115,7 +115,7 @@ var _ = Describe("EndToEndACL", func() {
By("invoking chaincode as a permitted Org1 Admin identity")
sess, err := network.PeerAdminSession(org1Peer0, invokeChaincode)
Expect(err).NotTo(HaveOccurred())
Eventually(sess.Err, time.Minute).Should(gbytes.Say("Chaincode invoke successful. result: status:200"))
Eventually(sess.Err, network.EventuallyTimeout).Should(gbytes.Say("Chaincode invoke successful. result: status:200"))

//
// when the ACL policy for DeliverFiltered is not satisifed
Expand All @@ -128,7 +128,7 @@ var _ = Describe("EndToEndACL", func() {
By("invoking chaincode as a forbidden Org1 Admin identity")
sess, err = network.PeerAdminSession(org1Peer0, invokeChaincode)
Expect(err).NotTo(HaveOccurred())
Eventually(sess.Err, time.Minute).Should(gbytes.Say(`\Qdeliver completed with status (FORBIDDEN)\E`))
Eventually(sess.Err, network.EventuallyTimeout).Should(gbytes.Say(`\Qdeliver completed with status (FORBIDDEN)\E`))

//
// when the ACL policy for Deliver is satisfied
Expand All @@ -141,7 +141,7 @@ var _ = Describe("EndToEndACL", func() {
By("fetching the latest block from the peer as a permitted Org1 Admin identity")
sess, err = network.PeerAdminSession(org1Peer0, fetchNewest)
Expect(err).NotTo(HaveOccurred())
Eventually(sess, time.Minute).Should(gexec.Exit(0))
Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit(0))
Expect(sess.Err).To(gbytes.Say("Received block: "))

//
Expand All @@ -150,7 +150,7 @@ var _ = Describe("EndToEndACL", func() {
By("fetching the latest block from the peer as a forbidden org2 Admin identity")
sess, err = network.PeerAdminSession(org2Peer0, fetchNewest)
Expect(err).NotTo(HaveOccurred())
Eventually(sess, time.Minute).Should(gexec.Exit())
Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit())
Expect(sess.Err).To(gbytes.Say("can't read the block: &{FORBIDDEN}"))

//
Expand All @@ -166,7 +166,7 @@ var _ = Describe("EndToEndACL", func() {
ChannelID: "testchannel",
})
Expect(err).NotTo(HaveOccurred())
Eventually(sess, time.Minute).Should(gexec.Exit(0))
Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit(0))
Expect(sess).To(gbytes.Say("Name: mycc, Version: 0.0, Path: .*, Escc: escc, Vscc: vscc"))

//
Expand All @@ -177,7 +177,7 @@ var _ = Describe("EndToEndACL", func() {
ChannelID: "testchannel",
})
Expect(err).NotTo(HaveOccurred())
Eventually(sess, time.Minute).Should(gexec.Exit())
Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit())
Expect(sess).NotTo(gbytes.Say("Name: mycc, Version: 0.0, Path: .*, Escc: escc, Vscc: vscc"))
Expect(sess.Err).To(gbytes.Say(`access denied for \[getchaincodes\]\[testchannel\](.*)signature set did not satisfy policy`))

Expand All @@ -188,7 +188,7 @@ var _ = Describe("EndToEndACL", func() {
// getting a transaction id from a block in the ledger
sess, err = network.PeerAdminSession(org1Peer0, fetchNewest)
Expect(err).NotTo(HaveOccurred())
Eventually(sess, time.Minute).Should(gexec.Exit(0))
Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit(0))
Expect(sess.Err).To(gbytes.Say("Received block: "))
txID := GetTxIDFromBlockFile(outputBlock)

Expand Down
9 changes: 4 additions & 5 deletions integration/e2e/e2e_test.go
Expand Up @@ -10,7 +10,6 @@ import (
"io/ioutil"
"os"
"syscall"
"time"

docker "github.com/fsouza/go-dockerclient"
. "github.com/onsi/ginkgo"
Expand Down Expand Up @@ -52,7 +51,7 @@ var _ = Describe("EndToEnd", func() {
AfterEach(func() {
if process != nil {
process.Signal(syscall.SIGTERM)
Eventually(process.Wait(), time.Minute).Should(Receive())
Eventually(process.Wait(), network.EventuallyTimeout).Should(Receive())
}
if network != nil {
network.Cleanup()
Expand Down Expand Up @@ -118,7 +117,7 @@ func RunQueryInvokeQuery(n *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer) {
Ctor: `{"Args":["query","a"]}`,
})
Expect(err).NotTo(HaveOccurred())
Eventually(sess, time.Minute).Should(gexec.Exit(0))
Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0))
Expect(sess).To(gbytes.Say("100"))

sess, err = n.PeerUserSession(peer, "User1", commands.ChaincodeInvoke{
Expand All @@ -133,7 +132,7 @@ func RunQueryInvokeQuery(n *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer) {
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:200"))

sess, err = n.PeerUserSession(peer, "User1", commands.ChaincodeQuery{
Expand All @@ -142,6 +141,6 @@ func RunQueryInvokeQuery(n *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer) {
Ctor: `{"Args":["query","a"]}`,
})
Expect(err).NotTo(HaveOccurred())
Eventually(sess, time.Minute).Should(gexec.Exit(0))
Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0))
Expect(sess).To(gbytes.Say("90"))
}
11 changes: 5 additions & 6 deletions integration/java_chaincode/javacc_test.go
Expand Up @@ -10,7 +10,6 @@ import (
"io/ioutil"
"os"
"syscall"
"time"

"github.com/fsouza/go-dockerclient"
. "github.com/onsi/ginkgo"
Expand Down Expand Up @@ -52,7 +51,7 @@ var _ = Describe("Java Chaincode EndToEnd Suite", func() {
AfterEach(func() {
if process != nil {
process.Signal(syscall.SIGKILL)
Eventually(process.Wait(), time.Minute).Should(Receive())
Eventually(process.Wait(), network.EventuallyTimeout).Should(Receive())
}
if network != nil {
network.Cleanup()
Expand Down Expand Up @@ -125,7 +124,7 @@ func RunQueryInvokeQuery(n *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer) {
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:200"))

By("querying the chaincode - 1")
Expand All @@ -135,7 +134,7 @@ func RunQueryInvokeQuery(n *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer) {
Ctor: `{"Args":["query","a"]}`,
})
Expect(err).NotTo(HaveOccurred())
Eventually(sess, time.Minute).Should(gexec.Exit(0))
Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0))
Expect(sess).To(gbytes.Say("90"))

By("invoking the chaincode - 2")
Expand All @@ -150,7 +149,7 @@ func RunQueryInvokeQuery(n *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer) {
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:200"))

By("querying the chaincode - 2")
Expand All @@ -160,6 +159,6 @@ func RunQueryInvokeQuery(n *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer) {
Ctor: `{"Args":["query","b"]}`,
})
Expect(err).NotTo(HaveOccurred())
Eventually(sess, time.Minute).Should(gexec.Exit(0))
Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0))
Expect(sess).To(gbytes.Say("220"))
}
5 changes: 2 additions & 3 deletions integration/nwo/network_test.go
Expand Up @@ -11,7 +11,6 @@ import (
"io/ioutil"
"os"
"syscall"
"time"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -70,7 +69,7 @@ var _ = Describe("Network", func() {
AfterEach(func() {
// Shutodwn processes and cleanup
process.Signal(syscall.SIGTERM)
Eventually(process.Wait(), time.Minute).Should(Receive())
Eventually(process.Wait(), network.EventuallyTimeout).Should(Receive())
network.Cleanup()
})

Expand Down Expand Up @@ -120,7 +119,7 @@ var _ = Describe("Network", func() {
AfterEach(func() {
for _, p := range processes {
p.Signal(syscall.SIGTERM)
Eventually(p.Wait(), time.Minute).Should(Receive())
Eventually(p.Wait(), network.EventuallyTimeout).Should(Receive())
}
network.Cleanup()
})
Expand Down
6 changes: 3 additions & 3 deletions integration/pluggable/pluggable_test.go
Expand Up @@ -157,7 +157,7 @@ func RunQueryInvokeQuery(n *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer) {
Ctor: `{"Args":["query","a"]}`,
})
Expect(err).NotTo(HaveOccurred())
Eventually(sess, time.Minute).Should(gexec.Exit(0))
Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0))
Expect(sess).To(gbytes.Say("100"))

sess, err = n.PeerUserSession(peer, "User1", commands.ChaincodeInvoke{
Expand All @@ -172,7 +172,7 @@ func RunQueryInvokeQuery(n *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer) {
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:200"))

sess, err = n.PeerUserSession(peer, "User1", commands.ChaincodeQuery{
Expand All @@ -181,6 +181,6 @@ func RunQueryInvokeQuery(n *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer) {
Ctor: `{"Args":["query","a"]}`,
})
Expect(err).NotTo(HaveOccurred())
Eventually(sess, time.Minute).Should(gexec.Exit(0))
Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0))
Expect(sess).To(gbytes.Say("90"))
}

0 comments on commit e193798

Please sign in to comment.