Skip to content

Commit b2e018e

Browse files
authored
Merge pull request #569 from intel-go/gregory/testing
Implemented #382 to repeat failed tests several times
2 parents a8f4031 + 7a615b2 commit b2e018e

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

test/framework/main/tf.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func main() {
2828
flag.StringVar(&configFile, "config", "config.json", "Name of config file to use")
2929
flag.StringVar(&directory, "directory", "", "Use `directory` to output log files instead of timestamp")
3030
flag.BoolVar(&test.NoDeleteContainersOnExit, "nodelete", false, "Do not remove containers after tests finish")
31+
repeatFailed := flag.Int("repeat-failed", 1, "Number of times to repeat a test which failed. This includes tests that timed out.")
3132
flag.Parse()
3233

3334
// Read config
@@ -46,6 +47,6 @@ func main() {
4647
}
4748

4849
// Start test execution
49-
status := config.RunAllTests(directory, tl)
50+
status := config.RunAllTests(directory, tl, *repeatFailed)
5051
os.Exit(status)
5152
}

test/framework/testsuite.go

+28-9
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ func isTestInList(test *TestConfig, tl TestsList) bool {
223223
}
224224

225225
// RunAllTests launches all tests.
226-
func (config *TestsuiteConfig) RunAllTests(logdir string, tl TestsList) int {
226+
func (config *TestsuiteConfig) RunAllTests(logdir string, tl TestsList, repeatCount int) int {
227227
report := StartReport(logdir)
228228
if report == nil {
229229
return 255
@@ -233,19 +233,38 @@ func (config *TestsuiteConfig) RunAllTests(logdir string, tl TestsList) int {
233233
sichan := make(chan os.Signal, 1)
234234
signal.Notify(sichan, os.Interrupt)
235235

236-
var totalTests, passedTests, failedTests []string
236+
type TestInfo struct {
237+
TestName string
238+
Repeated int
239+
}
240+
241+
var totalTests, passedTests, failedTests []TestInfo
242+
237243
for iii := range config.Tests {
238244
test := &config.Tests[iii]
239245

240246
if isTestInList(test, tl) {
241-
tr := config.executeOneTest(test, logdir, sichan)
247+
var tr *TestcaseReportInfo
248+
ti := TestInfo{
249+
TestName: test.Name,
250+
Repeated: 0,
251+
}
252+
253+
for ti.Repeated < repeatCount {
254+
tr = config.executeOneTest(test, logdir, sichan)
255+
ti.Repeated++
256+
if tr.Status == TestReportedPassed || tr.Status == TestInterrupted {
257+
break
258+
}
259+
}
260+
242261
report.AddTestResult(tr)
243262

244-
totalTests = append(totalTests, test.Name)
263+
totalTests = append(totalTests, ti)
245264
if tr.Status == TestReportedPassed {
246-
passedTests = append(passedTests, test.Name)
265+
passedTests = append(passedTests, ti)
247266
} else {
248-
failedTests = append(failedTests, test.Name)
267+
failedTests = append(failedTests, ti)
249268
}
250269

251270
if tr.Status == TestInterrupted {
@@ -256,9 +275,9 @@ func (config *TestsuiteConfig) RunAllTests(logdir string, tl TestsList) int {
256275

257276
report.FinishReport()
258277

259-
LogInfo("EXECUTED TEST NAMES:", totalTests)
260-
LogInfo("PASSED TEST NAMES:", passedTests)
261-
LogInfo("FAILED TEST NAMES:", failedTests)
278+
LogInfo("EXECUTED TEST NAMES AND REPEAT COUNT:", totalTests)
279+
LogInfo("PASSED TEST NAMES AND REPEAT COUNT:", passedTests)
280+
LogInfo("FAILED TEST NAMES AND REPEAT COUNT:", failedTests)
262281
LogInfo("TESTS EXECUTED:", len(totalTests))
263282
LogInfo("PASSED:", len(passedTests))
264283
LogInfo("FAILED:", len(failedTests))

0 commit comments

Comments
 (0)