From 7d8dd6ea6fff74d8fb33e4ffd40225c2f867797d Mon Sep 17 00:00:00 2001 From: ash Date: Tue, 8 Sep 2026 15:30:02 +0000 Subject: [PATCH] test: Hold disk init in DiskOnlyDelayedAttach too Empty-dir attach can finish before the pending DiskTierReady assertion under CI load, same race MixedPendingReady already fixed with RegisterInitHold. Drop t.Parallel and hold the barrier through the pending checks so disk-only stays green. Link: https://git.s1d3sw1ped.com/s1d3sw1ped/steamcache2/issues/36 --- steamcache/steamcache_test.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/steamcache/steamcache_test.go b/steamcache/steamcache_test.go index f2c7e1e..13b5b4d 100644 --- a/steamcache/steamcache_test.go +++ b/steamcache/steamcache_test.go @@ -1040,13 +1040,21 @@ func TestP1_03_EvictionAlgorithmsDistinct(t *testing.T) { // TestDiskOnlyDelayedAttach covers pure disk-only mode (mem=0 + disk>0) hitting the exact delayed attach path. // During init window (pre Size barrier), TieredCache has no slow tier so Create returns ErrNotFound (proxy semantics, no disk caching). // Post-barrier + attach, Create succeeds. Uses real temp dir. +// An init hold keeps the empty-dir attach from finishing before the pending assertions (CI race). func TestDiskOnlyDelayedAttach(t *testing.T) { - t.Parallel() td := t.TempDir() diskPath := filepath.Join(td, "disk") if err := os.MkdirAll(diskPath, 0755); err != nil { t.Fatal(err) } + hold := make(chan struct{}) + var holdOnce sync.Once + closeHold := func() { holdOnce.Do(func() { close(hold) }) } + disk.RegisterInitHold(diskPath, hold) + t.Cleanup(func() { + closeHold() + disk.ClearInitHold(diskPath) + }) // mem=0, disk>0 -> pure disk delayed path (go func) sc, err := New("localhost:0", "0", "10MB", diskPath, "", "lru", "lru", 10, 1, "0", nil) @@ -1054,6 +1062,7 @@ func TestDiskOnlyDelayedAttach(t *testing.T) { t.Fatalf("New disk-only: %v", err) } t.Cleanup(func() { sc.Shutdown() }) + t.Cleanup(closeHold) // before Shutdown: attach is blocked in Size() until the hold closes // Immediately in window: no slow tier attached yet -> Create must ErrNotFound (proxy, no disk write) _, err = sc.vfs.Create("during-init-key", 100) @@ -1067,6 +1076,7 @@ func TestDiskOnlyDelayedAttach(t *testing.T) { t.Errorf("during pending attach, DiskTierReady=%d, want 0", got) } + closeHold() // Wait the barrier (exercises the attach go's Size wait) _ = sc.disk.Size()