Skip to content

Commit 5a1c542

Browse files
Add smart starting of containers during tests
Change 'Given I start peers' to 'Given I start peers, waiting up to "<time>" seconds for them to be ready', reusing the functions created for intelligently starting used in 'Given we compose <compose-file>'. Modify the issue_1874b test to wait for the transaction invoked during vp0's down time to be committed instead of implicitly accomplishing this during the wait for 15 seconds statement. Change-Id: Ib4b00a6d4eb1dfb50f065cba7ac1d4804f447798 Signed-off-by: Julian Carrivick <[email protected]>
1 parent cc111e2 commit 5a1c542

File tree

3 files changed

+27
-26
lines changed

3 files changed

+27
-26
lines changed

bddtests/peer_basic.feature

+14-18
Original file line numberDiff line numberDiff line change
@@ -561,9 +561,8 @@ Feature: Network of Peers
561561
| vp0 | vp1 | vp2 |
562562

563563
# Now start vp3 again
564-
Given I start peers:
564+
Given I start peers, waiting up to "15" seconds for them to be ready:
565565
| vp3 |
566-
And I wait "15" seconds
567566

568567
# Invoke 10 more txs, this will trigger a state transfer, set a target, and execute new outstanding transactions
569568
When I invoke chaincode "example2" function name "invoke" on "vp0" "10" times
@@ -614,9 +613,8 @@ Feature: Network of Peers
614613
Given I stop peers:
615614
| vp0 | vp1 | vp2 | vp3 |
616615

617-
Given I start peers:
616+
Given I start peers, waiting up to "15" seconds for them to be ready:
618617
| vp0 | vp1 | vp2 | vp3 |
619-
And I wait "15" seconds
620618

621619
When I query chaincode "example2" function name "query" with value "a" on peers:
622620
| vp3 |
@@ -868,9 +866,8 @@ Feature: Network of Peers
868866
| vp1 | vp2 | vp3 |
869867

870868
# Now start vp1, vp2 again, hopefully retaining pbft state
871-
Given I start peers:
869+
Given I start peers, waiting up to "15" seconds for them to be ready:
872870
| vp1 | vp2 |
873-
And I wait "15" seconds
874871

875872
# Invoke 1 more tx, if the crash recovery worked, it will commit, otherwise, it will not
876873
When I invoke chaincode "example2" function name "invoke" on "vp0"
@@ -934,7 +931,7 @@ Feature: Network of Peers
934931
| vp0 | vp1 | vp2 |
935932

936933
# Now start vp3 again
937-
Given I start peers:
934+
Given I start peers, waiting up to "15" seconds for them to be ready:
938935
| vp3 |
939936

940937
# Invoke some more txs, this will trigger a state transfer, but it cannot complete
@@ -1064,9 +1061,8 @@ Feature: Network of Peers
10641061
When requesting "/network/peers" from "vp1"
10651062
Then I should get a JSON response with array "peers" contains "1" elements
10661063

1067-
Given I start peers:
1064+
Given I start peers, waiting up to "15" seconds for them to be ready:
10681065
| vp0 |
1069-
And I wait "10" seconds
10701066

10711067
When requesting "/network/peers" from "vp1"
10721068
Then I should get a JSON response with array "peers" contains "2" elements
@@ -1120,10 +1116,9 @@ Scenario: chaincode example02 with 4 peers, stop and start alternates, reverse
11201116
Then I should get a JSON response from peers with "result.message" = "997"
11211117
| vp0 | vp1 | vp3 |
11221118

1123-
Given I start peers:
1119+
Given I start peers, waiting up to "15" seconds for them to be ready:
11241120
| vp2 |
11251121

1126-
And I wait "15" seconds
11271122
Given I stop peers:
11281123
| vp1 |
11291124
When I invoke chaincode "example2" function name "invoke" on "vp3" "20" times
@@ -1173,7 +1168,7 @@ Scenario: chaincode example02 with 4 peers, two stopped
11731168
| a | b | 10 |
11741169
Then I should have received a transactionID
11751170

1176-
Given I start peers:
1171+
Given I start peers, waiting up to "15" seconds for them to be ready:
11771172
| vp3 |
11781173

