TestVFSFile_Hydration_Basic tests that hydration completes and reads from local file.
(t *testing.T)
| 1047 | |
| 1048 | // TestVFSFile_Hydration_Basic tests that hydration completes and reads from local file. |
| 1049 | func 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. |
| 1095 | func TestVFSFile_Hydration_ReadsDuringHydration(t *testing.T) { |
nothing calls this directly
no test coverage detected