diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-08 11:40:55 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-08 11:40:55 +0200 |
| commit | be5718d6e0de0f7ce3b4b506f389719542a46ea7 (patch) | |
| tree | a9af41a1fb97aeedb619f929e14bd66db091e982 /internal | |
| parent | 534d55c47fc29d1089cb5c2c9c4832461e762603 (diff) | |
tests: remove sleep-based waits in tui and runtime tests
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/ior_mode_test.go | 54 | ||||
| -rw-r--r-- | internal/statsengine/engine_reset_test.go | 1 | ||||
| -rw-r--r-- | internal/tui/tui_test.go | 3 |
3 files changed, 27 insertions, 31 deletions
diff --git a/internal/ior_mode_test.go b/internal/ior_mode_test.go index 48b2c36..6b51985 100644 --- a/internal/ior_mode_test.go +++ b/internal/ior_mode_test.go @@ -6,6 +6,7 @@ import ( "encoding/json" "errors" "testing" + "testing/synctest" "time" "ior/internal/flags" @@ -365,43 +366,38 @@ func TestBuildTestFlamesRuntimeSeedsLiveTrie(t *testing.T) { } func TestBuildTestLiveFlamesRuntimeContinuouslyUpdatesLiveTrie(t *testing.T) { - cfg := flags.NewFlags() - cfg.LiveInterval = 15 * time.Millisecond + synctest.Test(t, func(t *testing.T) { + cfg := flags.NewFlags() + cfg.LiveInterval = 15 * time.Millisecond - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() - _, streamBuf, liveTrie := buildTestLiveFlamesRuntime(ctx, cfg) - if streamBuf == nil { - t.Fatalf("expected stream buffer in test live flames runtime") - } - if liveTrie == nil { - t.Fatalf("expected live trie in test live flames runtime") - } + _, streamBuf, liveTrie := buildTestLiveFlamesRuntime(ctx, cfg) + if streamBuf == nil { + t.Fatalf("expected stream buffer in test live flames runtime") + } + if liveTrie == nil { + t.Fatalf("expected live trie in test live flames runtime") + } - initialVersion := liveTrie.Version() - if initialVersion == 0 { - t.Fatalf("expected seeded live trie version to be non-zero") - } - initialSnapshot, _ := liveTrie.SnapshotJSON() + initialVersion := liveTrie.Version() + if initialVersion == 0 { + t.Fatalf("expected seeded live trie version to be non-zero") + } + initialSnapshot, _ := liveTrie.SnapshotJSON() + + time.Sleep(cfg.LiveInterval + time.Nanosecond) + synctest.Wait() - sawUpdate := false - deadline := time.Now().Add(300 * time.Millisecond) - for time.Now().Before(deadline) { if liveTrie.Version() <= initialVersion { - time.Sleep(10 * time.Millisecond) - continue + t.Fatalf("expected live trie version to advance beyond %d", initialVersion) } currentSnapshot, _ := liveTrie.SnapshotJSON() - if !bytes.Equal(initialSnapshot, currentSnapshot) { - sawUpdate = true - break + if bytes.Equal(initialSnapshot, currentSnapshot) { + t.Fatalf("expected test live flames snapshot shape to change over time") } - time.Sleep(10 * time.Millisecond) - } - if !sawUpdate { - t.Fatalf("expected test live flames snapshot shape to change over time (version > %d)", initialVersion) - } + }) } func TestRunTraceWithContextRequiresRoot(t *testing.T) { diff --git a/internal/statsengine/engine_reset_test.go b/internal/statsengine/engine_reset_test.go index 7a86c86..e798686 100644 --- a/internal/statsengine/engine_reset_test.go +++ b/internal/statsengine/engine_reset_test.go @@ -15,7 +15,6 @@ func TestEngineResetClearsAccumulatedStats(t *testing.T) { t.Fatalf("expected non-zero totals before reset") } - time.Sleep(1 * time.Millisecond) e.Reset() after := e.Snapshot() if after.TotalSyscalls != 0 || after.TotalBytes != 0 || after.TotalErrors != 0 { diff --git a/internal/tui/tui_test.go b/internal/tui/tui_test.go index 82fe9da..85ebb71 100644 --- a/internal/tui/tui_test.go +++ b/internal/tui/tui_test.go @@ -612,7 +612,8 @@ func TestNormalizeKeyEventReleaseFallbackSuppressesImmediatePressOnly(t *testing t.Fatalf("expected immediate matching press to be suppressed, got %T", normalized) } - time.Sleep(70 * time.Millisecond) + // Expire suppression deterministically instead of waiting on wall clock time. + m.suppressPressUntil = time.Now().Add(-time.Nanosecond) if normalized, ok = m.normalizeKeyEvent(tea.KeyPressMsg{Code: tea.KeySpace, Text: " "}); !ok { t.Fatalf("expected press to be accepted after suppression window") } |
