Skip to content

Commit

Permalink
Merge branch 'develop' into feature/re-1696-add-ci-lint-chaincli
Browse files Browse the repository at this point in the history
  • Loading branch information
momentmaker authored Sep 22, 2023
2 parents 821833a + 24bf496 commit 90d1344
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 15 deletions.
5 changes: 2 additions & 3 deletions tools/flakeytests/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -55,15 +55,14 @@ func NewRunner(readers []io.Reader, reporter reporter, numReruns int) *Runner {
type testCommand struct {
command string
repo string
numReruns int
overrides func(*exec.Cmd)
}

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)
Expand Down
62 changes: 50 additions & 12 deletions tools/flakeytests/runner_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package flakeytests

import (
"fmt"
"io"
"os"
"os/exec"
Expand Down Expand Up @@ -317,26 +316,65 @@ 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()
require.NoError(t, err)
_, 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)
}

0 comments on commit 90d1344

Please sign in to comment.