From ec4b27c00574c014ce139e421752dc70ef94e5bd Mon Sep 17 00:00:00 2001 From: Aneurin Barker Snook Date: Tue, 1 Dec 2026 18:28:48 +0000 Subject: [PATCH] Scale test time limits under the race detector Co-Authored-By: Claude Sonnet 5.5 --- race_off_test.go | 7 +++++++ race_on_test.go | 7 +++++++ robust_test.go | 6 +++--- 3 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 race_off_test.go create mode 100644 race_on_test.go diff --git a/race_off_test.go b/race_off_test.go new file mode 100644 index 0000000..6d9a736 --- /dev/null +++ b/race_off_test.go @@ -0,0 +1,7 @@ +//go:build !race + +package sfz + +// slowdown is how many times slower tests run than usual, which time limits +// allow for. +const slowdown = 1 diff --git a/race_on_test.go b/race_on_test.go new file mode 100644 index 0000000..99d667c --- /dev/null +++ b/race_on_test.go @@ -0,0 +1,7 @@ +//go:build race + +package sfz + +// slowdown is how many times slower tests run than usual, which time limits +// allow for. +const slowdown = 10 diff --git a/robust_test.go b/robust_test.go index dadb260..27b4677 100644 --- a/robust_test.go +++ b/robust_test.go @@ -25,7 +25,7 @@ func TestDefinesCannotOutgrowLimit(t *testing.T) { if !errors.Is(err, ErrInvalid) { t.Errorf("err %v", err) } - if d := time.Since(start); d > 5*time.Second { + if d := time.Since(start); d > slowdown*5*time.Second { t.Errorf("took %v", d) } } @@ -94,7 +94,7 @@ func TestLexScales(t *testing.T) { if doc.String() != text { t.Errorf("%s: not written back", name) } - if d := time.Since(start); d > 3*time.Second { + if d := time.Since(start); d > slowdown*3*time.Second { t.Errorf("%s: took %v", name, d) } } @@ -318,7 +318,7 @@ func TestBuildVariablesWithAbsoluteSamples(t *testing.T) { }() select { case <-done: - case <-time.After(5 * time.Second): + case <-time.After(slowdown * 5 * time.Second): t.Fatalf("%q: Build didn't return", samples) } }