Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore] Fix false positive when running tests in the root-level direc… #10648

Merged
merged 2 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions tools/flakeytests/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ func NewRunner(readers []io.Reader, reporter reporter, numReruns int) *Runner {
}

func runGoTest(pkg string, tests []string, numReruns int, w io.Writer) error {
pkg = strings.Replace(pkg, "github.com/smartcontractkit/chainlink/v2", "", -1)
testFilter := strings.Join(tests, "|")
cmd := exec.Command("./tools/bin/go_core_tests", fmt.Sprintf("./%s", pkg)) //#nosec
cmd := exec.Command("./tools/bin/go_core_tests", fmt.Sprintf(".%s", pkg)) //#nosec
cmd.Env = append(os.Environ(), fmt.Sprintf("TEST_FLAGS=-count %d -run %s", numReruns, testFilter))
cmd.Stdout = io.MultiWriter(os.Stdout, w)
cmd.Stderr = io.MultiWriter(os.Stderr, w)
Expand All @@ -65,13 +66,7 @@ type TestEvent struct {
func newEvent(b []byte) (*TestEvent, error) {
e := &TestEvent{}
err := json.Unmarshal(b, e)
if err != nil {
return nil, err
}

e.Package = strings.Replace(e.Package, "github.com/smartcontractkit/chainlink/v2/", "", -1)
return e, nil

return e, err
}

func parseOutput(readers ...io.Reader) (map[string]map[string]int, error) {
Expand Down
43 changes: 32 additions & 11 deletions tools/flakeytests/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func TestParser(t *testing.T) {
require.NoError(t, err)

assert.Len(t, ts, 1)
assert.Len(t, ts["core/assets"], 1)
assert.Equal(t, ts["core/assets"]["TestLink"], 1)
assert.Len(t, ts["github.com/smartcontractkit/chainlink/v2/core/assets"], 1)
assert.Equal(t, ts["github.com/smartcontractkit/chainlink/v2/core/assets"]["TestLink"], 1)
}

func TestParser_SkipsNonJSON(t *testing.T) {
Expand All @@ -46,8 +46,8 @@ func TestParser_SkipsNonJSON(t *testing.T) {
require.NoError(t, err)

assert.Len(t, ts, 1)
assert.Len(t, ts["core/assets"], 1)
assert.Equal(t, ts["core/assets"]["TestLink"], 1)
assert.Len(t, ts["github.com/smartcontractkit/chainlink/v2/core/assets"], 1)
assert.Equal(t, ts["github.com/smartcontractkit/chainlink/v2/core/assets"]["TestLink"], 1)
}

func TestParser_PanicDueToLogging(t *testing.T) {
Expand All @@ -60,8 +60,8 @@ func TestParser_PanicDueToLogging(t *testing.T) {
require.NoError(t, err)

assert.Len(t, ts, 1)
assert.Len(t, ts["core/assets"], 1)
assert.Equal(t, ts["core/assets"]["TestAssets_LinkScanValue"], 1)
assert.Len(t, ts["github.com/smartcontractkit/chainlink/v2/core/assets"], 1)
assert.Equal(t, ts["github.com/smartcontractkit/chainlink/v2/core/assets"]["TestAssets_LinkScanValue"], 1)
}

func TestParser_SuccessfulOutput(t *testing.T) {
Expand Down Expand Up @@ -105,7 +105,7 @@ func TestRunner_WithFlake(t *testing.T) {
err := r.Run()
require.NoError(t, err)
assert.Len(t, m.entries, 1)
assert.Equal(t, m.entries["core/assets"], []string{"TestLink"})
assert.Equal(t, m.entries["github.com/smartcontractkit/chainlink/v2/core/assets"], []string{"TestLink"})
}

func TestRunner_WithFailedPackage(t *testing.T) {
Expand All @@ -130,7 +130,7 @@ func TestRunner_WithFailedPackage(t *testing.T) {
err := r.Run()
require.NoError(t, err)
assert.Len(t, m.entries, 1)
assert.Equal(t, m.entries["core/assets"], []string{"TestLink"})
assert.Equal(t, m.entries["github.com/smartcontractkit/chainlink/v2/core/assets"], []string{"TestLink"})
}

func TestRunner_AllFailures(t *testing.T) {
Expand Down Expand Up @@ -178,7 +178,28 @@ func TestRunner_RerunSuccessful(t *testing.T) {

err := r.Run()
require.NoError(t, err)
assert.Equal(t, m.entries["core/assets"], []string{"TestLink"})
assert.Equal(t, m.entries["github.com/smartcontractkit/chainlink/v2/core/assets"], []string{"TestLink"})
}

func TestRunner_RootLevelTest(t *testing.T) {
output := `{"Time":"2023-09-07T15:39:46.378315+01:00","Action":"fail","Package":"github.com/smartcontractkit/chainlink/v2/","Test":"TestConfigDocs","Elapsed":0}`

rerunOutput := ``
m := newMockReporter()
r := &Runner{
numReruns: 2,
readers: []io.Reader{strings.NewReader(output)},
runTestFn: func(pkg string, testNames []string, numReruns int, w io.Writer) error {
_, err := w.Write([]byte(rerunOutput))
return err
},
parse: parseOutput,
reporter: m,
}

err := r.Run()
require.NoError(t, err)
assert.Equal(t, m.entries["github.com/smartcontractkit/chainlink/v2/"], []string{"TestConfigDocs"})
}

type exitError struct{}
Expand Down Expand Up @@ -208,7 +229,7 @@ func TestRunner_RerunFailsWithNonzeroExitCode(t *testing.T) {

err := r.Run()
require.NoError(t, err)
assert.Equal(t, m.entries["core/assets"], []string{"TestLink"})
assert.Equal(t, m.entries["github.com/smartcontractkit/chainlink/v2/core/assets"], []string{"TestLink"})
}

func TestRunner_RerunWithNonZeroExitCodeDoesntStopCommand(t *testing.T) {
Expand Down Expand Up @@ -251,5 +272,5 @@ func TestRunner_RerunWithNonZeroExitCodeDoesntStopCommand(t *testing.T) {
require.NoError(t, err)
calls := index
assert.Equal(t, 2, calls)
assert.Equal(t, m.entries["core/assets"], []string{"TestLink"})
assert.Equal(t, m.entries["github.com/smartcontractkit/chainlink/v2/core/assets"], []string{"TestLink"})
}
Loading