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: #36
This commit is contained in:
@@ -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.
|
// 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, "")
|
||||||
@@ -1064,6 +1072,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)
|
||||||
@@ -1077,6 +1086,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()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user