Skip to content

Commit 8547618

Browse files
authored
Fix intermittent errors with test-network ca (#1305)
If CA server hasn't finished initialization then the initial register and enroll requests will fail. Instead of waiting 3 seconds, actually check if CA service is ready. Signed-off-by: David Enyeart <[email protected]>
1 parent 50699a6 commit 8547618

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

test-network/network.sh

+15-2
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,9 @@ function createOrgs() {
224224
infoln "Generating certificates using Fabric CA"
225225
${CONTAINER_CLI_COMPOSE} -f compose/$COMPOSE_FILE_CA -f compose/$CONTAINER_CLI/${CONTAINER_CLI}-$COMPOSE_FILE_CA up -d 2>&1
226226

227-
# Allow CAs to initialize and then make register and enroll requests
228-
sleep 3
229227
. organizations/fabric-ca/registerEnroll.sh
230228

229+
# Make sure CA files have been created
231230
while :
232231
do
233232
if [ ! -f "organizations/fabric-ca/org1/tls-cert.pem" ]; then
@@ -237,6 +236,20 @@ function createOrgs() {
237236
fi
238237
done
239238

239+
# Make sure CA service is initialized and can accept requests before making register and enroll calls
240+
export FABRIC_CA_CLIENT_HOME=${PWD}/organizations/peerOrganizations/org1.example.com/
241+
COUNTER=0
242+
rc=1
243+
while [[ $rc -ne 0 && $COUNTER -lt $MAX_RETRY ]]; do
244+
sleep 1
245+
set -x
246+
fabric-ca-client getcainfo -u https://admin:adminpw@localhost:7054 --caname ca-org1 --tls.certfiles "${PWD}/organizations/fabric-ca/org1/ca-cert.pem"
247+
res=$?
248+
{ set +x; } 2>/dev/null
249+
rc=$res # Update rc
250+
COUNTER=$((COUNTER + 1))
251+
done
252+
240253
infoln "Creating Org1 Identities"
241254

242255
createOrg1

0 commit comments

Comments
 (0)