diff --git a/tools/flakeytests/runner.go b/tools/flakeytests/runner.go index 05c700c9189..d935000222f 100644 --- a/tools/flakeytests/runner.go +++ b/tools/flakeytests/runner.go @@ -41,7 +41,7 @@ func NewRunner(readers []io.Reader, reporter reporter, numReruns int) *Runner { tc := &testCommand{ repo: "github.com/smartcontractkit/chainlink/v2", command: "./tools/bin/go_core_tests", - numReruns: numReruns, + overrides: func(*exec.Cmd) {}, } return &Runner{ readers: readers, @@ -55,7 +55,6 @@ func NewRunner(readers []io.Reader, reporter reporter, numReruns int) *Runner { type testCommand struct { command string repo string - numReruns int overrides func(*exec.Cmd) } @@ -63,7 +62,7 @@ func (t *testCommand) test(pkg string, tests []string, w io.Writer) error { replacedPkg := strings.Replace(pkg, t.repo, "", -1) testFilter := strings.Join(tests, "|") cmd := exec.Command(t.command, fmt.Sprintf(".%s", replacedPkg)) //#nosec - cmd.Env = append(os.Environ(), fmt.Sprintf("TEST_FLAGS=-count=%d -run %s", t.numReruns, testFilter)) + cmd.Env = append(os.Environ(), fmt.Sprintf("TEST_FLAGS=-run %s", testFilter)) cmd.Stdout = io.MultiWriter(os.Stdout, w) cmd.Stderr = io.MultiWriter(os.Stderr, w) t.overrides(cmd) diff --git a/tools/flakeytests/runner_test.go b/tools/flakeytests/runner_test.go index b815c978e6a..8fa81db5ba0 100644 --- a/tools/flakeytests/runner_test.go +++ b/tools/flakeytests/runner_test.go @@ -1,7 +1,6 @@ package flakeytests import ( - "fmt" "io" "os" "os/exec" @@ -317,22 +316,34 @@ 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" { + t.Skip() + } + + assert.True(t, true) +} + func TestParsesPanicCorrectly(t *testing.T) { output := `{"Time":"2023-09-07T15:39:46.378315+01:00","Action":"fail","Package":"github.com/smartcontractkit/chainlink/v2/tools/flakeytests/","Test":"TestSkippedForTests","Elapsed":0}` m := newMockReporter() + tc := &testCommand{ + 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.Stdout = io.Discard + cmd.Stderr = io.Discard + }, + } r := &Runner{ - numReruns: 2, - readers: []io.Reader{strings.NewReader(output)}, - testCommand: testAdapter(func(pkg string, tests []string, w io.Writer) error { - pkg = strings.Replace(pkg, "github.com/smartcontractkit/chainlink/v2/tools/flakeytests", "", -1) - testFilter := strings.Join(tests, "|") - cmd := exec.Command("../bin/go_core_tests", fmt.Sprintf(".%s", pkg)) //#nosec - cmd.Env = append(os.Environ(), "FLAKEY_TESTRUNNER_RUN_FIXTURE_TEST=1", fmt.Sprintf("TEST_FLAGS=-run %s", testFilter)) - return cmd.Run() - }), - parse: parseOutput, - reporter: m, + numReruns: 2, + readers: []io.Reader{strings.NewReader(output)}, + testCommand: tc, + parse: parseOutput, + reporter: m, } err := r.Run() @@ -340,3 +351,30 @@ func TestParsesPanicCorrectly(t *testing.T) { _, ok := m.entries["github.com/smartcontractkit/chainlink/v2/tools/flakeytests"]["TestSkippedForTests"] assert.False(t, ok) } + +func TestIntegration(t *testing.T) { + output := `{"Time":"2023-09-07T15:39:46.378315+01:00","Action":"fail","Package":"github.com/smartcontractkit/chainlink/v2/tools/flakeytests/","Test":"TestSkippedForTests_Success","Elapsed":0}` + + m := newMockReporter() + tc := &testCommand{ + 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.Stdout = io.Discard + cmd.Stderr = io.Discard + }, + } + r := &Runner{ + numReruns: 2, + readers: []io.Reader{strings.NewReader(output)}, + testCommand: tc, + parse: parseOutput, + reporter: m, + } + + err := r.Run() + require.NoError(t, err) + _, ok := m.entries["github.com/smartcontractkit/chainlink/v2/tools/flakeytests"]["TestSkippedForTests_Success"] + assert.False(t, ok) +}