Skip to content

Commit

Permalink
[FAB-11207] Fix local integration tests
Browse files Browse the repository at this point in the history
This change fixes override paths and matchers for host run
integration tests.

The scripts now also wait for the docker host to become available.

Change-Id: Id9e7017641cc372c30fa13f831d5ff96fb5ea6c7
Signed-off-by: Troy Ronda <[email protected]>
  • Loading branch information
troyronda committed Jul 18, 2018
1 parent 4fadae5 commit eebf851
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ endif
BASE_DOCKER_COMPOSE_FILES := -f ./docker-compose.yaml
ifeq ($(FABRIC_SDK_ENABLE_CHAINCODED),true)
BASE_DOCKER_COMPOSE_FILES := -f ./docker-compose-chaincoded.yaml $(BASE_DOCKER_COMPOSE_FILES)
export CORE_VM_ENDPOINT=http://chaincoded.example.com:2375
export CORE_VM_ENDPOINT=http://chaincoded.example.com:9375
else
BASE_DOCKER_COMPOSE_FILES := -f ./docker-compose-std.yaml $(BASE_DOCKER_COMPOSE_FILES)
endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@ entityMatchers:
sslTargetOverrideUrlSubstitutionExp: $1.org1.example.com
mappedHost: local.peer0.org1.example.com

- pattern: peer0.org2.example.com:8051
urlSubstitutionExp: localhost:8051
sslTargetOverrideUrlSubstitutionExp: peer0.org2.example.com
## TODO added below peer to ignore list, to avoid these revoked peer to conflict with bootstrap test
- pattern: peer1.org2.example.com:(\d+)
ignoreEndpoint: true

- pattern: peer1.org2.example.com
ignoreEndpoint: true

- pattern: (\w+).org2.example.com:(\d+)
urlSubstitutionExp: localhost:$2
sslTargetOverrideUrlSubstitutionExp: $1.org2.example.com
mappedHost: local.peer0.org2.example.com

