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 14, 2024
1 parent 37f3132 commit 57f47a4
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 67 deletions.
10 changes: 0 additions & 10 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
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
10 changes: 1 addition & 9 deletions tools/bin/go_core_race_tests
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,7 @@ 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
11 changes: 2 additions & 9 deletions tools/bin/go_core_tests
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,8 @@ 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 | tee $OUTPUT_FILE
EXITCODE=${PIPESTATUS[0]}

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

0 comments on commit 57f47a4

Please sign in to comment.