Skip to content

Commit

Permalink
DRY up env var usage to prevent typos
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryNguyen5 committed Apr 28, 2024
1 parent c70a6e4 commit fafd6e9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion tools/flakeytests/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func (r *Runner) runTests(rep *Report) (*Report, error) {

for pkg := range rep.packagePanics {
for i := 0; i < r.numReruns; i++ {
log.Printf("[PACKAGE_PANIC]: Executing test command with parameters: pkg=%s, numReruns=%d currentRun=%d\n", pkg, r.numReruns, i)
log.Printf("[PACKAGE_PANIC]: Executing test command with parameters: pkg=%s, numReruns=%d currentRun=%d\n", pkg, r.numReruns, i)
pr, err := r.runTest(pkg, []string{})
if err != nil {
return report, err
Expand Down
23 changes: 17 additions & 6 deletions tools/flakeytests/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ import (
"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"
)

// This test suite has two sets of tests that are run in two different modes:
// 1. Normal mode: The tests are run as usual. All tests that start with TestSkippedForTests will be skipped.
// There are a set of integration tests that will run this same test suite in integration mode.
// 2. Integration mode: The tests are run with an environment variable set to run the tests that were skipped in normal mode.
// Their output is captured and parsed to check if the flake runner is behaving as expected.
//
// In summary, the first set of tests are executed by the user, and these tests will trigger the second set of tests to run.
var runInIntegrationTestModeEnvKey = "FLAKEY_TEST_RUNNER_RUN_FIXTURE_TEST"
var skipIntegrationTestMode = os.Getenv(runInIntegrationTestModeEnvKey) != "1"
var runInIntegrationTestModeEnv = runInIntegrationTestModeEnvKey + "=1"

type mockReporter struct {
report *Report
}
Expand Down Expand Up @@ -307,7 +318,7 @@ func TestRunner_RerunWithNonZeroExitCodeDoesntStopCommand(t *testing.T) {

// Used for integration tests
func TestSkippedForTests_Subtests(t *testing.T) {
if os.Getenv("FLAKEY_TEST_RUNNER_RUN_FIXTURE_TEST") != "1" {
if skipIntegrationTestMode {
t.Skip()
}

Expand All @@ -322,7 +333,7 @@ func TestSkippedForTests_Subtests(t *testing.T) {

// Used for integration tests
func TestSkippedForTests(t *testing.T) {
if os.Getenv("FLAKEY_TEST_RUNNER_RUN_FIXTURE_TEST") != "1" {
if skipIntegrationTestMode {
t.Skip()
}

Expand All @@ -333,7 +344,7 @@ func TestSkippedForTests(t *testing.T) {

// Used for integration tests
func TestSkippedForTests_Success(t *testing.T) {
if os.Getenv("FLAKEY_TEST_RUNNER_RUN_FIXTURE_TEST") != "1" {
if skipIntegrationTestMode {
t.Skip()
}

Expand All @@ -356,7 +367,7 @@ func TestIntegration_DealsWithSubtests(t *testing.T) {
repo: "github.com/smartcontractkit/chainlink/v2/tools/flakeytests",
command: "../bin/go_core_tests",
overrides: func(cmd *exec.Cmd) {
cmd.Env = append(cmd.Env, "FLAKEY_TESTRUNNER_RUN_FIXTURE_TEST=1")
cmd.Env = append(cmd.Env, runInIntegrationTestModeEnv)
cmd.Stdout = io.Discard
cmd.Stderr = io.Discard
},
Expand Down Expand Up @@ -392,7 +403,7 @@ func TestIntegration_ParsesPanics(t *testing.T) {
repo: "github.com/smartcontractkit/chainlink/v2/tools/flakeytests",
command: "../bin/go_core_tests",
overrides: func(cmd *exec.Cmd) {
cmd.Env = append(cmd.Env, "FLAKEY_TESTRUNNER_RUN_FIXTURE_TEST=1")
cmd.Env = append(cmd.Env, runInIntegrationTestModeEnv)
cmd.Stdout = io.Discard
cmd.Stderr = io.Discard
},
Expand Down Expand Up @@ -423,7 +434,7 @@ func TestIntegration(t *testing.T) {
repo: "github.com/smartcontractkit/chainlink/v2/tools/flakeytests",
command: "../bin/go_core_tests",
overrides: func(cmd *exec.Cmd) {
cmd.Env = append(cmd.Env, "FLAKEY_TESTRUNNER_RUN_FIXTURE_TEST=1")
cmd.Env = append(cmd.Env, runInIntegrationTestModeEnv)
cmd.Stdout = io.Discard
cmd.Stderr = io.Discard
},
Expand Down

0 comments on commit fafd6e9

Please sign in to comment.