MCPcopy
hub / github.com/benbjohnson/litestream / TestVFSFile_Hydration_Basic

Function TestVFSFile_Hydration_Basic

vfs_test.go:1049–1092  ·  view source on GitHub ↗

TestVFSFile_Hydration_Basic tests that hydration completes and reads from local file.

(t *testing.T)

Source from the content-addressed store, hash-verified

1047
1048// TestVFSFile_Hydration_Basic tests that hydration completes and reads from local file.
1049func TestVFSFile_Hydration_Basic(t *testing.T) {
1050 client := newMockReplicaClient()
1051 client.addFixture(t, buildLTXFixture(t, 1, 'a'))
1052
1053 // Create temp directory for hydration
1054 hydrationDir := t.TempDir()
1055
1056 // Create VFSFile with hydration enabled
1057 f := NewVFSFile(client, "test.db", slog.Default())
1058 f.hydrationPath = filepath.Join(hydrationDir, "test.db.hydration.db")
1059 f.PollInterval = 100 * time.Millisecond
1060
1061 if err := f.Open(); err != nil {
1062 t.Fatalf("open vfs file: %v", err)
1063 }
1064 defer f.Close()
1065
1066 // Wait for hydration to complete
1067 deadline := time.Now().Add(5 * time.Second)
1068 for f.hydrator == nil || !f.hydrator.Complete() {
1069 if time.Now().After(deadline) {
1070 t.Fatalf("hydration did not complete in time")
1071 }
1072 time.Sleep(10 * time.Millisecond)
1073 }
1074
1075 // Verify hydration file exists
1076 if _, err := os.Stat(f.hydrationPath); err != nil {
1077 t.Fatalf("hydration file not found: %v", err)
1078 }
1079
1080 // Read a page - should come from hydrated file
1081 buf := make([]byte, 4096)
1082 if _, err := f.ReadAt(buf, 0); err != nil {
1083 t.Fatalf("read at: %v", err)
1084 }
1085
1086 // Check that the data matches (excluding modified header bytes)
1087 for i := 28; i < len(buf); i++ {
1088 if buf[i] != 'a' {
1089 t.Fatalf("expected byte 'a' at position %d, got %q", i, buf[i])
1090 }
1091 }
1092}
1093
1094// TestVFSFile_Hydration_ReadsDuringHydration tests that reads work via cache/remote during hydration.
1095func TestVFSFile_Hydration_ReadsDuringHydration(t *testing.T) {

Callers

nothing calls this directly

Calls 8

OpenMethod · 0.95
CloseMethod · 0.95
ReadAtMethod · 0.95
newMockReplicaClientFunction · 0.85
buildLTXFixtureFunction · 0.85
NewVFSFileFunction · 0.85
addFixtureMethod · 0.80
CompleteMethod · 0.80

Tested by

no test coverage detected