11791174
# Make sure vp3 catches up first
@@ -1197,7 +1192,6 @@ Scenario: chaincode example02 with 4 peers, two stopped
11971192
| vp0 | vp1 | vp3 |
11981193

11991194
@issue_1874b
1200-
#@doNotDecompose
12011195
Scenario: chaincode example02 with 4 peers, two stopped, bring back vp0
12021196
Given we compose "docker-compose-4-consensus-batch.yml"
12031197
And I register with CA supplying username "binhn" and secret "7avZQLwcUe9q" on peers:
@@ -1243,15 +1237,18 @@ Scenario: chaincode example02 with 4 peers, two stopped, bring back vp0
12431237
| a | b | 10 |
12441238
Then I should have received a transactionID
12451239

1246-
Given I start peers:
1240+
Given I start peers, waiting up to "15" seconds for them to be ready:
12471241
| vp0 |
1248-
And I wait "15" seconds
1242+
1243+
# Ensure transaction committed while vp0 was down is part of the ledger
1244+
Then I wait up to "60" seconds for transaction to be committed to peers:
1245+
| vp0 | vp1 | vp2 |
12491246

12501247
When I invoke chaincode "example2" function name "invoke" on "vp1" "8" times
12511248
|arg1|arg2|arg3|
12521249
| a | b | 10 |
12531250
Then I should have received a transactionID
1254-
Then I wait up to "60" seconds for transaction to be committed to peers:
1251+
Then I wait up to "60" seconds for transactions to be committed to peers:
12551252
| vp0 | vp1 | vp2 |
12561253

12571254
When I query chaincode "example2" function name "query" with value "a" on peers:
@@ -1294,9 +1291,8 @@ Scenario: chaincode example02 with 4 peers, two stopped, bring back both
12941291
| a | b | 10 |
12951292
Then I should have received a transactionID
12961293

1297-
Given I start peers:
1294+
Given I start peers, waiting up to "15" seconds for them to be ready:
12981295
| vp1 | vp2 |
1299-
And I wait "15" seconds
13001296

13011297
When I invoke chaincode "example2" function name "invoke" on "vp0" "8" times
13021298
|arg1|arg2|arg3|

bddtests/steps/bdd_compose_util.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -116,20 +116,22 @@ def getDockerComposeServiceForContainer(containerName):
116116
return dockerComposeService
117117

118118
def allContainersAreReadyWithinTimeout(context, timeout):
119+
allContainers = context.compose_containers
120+
return containersAreReadyWithinTimeout(context, allContainers, timeout)
121+
122+
def containersAreReadyWithinTimeout(context, containers, timeout):
119123
timeoutTimestamp = time.time() + timeout
120124
formattedTime = time.strftime("%X", time.localtime(timeoutTimestamp))
121125
bdd_log("All containers should be up by {}".format(formattedTime))
122126

123-
allContainers = context.compose_containers
124-
125-
for container in allContainers:
127+
for container in containers:
126128
if not containerIsInitializedByTimestamp(container, timeoutTimestamp):
127129
return False
128130

129-
peersAreReady = peersAreReadyByTimestamp(context, allContainers, timeoutTimestamp)
131+
peersAreReady = peersAreReadyByTimestamp(context, containers, timeoutTimestamp)
130132

131133
if peersAreReady:
132-
bdd_log("All containers in ready state, ready to proceed")
134+
bdd_log("Containers in ready state, ready to proceed")
133135

134136
return peersAreReady
135137

bddtests/steps/peer_basic_impl.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -586,11 +586,14 @@ def step_impl(context):
586586
assert os.path.isfile(listener), "Please build the block-listener binary!"
587587
bdd_test_util.start_background_process(context, "eventlistener", [listener, "-listen-to-rejections"] )
588588

589-
590-
@given(u'I start peers')
591-
def step_impl(context):
589+
@given(u'I start peers, waiting up to "{seconds}" seconds for them to be ready')
590+
def step_impl(context, seconds):
592591
compose_op(context, "start")
593592

593+
timeout = int(seconds)
594+
assert bdd_compose_util.allContainersAreReadyWithinTimeout(context, timeout), \
595+
"Peers did not come up within {} seconds, aborting.".format(timeout)
596+
594597
@given(u'I stop peers')
595598
def step_impl(context):
596599
compose_op(context, "stop")

0 commit comments

Comments
 (0)