Skip to content

Commit

Permalink
test: build test binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
erikburt committed Nov 14, 2024
1 parent b805b82 commit 5a602f6
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 0 deletions.
82 changes: 82 additions & 0 deletions .github/workflows/cache-test-binaries.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Test Binary Caching

# Run on key branches to make sure integration is good, otherwise run on all PR's
on:
pull_request:


jobs:

build-test-binaries:
runs-on: ubuntu22.04-32cores-128GB

Check failure on line 11 in .github/workflows/cache-test-binaries.yml

View workflow job for this annotation

GitHub Actions / Validate Workflow Changes

1. This Ubuntu runner is 8-16 more expensive than a base Ubuntu runner. Consider using a smaller Ubuntu runner. (runner-ubuntu / error)
env:
# We explicitly have this env var not be "CL_DATABASE_URL" to avoid having it be used by core related tests
# when they should not be using it, while still allowing us to DRY up the setup
DB_URL: postgresql://postgres:postgres@localhost:5432/chainlink_test?sslmode=disable
steps:
- name: Checkout the repo
uses: actions/[email protected]

- name: Change Modtime of Files (cache optimization)
shell: bash
run: |
find . -type f,d -exec touch -r {} -d '1970-01-01T00:00:01' {} \; || true
- name: Setup Go
uses: ./.github/actions/setup-go
with:
restore-build-cache-only: true
# piggy back on go_core_tests for caching
build-cache-version: 'go_core_tests'

- name: Build Test Binaries
shell: bash
env:
OUTPUT_FILE: ./output.txt
USE_TEE: false
CL_DATABASE_URL: ${{ env.DB_URL }}
run: |
./tools/bin/build-test-binaries
- name: Debug testsout
shell: bash
run: |
ls -lah ./testsout
du -ch ./testsout
build-test-binaries-concurrent:
runs-on: ubuntu22.04-32cores-128GB

Check failure on line 48 in .github/workflows/cache-test-binaries.yml

View workflow job for this annotation

GitHub Actions / Validate Workflow Changes

1. This Ubuntu runner is 8-16 more expensive than a base Ubuntu runner. Consider using a smaller Ubuntu runner. (runner-ubuntu / error)
env:
# We explicitly have this env var not be "CL_DATABASE_URL" to avoid having it be used by core related tests
# when they should not be using it, while still allowing us to DRY up the setup
DB_URL: postgresql://postgres:postgres@localhost:5432/chainlink_test?sslmode=disable
steps:
- name: Checkout the repo
uses: actions/[email protected]

- name: Change Modtime of Files (cache optimization)
shell: bash
run: |
find . -type f,d -exec touch -r {} -d '1970-01-01T00:00:01' {} \; || true
- name: Setup Go
uses: ./.github/actions/setup-go
with:
restore-build-cache-only: true
# piggy back on go_core_tests for caching
build-cache-version: 'go_core_tests'

- name: Build Test Binaries
shell: bash
env:
OUTPUT_FILE: ./output.txt
USE_TEE: false
CL_DATABASE_URL: ${{ env.DB_URL }}
run: |
./tools/bin/build-test-binaries-with-concurrency
- name: Debug testsout
shell: bash
run: |
ls -lah ./testsout
du -ch ./testsout
24 changes: 24 additions & 0 deletions tools/bin/build-test-binaries
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

# Directory to store compiled test binaries
mkdir -p testsout

TOOLS_PATH=${TOOLS_PATH:-"./tools"}
GO_LDFLAGS=$(bash ${TOOLS_PATH}/bin/ldflags)

# Find all packages with tests recursively
testable_packages=$(go list ./... | grep -vE '/vendor|/testsout')

# Compile test binaries for each package and handle naming conflicts
for pkg in $testable_packages; do
output_file="testsout/$(echo $pkg | tr '/' '-')-test" # Transform pkg path to a unique filename

# Compile test binary
echo "Compiling test for package $pkg"
go test -c -o "$output_file" -ldflags "$GO_LDFLAGS" -tags integration -vet=off "$pkg"
done

# for binary in testsout/*-test; do
# echo "Running $binary"
# $binary -test.run . || exit 1 # Exit on failure
# done
55 changes: 55 additions & 0 deletions tools/bin/build-test-binaries-with-concurrency
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash

# Directory to store compiled test binaries
mkdir -p testsout

TOOLS_PATH=${TOOLS_PATH:-"./tools"}
GO_LDFLAGS=$(bash ${TOOLS_PATH}/bin/ldflags)

# Find all packages with tests recursively
testable_packages=$(go list ./... | grep -vE '/vendor|/testsout')

# Set the concurrency limits
build_concurrency=4
# run_concurrency=4
build_jobs=0
# run_jobs=0

# Compile test binaries for each package with controlled concurrency
for pkg in $testable_packages; do
output_file="testsout/$(echo $pkg | tr '/' '-')-test" # Transform pkg path to a unique filename

# Compile test binary in the background
echo "Compiling test for package $pkg"
go test -c -o "$output_file" -ldflags "$GO_LDFLAGS" -tags integration -vet=off "$pkg" &

# Increment the build job count
build_jobs=$((build_jobs + 1))

# If we've reached the build concurrency limit, wait for any job to finish
if [[ $build_jobs -ge $build_concurrency ]]; then
wait -n
build_jobs=$((build_jobs - 1))
fi
done

# Wait for all remaining build jobs to complete
wait

# Run all compiled test binaries with controlled concurrency
# for binary in testsout/*-test; do
# echo "Running $binary"
# $binary -test.run . || exit 1 &

# Increment the run job count
# run_jobs=$((run_jobs + 1))

# If we've reached the run concurrency limit, wait for any job to finish
# if [[ $run_jobs -ge $run_concurrency ]]; then
# wait -n
# run_jobs=$((run_jobs - 1))
# fi
# done

# Wait for all remaining run jobs to complete
wait

0 comments on commit 5a602f6

Please sign in to comment.