From 0d8e8458d8dc8a4b6090926898467e81686208f0 Mon Sep 17 00:00:00 2001 From: Joshua Kim <20001595+joshua-kim@users.noreply.github.com> Date: Wed, 30 Nov 2022 19:32:19 -0500 Subject: [PATCH] Add race detection to the e2e tests (#2299) --- .github/workflows/run_e2e_tests.sh | 2 +- .github/workflows/test.e2e.yml | 2 +- scripts/build.sh | 26 +++++++++++++-- scripts/build_avalanche.sh | 23 +++++++++++++- scripts/build_coreth.sh | 51 +++++++++++++++++++++++------- scripts/local.Dockerfile | 2 +- scripts/tests.e2e.sh | 2 +- 7 files changed, 89 insertions(+), 19 deletions(-) diff --git a/.github/workflows/run_e2e_tests.sh b/.github/workflows/run_e2e_tests.sh index a2404688c010..2b56af5f0a06 100755 --- a/.github/workflows/run_e2e_tests.sh +++ b/.github/workflows/run_e2e_tests.sh @@ -45,7 +45,7 @@ docker pull $avalanchego_byzantine_image git_commit_id=$( git rev-list -1 HEAD ) # Build current avalanchego -source "$AVALANCHE_PATH"/scripts/build_image.sh +source "$AVALANCHE_PATH"/scripts/build_image.sh -r # Target built version to use in avalanche-testing avalanche_image="$avalanchego_dockerhub_repo:$current_branch" diff --git a/.github/workflows/test.e2e.yml b/.github/workflows/test.e2e.yml index 25e7e1b6edce..f6984d28b184 100644 --- a/.github/workflows/test.e2e.yml +++ b/.github/workflows/test.e2e.yml @@ -22,7 +22,7 @@ jobs: check-latest: true - name: Build the avalanchego binaries shell: bash - run: ./scripts/build.sh + run: ./scripts/build.sh -r - name: Run e2e tests shell: bash run: scripts/tests.e2e.sh ./build/avalanchego diff --git a/scripts/build.sh b/scripts/build.sh index a427058c3424..304d3dce5065 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -4,6 +4,26 @@ set -o errexit set -o nounset set -o pipefail +print_usage() { + printf "Usage: build [OPTIONS] + + Build avalanchego + + Options: + + -r Build with race detector +" +} + +race='' +while getopts 'r' flag; do + case "${flag}" in + r) race='-r' ;; + *) print_usage + exit 1 ;; + esac +done + # Avalanchego root folder AVALANCHE_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd ) # Load the versions @@ -15,11 +35,13 @@ source "$AVALANCHE_PATH"/scripts/constants.sh echo "Downloading dependencies..." go mod download +build_args="$race" + # Build avalanchego -"$AVALANCHE_PATH"/scripts/build_avalanche.sh +"$AVALANCHE_PATH"/scripts/build_avalanche.sh $build_args # Build coreth -"$AVALANCHE_PATH"/scripts/build_coreth.sh +"$AVALANCHE_PATH"/scripts/build_coreth.sh $build_args # Exit build successfully if the binaries are created if [[ -f "$avalanchego_path" && -f "$evm_path" ]]; then diff --git a/scripts/build_avalanche.sh b/scripts/build_avalanche.sh index fbd7ba1cf9c3..1d7947595d73 100755 --- a/scripts/build_avalanche.sh +++ b/scripts/build_avalanche.sh @@ -4,6 +4,26 @@ set -o errexit set -o nounset set -o pipefail +print_usage() { + printf "Usage: build_avalanche [OPTIONS] + + Build avalanchego + + Options: + + -r Build with race detector +" +} + +race='' +while getopts 'r' flag; do + case "${flag}" in + r) race='-race' ;; + *) print_usage + exit 1 ;; + esac +done + # Changes to the minimum golang version must also be replicated in # scripts/build_avalanche.sh (here) # scripts/local.Dockerfile @@ -40,5 +60,6 @@ source "$AVALANCHE_PATH"/scripts/versions.sh # Load the constants source "$AVALANCHE_PATH"/scripts/constants.sh +build_args="$race" echo "Building AvalancheGo..." -go build -ldflags "-X github.com/ava-labs/avalanchego/version.GitCommit=$git_commit $static_ld_flags" -o "$avalanchego_path" "$AVALANCHE_PATH/main/"*.go +go build $build_args -ldflags "-X github.com/ava-labs/avalanchego/version.GitCommit=$git_commit $static_ld_flags" -o "$avalanchego_path" "$AVALANCHE_PATH/main/"*.go diff --git a/scripts/build_coreth.sh b/scripts/build_coreth.sh index 453b0b1b23c0..19dbbeb04322 100755 --- a/scripts/build_coreth.sh +++ b/scripts/build_coreth.sh @@ -4,6 +4,10 @@ set -o errexit set -o nounset set -o pipefail +race='' +coreth_path='' +evm_path='' + # Directory above this script AVALANCHE_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd ) @@ -13,23 +17,46 @@ source "$AVALANCHE_PATH"/scripts/versions.sh # Load the constants source "$AVALANCHE_PATH"/scripts/constants.sh -# check if there's args defining different coreth source and build paths -if [[ $# -eq 2 ]]; then - coreth_path=$1 - evm_path=$2 -elif [[ $# -eq 0 ]]; then - if [[ ! -d "$coreth_path" ]]; then - go get "github.com/ava-labs/coreth@$coreth_version" - fi -else - echo "Invalid arguments to build coreth. Requires either no arguments (default) or two arguments to specify coreth directory and location to add binary." - exit 1 +print_usage() { + printf "Usage: build_coreth [OPTIONS] + + Build coreth + + Options: + -r Build with race detector (optional) + -c Coreth path (optional; must be provided with -c) + -e EVM path (optional; must be provided with -e) +" +} + +while getopts 'rc:e:' flag; do + case "${flag}" in + r) race='-race' ;; + c) coreth_path=${OPTARG} ;; + e) evm_path=${OPTARG} ;; + *) print_usage + exit 1 ;; + esac +done + +echo "coreth:"$coreth_path evm:$evm_path"" + +# Sanity-check the user's overrides for coreth path/version if they supplied a flag +if [[ -z $coreth_path ]] || [[ -z $evm_path ]]; then + echo "Invalid arguments to build coreth. Coreth path (-c) must be provided with EVM path (-e)." + print_usage + exit 1 +fi + +if [[ ! -d "$coreth_path" ]]; then + go get "github.com/ava-labs/coreth@$coreth_version" fi # Build Coreth +build_args="$race" echo "Building Coreth @ ${coreth_version} ..." cd "$coreth_path" -go build -ldflags "-X github.com/ava-labs/coreth/plugin/evm.Version=$coreth_version $static_ld_flags" -o "$evm_path" "plugin/"*.go +go build $build_args -ldflags "-X github.com/ava-labs/coreth/plugin/evm.Version=$coreth_version $static_ld_flags" -o "$evm_path" "plugin/"*.go cd "$AVALANCHE_PATH" # Building coreth + using go get can mess with the go.mod file. diff --git a/scripts/local.Dockerfile b/scripts/local.Dockerfile index 6f65bb62964d..dd213a50d2a5 100644 --- a/scripts/local.Dockerfile +++ b/scripts/local.Dockerfile @@ -19,6 +19,6 @@ COPY coreth coreth WORKDIR $GOPATH/src/github.com/ava-labs/avalanchego RUN ./scripts/build_avalanche.sh -RUN ./scripts/build_coreth.sh ../coreth $PWD/build/plugins/evm +RUN ./scripts/build_coreth.sh -c ../coreth -e $PWD/build/plugins/evm RUN ln -sv $GOPATH/src/github.com/ava-labs/avalanche-byzantine/ /avalanchego diff --git a/scripts/tests.e2e.sh b/scripts/tests.e2e.sh index 1cadd894daf9..b8db439ee334 100755 --- a/scripts/tests.e2e.sh +++ b/scripts/tests.e2e.sh @@ -71,7 +71,7 @@ echo "launch avalanche-network-runner in the background" server \ --log-level debug \ --port=":12342" \ ---disable-grpc-gateway 2> /dev/null & +--disable-grpc-gateway & PID=${!} #################################