Skip to content

Commit 7a2d6a5

Browse files
guogerC0rWin
authored andcommitted
[FAB-11918] Add CFT integration test.
Change-Id: I23e4ef5c764dc980f1e100cfc26ffe2988ce6f6e Signed-off-by: Jay Guo <guojiannan1101@gmail.com>
1 parent 858aaa9 commit 7a2d6a5

File tree

1 file changed

+138
-0
lines changed

1 file changed

+138
-0
lines changed

integration/e2e/cft_test.go

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/*
2+
Copyright IBM Corp All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package e2e
8+
9+
import (
10+
"io/ioutil"
11+
"os"
12+
"path/filepath"
13+
"syscall"
14+
15+
docker "github.com/fsouza/go-dockerclient"
16+
"github.com/hyperledger/fabric/integration/nwo"
17+
"github.com/hyperledger/fabric/integration/nwo/commands"
18+
. "github.com/onsi/ginkgo"
19+
. "github.com/onsi/gomega"
20+
"github.com/onsi/gomega/gexec"
21+
"github.com/tedsuo/ifrit"
22+
"github.com/tedsuo/ifrit/grouper"
23+
)
24+
25+
var _ = Describe("EndToEnd Crash Fault Tolerance", func() {
26+
var (
27+
testDir string
28+
client *docker.Client
29+
network *nwo.Network
30+
chaincode nwo.Chaincode
31+
32+
networkProc, o1Proc ifrit.Process
33+
)
34+
35+
BeforeEach(func() {
36+
var err error
37+
testDir, err = ioutil.TempDir("", "e2e")
38+
Expect(err).NotTo(HaveOccurred())
39+
40+
client, err = docker.NewClientFromEnv()
41+
Expect(err).NotTo(HaveOccurred())
42+
43+
chaincode = nwo.Chaincode{
44+
Name: "mycc",
45+
Version: "0.0",
46+
Path: "github.com/hyperledger/fabric/integration/chaincode/simple/cmd",
47+
Ctor: `{"Args":["init","a","100","b","200"]}`,
48+
Policy: `AND ('Org1MSP.member','Org2MSP.member')`,
49+
}
50+
})
51+
52+
AfterEach(func() {
53+
if o1Proc != nil {
54+
o1Proc.Signal(syscall.SIGTERM)
55+
Eventually(o1Proc.Wait(), network.EventuallyTimeout).Should(Receive())
56+
}
57+
if networkProc != nil {
58+
networkProc.Signal(syscall.SIGTERM)
59+
Eventually(networkProc.Wait(), network.EventuallyTimeout).Should(Receive())
60+
}
61+
if network != nil {
62+
network.Cleanup()
63+
}
64+
os.RemoveAll(testDir)
65+
})
66+
67+
When("orderer stops and restarts", func() {
68+
It("keeps network up and running", func() {
69+
network = nwo.New(nwo.MultiNodeEtcdRaft(), testDir, client, 33000, components)
70+
71+
o1, o2, o3 := network.Orderer("orderer1"), network.Orderer("orderer2"), network.Orderer("orderer3")
72+
p := network.Peer("Org1", "peer1")
73+
blockFile1 := filepath.Join(testDir, "newest_orderer1_block.pb")
74+
blockFile2 := filepath.Join(testDir, "newest_orderer2_block.pb")
75+
76+
network.GenerateConfigTree()
77+
network.Bootstrap()
78+
79+
o1Runner := network.OrdererRunner(o1)
80+
orderers := grouper.Members{
81+
{Name: o2.ID(), Runner: network.OrdererRunner(o2)},
82+
{Name: o3.ID(), Runner: network.OrdererRunner(o3)},
83+
}
84+
ordererGroup := grouper.NewParallel(syscall.SIGTERM, orderers)
85+
peerGroup := network.PeerGroupRunner()
86+
87+
networkRunner := grouper.NewOrdered(
88+
syscall.SIGTERM,
89+
grouper.Members{
90+
{Name: "orderers", Runner: ordererGroup},
91+
{Name: "peers", Runner: peerGroup},
92+
},
93+
)
94+
o1Proc = ifrit.Invoke(o1Runner)
95+
networkProc = ifrit.Invoke(networkRunner)
96+
Eventually(o1Proc.Ready()).Should(BeClosed())
97+
Eventually(networkProc.Ready()).Should(BeClosed())
98+
99+
By("performing operation with orderer1")
100+
network.CreateAndJoinChannel(o1, "testchannel")
101+
102+
By("killing orderer1")
103+
o1Proc.Signal(syscall.SIGKILL)
104+
Eventually(o1Proc.Wait(), network.EventuallyTimeout).Should(Receive(MatchError("exit status 137")))
105+
106+
By("performing operations with running orderer")
107+
nwo.DeployChaincode(network, "testchannel", o2, chaincode)
108+
109+
By("restarting orderer1")
110+
o1Runner = network.OrdererRunner(o1)
111+
o1Proc = ifrit.Invoke(o1Runner)
112+
Eventually(o1Proc.Ready()).Should(BeClosed())
113+
114+
By("executing transaction with restarted orderer")
115+
RunQueryInvokeQuery(network, o1, p, "testchannel")
116+
117+
fetchLatestBlock := func(targetOrderer *nwo.Orderer, blockFile string) {
118+
c := commands.ChannelFetch{
119+
ChannelID: "testchannel",
120+
Block: "newest",
121+
OutputFile: blockFile,
122+
}
123+
if targetOrderer != nil {
124+
c.Orderer = network.OrdererAddress(targetOrderer, nwo.ListenPort)
125+
}
126+
sess, err := network.PeerAdminSession(p, c)
127+
Expect(err).NotTo(HaveOccurred())
128+
Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit(0))
129+
}
130+
131+
fetchLatestBlock(o1, blockFile1)
132+
fetchLatestBlock(o2, blockFile2)
133+
b1 := nwo.UnmarshalBlockFromFile(blockFile1)
134+
b2 := nwo.UnmarshalBlockFromFile(blockFile2)
135+
Expect(b1.Header.Bytes()).To(Equal(b2.Header.Bytes()))
136+
})
137+
})
138+
})

0 commit comments

Comments
 (0)