Skip to content

Commit

Permalink
Add race detection to the e2e tests (ava-labs#2299)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshua-kim authored Dec 1, 2022
1 parent d6c7e20 commit 0d8e845
Showing 7 changed files with 89 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run_e2e_tests.sh
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion .github/workflows/test.e2e.yml
Original file line number Diff line number Diff line change
@@ -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
26 changes: 24 additions & 2 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -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
23 changes: 22 additions & 1 deletion scripts/build_avalanche.sh
Original file line number Diff line number Diff line change
@@ -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
51 changes: 39 additions & 12 deletions scripts/build_coreth.sh
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion scripts/local.Dockerfile
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion scripts/tests.e2e.sh
Original file line number Diff line number Diff line change
@@ -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=${!}

#################################

0 comments on commit 0d8e845

Please sign in to comment.