返回 DeepSeek-Reasonix
read_regular_test.go
根目录 / internal / repair / read_regular_test.go
1 package repair
2
3 import (
4 "encoding/json"
5 "io"
6 "os"
7 "testing"
8 )
9
10 func TestPendingUpdateReadHandlePreservesSnapshotAcrossArchive(t *testing.T) {
11 fixture := prepareSupersededUpdateFixture(t, "v1.19.1", "v1.20.0")
12 // Hold the same regular-file handle used by pending transaction readers
13 // throughout a real archival. On Windows this requires delete sharing;
14 // readers keep their old file identity while the path is atomically moved.
15 reader, err := openRepairRegularRead(PendingUpdatePath())
16 if err != nil {
17 t.Fatal(err)
18 }
19 defer reader.Close()
20 archived, err := ArchiveSupersededPendingFileUpdate(fixture.running, fixture.root)
21 if err != nil || !archived {
22 t.Fatalf("archive with active reader: archived=%v err=%v", archived, err)
23 }
24 body, err := io.ReadAll(reader)
25 if err != nil {
26 t.Fatal(err)
27 }
28 var snapshot UpdateTransaction
29 if err := json.Unmarshal(body, &snapshot); err != nil {
30 t.Fatal(err)
31 }
32 if UpdateTransactionID(&snapshot) != UpdateTransactionID(fixture.transaction) {
33 t.Fatal("reader lost the original transaction snapshot after archival")
34 }
35 if _, err := readPendingUpdateUnchecked(); !os.IsNotExist(err) {
36 t.Fatalf("new reader observed an archived pending marker: %v", err)
37 }
38 }
39
39 lines GO