test: cover open-only geometry and disappearance race

This commit is contained in:
pingqiu committed 2026-11-18 23:38:06 -08:00
1 parent d102a1c1a3
commit 4055e403ea
1 file changed
+49 -1
@@ -3,6 +3,7 @@ package main
import (
"bytes"
"context"
"os"
"path/filepath"
"testing"
"time"
@@ -34,7 +35,14 @@ func TestExistingDurableVolumeIgnoresCreateGeometry(t *testing.T) {
if err != nil {
t.Fatalf("existing storage must ignore create-only geometry: %v", err)
}
p, err := durable.NewDurableProvider(durable.ProviderConfig{Impl: durable.ImplName(f.durableImpl), StorageRoot: f.durableRoot, NumBlocks: uint32(f.durableBlocks), BlockSize: int(f.durableBlockSize)}, healthyView{})
blocks, blockSize, err := durableCreateGeometry(f)
if err != nil {
t.Fatal(err)
}
if blocks != 0 {
t.Fatal("existing file must select open-only mode")
}
p, err := durable.NewDurableProvider(durable.ProviderConfig{Impl: durable.ImplName(f.durableImpl), StorageRoot: f.durableRoot, NumBlocks: blocks, BlockSize: blockSize}, healthyView{})
if err != nil {
t.Fatal(err)
}
@@ -62,3 +70,43 @@ func TestExistingDurableVolumeIgnoresCreateGeometry(t *testing.T) {
t.Fatal("existing bytes changed")
}
}
func TestExistingDurableVolumeDisappearsDoesNotCreateFromIgnoredFlags(t *testing.T) {
root := t.TempDir()
path := filepath.Join(root, "v1.bin")
s, err := storage.CreateWALStore(path, 16, 4096)
if err != nil {
t.Fatal(err)
}
if err = s.Close(); err != nil {
t.Fatal(err)
}
f, err := parseFlags(append(phase150RequiredBlockvolumeArgs(), "--volume-id=v1", "--durable-root="+root, "--durable-impl=walstore", "--durable-blocks=4294967297"))
if err != nil {
t.Fatal(err)
}
blocks, bs, err := durableCreateGeometry(f)
if err != nil {
t.Fatal(err)
}
if blocks != 0 {
t.Fatal("not open-only")
}
if err = os.Remove(path); err != nil {
t.Fatal(err)
}
if _, _, err = durableCreateGeometry(f); err == nil {
t.Fatal("fresh recheck accepted original overflowing count")
}
p, err := durable.NewDurableProvider(durable.ProviderConfig{Impl: durable.ImplWALStore, StorageRoot: root, NumBlocks: blocks, BlockSize: bs}, healthyView{})
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { p.Close() })
if _, err = p.EnsureStorage("v1"); err == nil {
t.Fatal("created replacement from ignored flags")
}
if _, err = os.Stat(path); !os.IsNotExist(err) {
t.Fatalf("replacement file exists: %v", err)
}
}