Skip to content

Commit 242e90a

Browse files
committed
Shave 5 seconds off typical test time
1 parent 0d4de74 commit 242e90a

File tree

2 files changed

+35
-16
lines changed

2 files changed

+35
-16
lines changed

tools/flakeguard/runner/runner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ func attributePanicToTest(outputs []string) (test string, timeout bool, err erro
634634
return testName, false, nil
635635
}
636636
}
637-
return "", false, fmt.Errorf("failed to attribute panic to test, using regex %s on these strings:\n\n%s",
637+
return "", false, fmt.Errorf("failed to attribute panic to test, using regex '%s' on these strings:\n\n%s",
638638
testNameRe.String(), strings.Join(outputs, ""))
639639
}
640640

tools/flakeguard/runner/runner_test.go

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ func TestRun(t *testing.T) {
257257

258258
for _, tc := range testCases {
259259
t.Run(tc.name, func(t *testing.T) {
260+
t.Parallel()
261+
260262
testResults, err := tc.runner.RunTestPackages([]string{flakyTestPackagePath})
261263
require.NoError(t, err)
262264

@@ -543,9 +545,36 @@ func TestAttributePanicToTest(t *testing.T) {
543545
},
544546
},
545547
{
546-
name: "no test name in panic",
547-
expectedTestName: "UnknownTestPanic",
548+
name: "empty",
549+
expectedTestName: "",
548550
expectedTimeout: false,
551+
outputs: []string{},
552+
},
553+
}
554+
555+
for _, tc := range testCases {
556+
t.Run(tc.name, func(t *testing.T) {
557+
testName, timeout, err := attributePanicToTest(tc.outputs)
558+
assert.Equal(t, tc.expectedTimeout, timeout, "timeout flag mismatch")
559+
if tc.expectedTestName == "" {
560+
require.Error(t, err)
561+
} else {
562+
require.NoError(t, err)
563+
assert.Equal(t, tc.expectedTestName, testName, "test name mismatch")
564+
}
565+
})
566+
}
567+
}
568+
569+
func TestFailToAttributePanicToTest(t *testing.T) {
570+
t.Parallel()
571+
572+
testCases := []struct {
573+
name string
574+
outputs []string
575+
}{
576+
{
577+
name: "no test name in panic",
549578
outputs: []string{
550579
"panic: reflect: Elem of invalid type bool",
551580
"goroutine 104182 [running]:",
@@ -582,24 +611,14 @@ func TestAttributePanicToTest(t *testing.T) {
582611
"FAIL\tgithub.com/smartcontractkit/chainlink/deployment/ccip/changeset/solana\t184.801s",
583612
},
584613
},
585-
{
586-
name: "empty",
587-
expectedTestName: "",
588-
expectedTimeout: false,
589-
outputs: []string{},
590-
},
591614
}
592615

593616
for _, tc := range testCases {
594617
t.Run(tc.name, func(t *testing.T) {
595618
testName, timeout, err := attributePanicToTest(tc.outputs)
596-
assert.Equal(t, tc.expectedTimeout, timeout, "timeout flag mismatch")
597-
if tc.expectedTestName == "" {
598-
require.Error(t, err)
599-
} else {
600-
require.NoError(t, err)
601-
assert.Equal(t, tc.expectedTestName, testName, "test name mismatch")
602-
}
619+
require.Error(t, err)
620+
assert.Empty(t, testName, "test name should be empty")
621+
assert.False(t, timeout, "timeout flag should be false")
603622
})
604623
}
605624
}

0 commit comments

Comments
 (0)