orderer:
Expand Down
8 changes: 5 additions & 3 deletions test/fixtures/dockerenv/docker-compose-chaincoded.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ services:
- ../../../test/fixtures/testdata/src/github.com/example_pvt_cc:/opt/gopath/src/github.com/example_pvt_cc
command: /opt/gopath/src/github.com/hyperledger/fabric-sdk-go/test/scripts/chaincoded.sh
#comment out logging.driver in order to render the debug logs
logging:
driver: none
#logging:
# driver: none
networks:
default:
aliases:
- chaincoded.example.com
ports:
- "9375:9375"
expose:
- "2375"
- "9375"
depends_on:
- dockerd
1 change: 1 addition & 0 deletions test/fixtures/dockerenv/docker-compose-negative.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ services:
- FABRIC_FIXTURE_VERSION
- FABRIC_SDK_CLIENT_EVENTSERVICE_TYPE
- TEST_CHANGED_ONLY
- CORE_VM_ENDPOINT
volumes:
- ../../../:/opt/gopath/src/github.com/hyperledger/fabric-sdk-go
command: /opt/gopath/src/github.com/hyperledger/fabric-sdk-go/test/scripts/negative.sh
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/dockerenv/docker-compose-nopkcs11-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ services:
- FABRIC_SDK_CLIENT_EVENTSERVICE_TYPE
- E2E_ONLY
- TEST_CHANGED_ONLY
- CORE_VM_ENDPOINT
volumes:
- ../../../:/opt/gopath/src/github.com/hyperledger/fabric-sdk-go
command: /opt/gopath/src/github.com/hyperledger/fabric-sdk-go/test/scripts/integration.sh
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/dockerenv/docker-compose-pkcs11-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ services:
- FABRIC_FIXTURE_VERSION
- FABRIC_SDK_CLIENT_EVENTSERVICE_TYPE
- TEST_CHANGED_ONLY
- CORE_VM_ENDPOINT
volumes:
- ../../../:/opt/gopath/src/github.com/hyperledger/fabric-sdk-go
command: bash -c "/opt/gopath/src/github.com/hyperledger/fabric-sdk-go/test/scripts/unit-pkcs11.sh && /opt/gopath/src/github.com/hyperledger/fabric-sdk-go/test/scripts/integration-pkcs11.sh"
Expand Down
2 changes: 1 addition & 1 deletion test/integration/base_test_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func GetConfigPath(filename string) string {

// GetConfigOverridesPath returns the path to the named config override fixture file
func GetConfigOverridesPath(filename string) string {
const configPath = "test/fixtures/config/overrides"
const configPath = "test/fixtures/config"
return path.Join(goPath(), "src", metadata.Project, configPath, "overrides", filename)
}

Expand Down
5 changes: 4 additions & 1 deletion test/scripts/chaincoded.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ GOPATH="${GOPATH:-$HOME/go}"
mkdir -p ${GOPATH}/src/github.com/hyperledger
ln -s ${GOPATH}/src/chaincoded/vendor/github.com/hyperledger/fabric ${GOPATH}/src/github.com/hyperledger/fabric

echo "Installing chaincodes ..."
go install github.com/example_cc
go install github.com/example_pvt_cc
go install chaincoded/cmd/chaincoded
Expand All @@ -24,4 +25,6 @@ PEERS=(
peer1.org2.example.com:9052
)

chaincoded ":2375" ${PEERS[@]}
# Remove dev/null redirection to see chaincode logs
echo "Running chaincoded ..."
chaincoded ":9375" ${PEERS[@]} > /dev/null 2> /dev/null
3 changes: 3 additions & 0 deletions test/scripts/integration-pkcs11.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ SCRIPT_DIR="$(dirname "$0")"
REPO="github.com/hyperledger/fabric-sdk-go"

source ${SCRIPT_DIR}/lib/find_packages.sh
source ${SCRIPT_DIR}/lib/docker.sh

echo "Running" $(basename "$0")

Expand Down Expand Up @@ -96,6 +97,8 @@ do
rm -rf private.p8
done

waitForCoreVMUp

echo "Code level ${FABRIC_SDKGO_CODELEVEL_TAG} (Fabric ${FABRIC_FIXTURE_VERSION})"
echo "Running integration tests ..."

Expand Down
3 changes: 3 additions & 0 deletions test/scripts/integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ SCRIPT_DIR="$(dirname "$0")"
REPO="github.com/hyperledger/fabric-sdk-go"

source ${SCRIPT_DIR}/lib/find_packages.sh
source ${SCRIPT_DIR}/lib/docker.sh

echo "Running" $(basename "$0")

Expand Down Expand Up @@ -84,6 +85,8 @@ if [ ${#PKGS[@]} -eq 0 ]; then
exit 0
fi

waitForCoreVMUp

echo "Code level ${FABRIC_SDKGO_CODELEVEL_TAG} (Fabric ${FABRIC_FIXTURE_VERSION})"
echo "Running integration tests ..."

Expand Down
37 changes: 37 additions & 0 deletions test/scripts/lib/docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash
#
# Copyright SecureKey Technologies Inc. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#

function waitForCoreVMUp {
# When dockerd handles chaincode operation, we need to wait for it to be ready
# (it takes time to start due to chaincode compilation).
if [[ "${CORE_VM_ENDPOINT}" =~ http://(.*):(.*) ]]; then
declare attempt=0
declare host=${BASH_REMATCH[1]}
declare port=${BASH_REMATCH[2]}

if [ "${TEST_LOCAL}" = true ]; then
host="localhost"
fi

echo "Waiting for VM endpoint to listen [${host}:${port}]..."
while true; do
if [ ${attempt} -gt 120 ]; then
echo "VM endpoint not listening after ${attempt} attempts"
exit 1
fi

alive=$(curl -s --head --request GET ${host}:${port}/info || true)
if [[ "${alive}" =~ ^HTTP/(.*)200 ]]; then
break
fi

sleep 1
attempt=$((attempt + 1))
done
echo "VM endpoint is listening after ${attempt} attempts"
fi
}
3 changes: 3 additions & 0 deletions test/scripts/negative.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ SCRIPT_DIR="$(dirname "$0")"
REPO="github.com/hyperledger/fabric-sdk-go"

source ${SCRIPT_DIR}/lib/find_packages.sh
source ${SCRIPT_DIR}/lib/docker.sh

echo "Running" $(basename "$0")

Expand Down Expand Up @@ -73,6 +74,8 @@ if [ ${#PKGS[@]} -eq 0 ]; then
exit 0
fi

waitForCoreVMUp

echo "Code level ${FABRIC_SDKGO_CODELEVEL_TAG} (Fabric ${FABRIC_FIXTURE_VERSION})"
echo "Running integration tests for expired orderer certificates ..."

Expand Down

0 comments on commit eebf851

Please sign in to comment.