Skip to content

Commit

Permalink
tools/bin: simplify test commands
Browse files Browse the repository at this point in the history
  • Loading branch information
jmank88 committed Oct 15, 2024
1 parent 03df898 commit 3f1cf07
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 162 deletions.
98 changes: 0 additions & 98 deletions .github/workflows/ci-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,23 +179,13 @@ jobs:
run: |
echo "TIMEOUT=10m" >> $GITHUB_ENV
echo "COUNT=50" >> $GITHUB_ENV
- name: Install gotestloghelper
if: ${{ needs.filter.outputs.changes == 'true' }}
run: go install github.com/smartcontractkit/chainlink-testing-framework/tools/[email protected]
- name: Run tests
if: ${{ needs.filter.outputs.changes == 'true' }}
id: run-tests
env:
OUTPUT_FILE: ./output.txt
USE_TEE: false
CL_DATABASE_URL: ${{ env.DB_URL }}
run: ./tools/bin/${{ matrix.type.cmd }} ./...
- name: Print Filtered Test Results
if: ${{ failure() && needs.filter.outputs.changes == 'true' && steps.run-tests.conclusion == 'failure' }}
run: |
if [[ "${{ matrix.type.printResults }}" == "true" ]]; then
cat output.txt | gotestloghelper -ci
fi
- name: Print Races
id: print-races
if: ${{ failure() && matrix.type.cmd == 'go_core_race_tests' && needs.filter.outputs.changes == 'true' }}
Expand Down Expand Up @@ -243,94 +233,6 @@ jobs:
echo "path_output=${resultsFile}" >> $GITHUB_OUTPUT
fi
detect-flakey-tests:
needs: [filter, core]
name: Flakey Test Detection
runs-on: ubuntu-latest
if: ${{ always() && github.actor != 'dependabot[bot]' }}
env:
CL_DATABASE_URL: postgresql://postgres:postgres@localhost:5432/chainlink_test?sslmode=disable
permissions:
id-token: write
contents: read
steps:
- name: Checkout the repo
uses: actions/[email protected]
- name: Setup node
if: ${{ needs.filter.outputs.changes == 'true' }}
uses: actions/[email protected]
- name: Setup NodeJS
if: ${{ needs.filter.outputs.changes == 'true' }}
uses: ./.github/actions/setup-nodejs
with:
prod: "true"
- name: Setup Go
if: ${{ needs.filter.outputs.changes == 'true' }}
uses: ./.github/actions/setup-go
- name: Setup Postgres
if: ${{ needs.filter.outputs.changes == 'true' }}
uses: ./.github/actions/setup-postgres
- name: Touching core/web/assets/index.html
if: ${{ needs.filter.outputs.changes == 'true' }}
run: mkdir -p core/web/assets && touch core/web/assets/index.html
- name: Download Go vendor packages
if: ${{ needs.filter.outputs.changes == 'true' }}
run: go mod download
- name: Replace chainlink-evm deps
if: ${{ needs.filter.outputs.changes == 'true' && inputs.evm-ref != ''}}
shell: bash
run: go get github.com/smartcontractkit/chainlink-integrations/evm/relayer@${{ inputs.evm-ref }}
- name: Build binary
if: ${{ needs.filter.outputs.changes == 'true' }}
run: go build -o chainlink.test .
- name: Setup DB
if: ${{ needs.filter.outputs.changes == 'true' }}
run: ./chainlink.test local db preparetest
- name: Load test outputs
if: ${{ needs.filter.outputs.changes == 'true' }}
uses: actions/[email protected]
with:
name: go_core_tests_logs
path: ./artifacts
- name: Delete go_core_tests_logs/coverage.txt
if: ${{ needs.filter.outputs.changes == 'true' }}
shell: bash
run: |
# Need to delete coverage.txt so the disk doesn't fill up
rm -f ./artifacts/go_core_tests_logs/coverage.txt
- name: Build flakey test runner
if: ${{ needs.filter.outputs.changes == 'true' }}
run: go build ./tools/flakeytests/cmd/runner
- name: Re-run tests
if: ${{ needs.filter.outputs.changes == 'true' }}
env:
GRAFANA_INTERNAL_BASIC_AUTH: ${{ secrets.GRAFANA_INTERNAL_BASIC_AUTH }}
GRAFANA_INTERNAL_HOST: ${{ secrets.GRAFANA_INTERNAL_HOST }}
GRAFANA_INTERNAL_TENANT_ID: ${{ secrets.GRAFANA_INTERNAL_TENANT_ID }}
GITHUB_EVENT_PATH: ${{ github.event_path }}
GITHUB_EVENT_NAME: ${{ github.event_name }}
GITHUB_REPO: ${{ github.repository }}
GITHUB_RUN_ID: ${{ github.run_id }}
run: |
./runner \
-grafana_auth=$GRAFANA_INTERNAL_BASIC_AUTH \
-grafana_host=$GRAFANA_INTERNAL_HOST \
-grafana_org_id=$GRAFANA_INTERNAL_TENANT_ID \
-gh_sha=$GITHUB_SHA \
-gh_event_path=$GITHUB_EVENT_PATH \
-gh_event_name=$GITHUB_EVENT_NAME \
-gh_run_id=$GITHUB_RUN_ID \
-gh_repo=$GITHUB_REPO \
-command=./tools/bin/go_core_tests \
`ls -R ./artifacts/output.txt`
- name: Store logs artifacts
if: ${{ needs.filter.outputs.changes == 'true' && always() }}
uses: actions/[email protected]
with:
name: flakey_test_runner_logs
path: |
./output.txt
scan:
name: SonarQube Scan
needs: [core]
Expand Down
2 changes: 1 addition & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ modgraph:

