Skip to content

Commit 8529a08

Browse files
committed
tests: reduce number of rounds for race tests
As long as we require a minimum number of successes (to verify that the success cases have the right values), it is not necessary to do 50k rounds. With the new resolver for procfs, the increase in syscalls results in the tests taking too long. Signed-off-by: Aleksa Sarai <[email protected]>
1 parent f52dfb2 commit 8529a08

File tree

2 files changed

+56
-12
lines changed

2 files changed

+56
-12
lines changed

lookup_linux_test.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -558,20 +558,34 @@ func TestPartialLookup_RacingRename(t *testing.T) {
558558
go doRenameExchangeLoop(pauseCh, exitCh, rootDir, test.subPathA, test.subPathB)
559559

560560
// Do several runs to try to catch bugs.
561-
const testRuns = 50000
561+
const (
562+
testRuns = 3000
563+
minPassCount = 10
564+
)
562565
m := newRacingLookupMeta(pauseCh)
563-
for i := 0; i < testRuns; i++ {
566+
doneRuns := 0
567+
for ; doneRuns < testRuns || m.passOkCount < minPassCount; doneRuns++ {
564568
m.checkPartialLookup(t, rootDir, test.unsafePath, test.skipErrs, test.allowedResults)
569+
// Make sure we don't infinite loop here.
570+
if doneRuns >= 50*testRuns {
571+
break
572+
}
565573
}
566574

567575
pct := func(count int) string {
568-
return fmt.Sprintf("%d(%.3f%%)", count, 100.0*float64(count)/float64(testRuns))
576+
return fmt.Sprintf("%d(%.3f%%)", count, 100.0*float64(count)/float64(doneRuns))
577+
}
578+
579+
// No passing runs is a bit unfortunate, but some of our tests
580+
// can do that and failing here would just lead to flaky tests.
581+
if m.passOkCount == 0 {
582+
t.Logf("WARNING: NO PASSING RUNS!")
569583
}
570584

571585
// Output some stats.
572586
t.Logf("after %d runs: passOk=%s passErr=%s skip=%s fail=%s (+badErr=%s)",
573587
// runs and breakdown of path-related (pass, fail) as well as skipped runs
574-
testRuns, pct(m.passOkCount), pct(m.passErrCount), pct(m.skipCount), pct(m.failCount),
588+
doneRuns, pct(m.passOkCount), pct(m.passErrCount), pct(m.skipCount), pct(m.failCount),
575589
// failures due to incorrect errors (rather than bad paths)
576590
pct(m.badErrCount))
577591
t.Logf(" badHandleName=%s fixRemainingPath=%s",

mkdir_linux_test.go

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,13 @@ func TestMkdirAllHandle_RacingRename(t *testing.T) { //nolint:revive // undersco
404404
}(rootCh)
405405

406406
// Do several runs to try to catch bugs.
407-
const testRuns = 2000
407+
const (
408+
testRuns = 800
409+
minPassCount = 10
410+
)
408411
m := newRacingMkdirMeta()
409-
for i := 0; i < testRuns; i++ {
412+
doneRuns := 0
413+
for ; doneRuns < testRuns || m.passOkCount < minPassCount; doneRuns++ {
410414
root := createTree(t, treeSpec...)
411415

412416
rootCh <- root
@@ -417,15 +421,26 @@ func TestMkdirAllHandle_RacingRename(t *testing.T) { //nolint:revive // undersco
417421
// Clean up the root after each run so we don't exhaust all
418422
// space in the tmpfs.
419423
_ = os.RemoveAll(root)
424+
425+
// Make sure we don't infinite loop here.
426+
if doneRuns >= 50*testRuns {
427+
break
428+
}
420429
}
421430

422431
pct := func(count int) string {
423-
return fmt.Sprintf("%d(%.3f%%)", count, 100.0*float64(count)/float64(testRuns))
432+
return fmt.Sprintf("%d(%.3f%%)", count, 100.0*float64(count)/float64(doneRuns))
433+
}
434+
435+
// No passing runs is a bit unfortunate, but some of our tests
436+
// can do that and failing here would just lead to flaky tests.
437+
if m.passOkCount == 0 {
438+
t.Logf("WARNING: NO PASSING RUNS!")
424439
}
425440

426441
// Output some stats.
427442
t.Logf("after %d runs: passOk=%s passErr=%s fail=%s",
428-
testRuns, pct(m.passOkCount), pct(m.passErrCount), pct(m.failCount))
443+
doneRuns, pct(m.passOkCount), pct(m.passErrCount), pct(m.failCount))
429444
if len(m.passErrCounts) > 0 {
430445
t.Logf(" passErr breakdown:")
431446
for err, count := range m.passErrCounts {
@@ -475,9 +490,13 @@ func TestMkdirAllHandle_RacingDelete(t *testing.T) { //nolint:revive // undersco
475490
}(rootCh)
476491

477492
// Do several runs to try to catch bugs.
478-
const testRuns = 2000
493+
const (
494+
testRuns = 800
495+
minPassCount = 10
496+
)
479497
m := newRacingMkdirMeta()
480-
for i := 0; i < testRuns; i++ {
498+
doneRuns := 0
499+
for ; doneRuns < testRuns; doneRuns++ {
481500
root := createTree(t, treeSpec...)
482501

483502
rootCh <- root
@@ -487,15 +506,26 @@ func TestMkdirAllHandle_RacingDelete(t *testing.T) { //nolint:revive // undersco
487506
// Clean up the root after each run so we don't exhaust all
488507
// space in the tmpfs.
489508
_ = os.RemoveAll(root + "/..")
509+
510+
// Make sure we don't infinite loop here.
511+
if doneRuns >= 50*testRuns {
512+
break
513+
}
490514
}
491515

492516
pct := func(count int) string {
493-
return fmt.Sprintf("%d(%.3f%%)", count, 100.0*float64(count)/float64(testRuns))
517+
return fmt.Sprintf("%d(%.3f%%)", count, 100.0*float64(count)/float64(doneRuns))
518+
}
519+
520+
// No passing runs is a bit unfortunate, but some of our tests
521+
// can do that and failing here would just lead to flaky tests.
522+
if m.passOkCount == 0 {
523+
t.Logf("WARNING: NO PASSING RUNS!")
494524
}
495525

496526
// Output some stats.
497527
t.Logf("after %d runs: passOk=%s passErr=%s fail=%s",
498-
testRuns, pct(m.passOkCount), pct(m.passErrCount), pct(m.failCount))
528+
doneRuns, pct(m.passOkCount), pct(m.passErrCount), pct(m.failCount))
499529
if len(m.passErrCounts) > 0 {
500530
t.Logf(" passErr breakdown:")
501531
for err, count := range m.passErrCounts {

0 commit comments

Comments
 (0)