add a retry to the test-network ccaas chaincode init command

Without this, the init command fails if the chaincode container is not ready.

Signed-off-by: Arne Rutjes <arne123@gmail.com>
This commit is contained in:
Arne Rutjes 2023-09-18 16:17:35 +02:00 committed by Dave Enyeart
parent 9441772423
commit 98f748155b

View file

@ -126,15 +126,24 @@ function chaincodeInvokeInit() {
res=$? res=$?
verifyResult $res "Invoke transaction failed on channel '$CHANNEL_NAME' due to uneven number of peer and org parameters " verifyResult $res "Invoke transaction failed on channel '$CHANNEL_NAME' due to uneven number of peer and org parameters "
# while 'peer chaincode' command can get the orderer endpoint from the local rc=1
# peer (if join was successful), let's supply it directly as we know local COUNTER=1
# it using the "-o" option local fcn_call='{"function":"'${CC_INIT_FCN}'","Args":[]}'
set -x # continue to poll
fcn_call='{"function":"'${CC_INIT_FCN}'","Args":[]}' # we either get a successful response, or reach MAX RETRY
infoln "invoke fcn call:${fcn_call}" while [ $rc -ne 0 -a $COUNTER -lt $MAX_RETRY ]; do
peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile "$ORDERER_CA" -C $CHANNEL_NAME -n ${CC_NAME} "${PEER_CONN_PARMS[@]}" --isInit -c ${fcn_call} >&log.txt sleep $DELAY
res=$? # while 'peer chaincode' command can get the orderer endpoint from the
{ set +x; } 2>/dev/null # peer (if join was successful), let's supply it directly as we know
# it using the "-o" option
set -x
infoln "invoke fcn call:${fcn_call}"
peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile "$ORDERER_CA" -C $CHANNEL_NAME -n ${CC_NAME} "${PEER_CONN_PARMS[@]}" --isInit -c ${fcn_call} >&log.txt
res=$?
{ set +x; } 2>/dev/null
let rc=$res
COUNTER=$(expr $COUNTER + 1)
done
cat log.txt cat log.txt
verifyResult $res "Invoke execution on $PEERS failed " verifyResult $res "Invoke execution on $PEERS failed "
successln "Invoke transaction successful on $PEERS on channel '$CHANNEL_NAME'" successln "Invoke transaction successful on $PEERS on channel '$CHANNEL_NAME'"