.PHONY: test-short
test-short: ## Run 'go test -short' and suppress uninteresting output
go test -short ./... | grep -v "no test files" | grep -v "\(cached\)"
go test -short ./... | grep -v "\[no test files\]" | grep -v "\(cached\)"

help:
@echo ""
Expand Down
15 changes: 2 additions & 13 deletions core/internal/testutils/testutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
// NOTE: To avoid circular dependencies, this package MUST NOT import
// anything from "github.com/smartcontractkit/chainlink/v2/core"
"github.com/smartcontractkit/chainlink-common/pkg/sqlutil"
"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"
)

const (
Expand Down Expand Up @@ -125,19 +126,7 @@ func WaitTimeout(t *testing.T) time.Duration {

// Context returns a context with the test's deadline, if available.
func Context(tb testing.TB) context.Context {
ctx := context.Background()
var cancel func()
switch t := tb.(type) {
case *testing.T:
if d, ok := t.Deadline(); ok {
ctx, cancel = context.WithDeadline(ctx, d)
}
}
if cancel == nil {
ctx, cancel = context.WithCancel(ctx)
}
tb.Cleanup(cancel)
return ctx
return tests.Context(tb)
}

// MustParseURL parses the URL or fails the test
Expand Down
15 changes: 2 additions & 13 deletions integration-tests/deployment/ccip/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/pkg/errors"
"golang.org/x/sync/errgroup"

"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"
"github.com/smartcontractkit/chainlink-testing-framework/lib/blockchain"

"github.com/smartcontractkit/chainlink-ccip/pluginconfig"
Expand Down Expand Up @@ -50,19 +51,7 @@ const (

// Context returns a context with the test's deadline, if available.
func Context(tb testing.TB) context.Context {
ctx := context.Background()
var cancel func()
switch t := tb.(type) {
case *testing.T:
if d, ok := t.Deadline(); ok {
ctx, cancel = context.WithDeadline(ctx, d)
}
}
if cancel == nil {
ctx, cancel = context.WithCancel(ctx)
}
tb.Cleanup(cancel)
return ctx
return tests.Context(tb)
}

type DeployedEnv struct {
Expand Down
15 changes: 2 additions & 13 deletions integration-tests/deployment/memory/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/smartcontractkit/chainlink-common/pkg/config"
"github.com/smartcontractkit/chainlink-common/pkg/loop"
"github.com/smartcontractkit/chainlink-common/pkg/utils/mailbox"
"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"

"github.com/smartcontractkit/chainlink/integration-tests/deployment"

Expand All @@ -43,19 +44,7 @@ import (
)

func Context(tb testing.TB) context.Context {
ctx := context.Background()
var cancel func()
switch t := tb.(type) {
case *testing.T:
if d, ok := t.Deadline(); ok {
ctx, cancel = context.WithDeadline(ctx, d)
}
}
if cancel == nil {
ctx, cancel = context.WithCancel(ctx)
}
tb.Cleanup(cancel)
return ctx
return tests.Context(tb)
}

type Node struct {
Expand Down
13 changes: 1 addition & 12 deletions tools/bin/go_core_race_tests
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,7 @@ USE_TEE="${USE_TEE:-true}"
TIMEOUT="${TIMEOUT:-30s}"
COUNT="${COUNT:-10}"

# To allow reuse in CI from other repositories
TOOLS_PATH=${TOOLS_PATH:-"./tools"}

GO_LDFLAGS=$(bash ${TOOLS_PATH}/bin/ldflags)
use_tee() {
if [ "$USE_TEE" = "true" ]; then
tee "$@"
else
cat > "$@"
fi
}
GORACE="log_path=$PWD/race" go test -json -race -ldflags "$GO_LDFLAGS" -shuffle on -timeout "$TIMEOUT" -count "$COUNT" $1 | use_tee "$OUTPUT_FILE"
GORACE="log_path=$PWD/race" go test -race -shuffle on -timeout "$TIMEOUT" -count "$COUNT" $1 | tee "$OUTPUT_FILE"
EXITCODE=${PIPESTATUS[0]}
# Fail if any race logs are present.
if ls race.* &>/dev/null
Expand Down
14 changes: 2 additions & 12 deletions tools/bin/go_core_tests
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,10 @@ SCRIPT_PATH=`dirname "$0"`; SCRIPT_PATH=`eval "cd \"$SCRIPT_PATH\" && pwd"`
OUTPUT_FILE=${OUTPUT_FILE:-"./output.txt"}
USE_TEE="${USE_TEE:-true}"

# To allow reuse in CI from other repositories
TOOLS_PATH=${TOOLS_PATH:-"./tools"}

echo "Failed tests and panics: ---------------------"
echo ""
GO_LDFLAGS=$(bash ${TOOLS_PATH}/bin/ldflags)
use_tee() {
if [ "$USE_TEE" = "true" ]; then
tee "$@"
else
cat > "$@"
fi
}
go test -json -ldflags "$GO_LDFLAGS" -tags integration $TEST_FLAGS -covermode=atomic -coverpkg=./... -coverprofile=coverage.txt $1 | use_tee $OUTPUT_FILE

go test $TEST_FLAGS $1 | grep -v "\[no test files\]" | tee $OUTPUT_FILE
EXITCODE=${PIPESTATUS[0]}

# Assert no known sensitive strings present in test logger output
Expand Down

0 comments on commit 3f1cf07

Please sign in to comment.