test: Hold disk init in DiskOnlyDelayedAttach too
CI / vulncheck (pull_request) Successful in 15s
CI / check-and-test (pull_request) Successful in 41s

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: #36
This commit is contained in:
ash
2026-09-08 15:30:02 +00:00
parent 5e22f1054b
commit 7d8dd6ea6f
+11 -1
View File
@@ -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. // 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). // 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. // 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) { func TestDiskOnlyDelayedAttach(t *testing.T) {
t.Parallel()
td := t.TempDir() td := t.TempDir()
diskPath := filepath.Join(td, "disk") diskPath := filepath.Join(td, "disk")
if err := os.MkdirAll(diskPath, 0755); err != nil { if err := os.MkdirAll(diskPath, 0755); err != nil {
t.Fatal(err) 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) // mem=0, disk>0 -> pure disk delayed path (go func)
sc, err := New("localhost:0", "0", "10MB", diskPath, "", "lru", "lru", 10, 1, "0", nil) 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.Fatalf("New disk-only: %v", err)
} }
t.Cleanup(func() { sc.Shutdown() }) 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) // Immediately in window: no slow tier attached yet -> Create must ErrNotFound (proxy, no disk write)
_, err = sc.vfs.Create("during-init-key", 100) _, 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) t.Errorf("during pending attach, DiskTierReady=%d, want 0", got)
} }
closeHold()
// Wait the barrier (exercises the attach go's Size wait) // Wait the barrier (exercises the attach go's Size wait)
_ = sc.disk.Size() _ = sc.disk.Size()