From e3b2b8de1e9b337483fa23a1635117ccd0205b37 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 32c9428..b58e8ab 100644 --- a/steamcache/steamcache_test.go +++ b/steamcache/steamcache_test.go @@ -1050,13 +1050,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, "") @@ -1064,6 +1072,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) @@ -1077,6 +1086,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()