@@ -25,6 +25,9 @@ import (
2525 "go.ate.dev/substrate/internal/proto/ateworkerpb"
2626)
2727
28+ // testBootID is the boot the tests record and reuse checkpoints on.
29+ const testBootID = "boot-1"
30+
2831func TestRecordAndReuseCheckpoint (t * testing.T ) {
2932 checkpointDir := t .TempDir ()
3033 imgPath := filepath .Join (checkpointDir , "checkpoint.img" )
@@ -34,33 +37,38 @@ func TestRecordAndReuseCheckpoint(t *testing.T) {
3437
3538 // Without a completion marker (e.g. partial files from an interrupted attempt),
3639 // ReuseCheckpoint returns nil.
37- if got := ReuseCheckpoint (checkpointDir , ateworkerpb .SnapshotFidelity_SNAPSHOT_FIDELITY_MEMORY ); got != nil {
40+ if got := ReuseCheckpoint (checkpointDir , testBootID , ateworkerpb .SnapshotFidelity_SNAPSHOT_FIDELITY_MEMORY ); got != nil {
3841 t .Fatalf ("ReuseCheckpoint(before RecordCheckpoint) = %v, want nil" , got )
3942 }
4043
4144 wantResp := & ateworkerpb.CheckpointWorkloadResponse {
4245 SnapshotFiles : []string {"checkpoint.img" },
4346 }
44- if err := RecordCheckpoint (checkpointDir , ateworkerpb .SnapshotFidelity_SNAPSHOT_FIDELITY_MEMORY , wantResp ); err != nil {
47+ if err := RecordCheckpoint (checkpointDir , testBootID , ateworkerpb .SnapshotFidelity_SNAPSHOT_FIDELITY_MEMORY , wantResp ); err != nil {
4548 t .Fatalf ("RecordCheckpoint: %v" , err )
4649 }
4750
4851 // Reusing with matching fidelity and intact file succeeds.
49- got := ReuseCheckpoint (checkpointDir , ateworkerpb .SnapshotFidelity_SNAPSHOT_FIDELITY_MEMORY )
52+ got := ReuseCheckpoint (checkpointDir , testBootID , ateworkerpb .SnapshotFidelity_SNAPSHOT_FIDELITY_MEMORY )
5053 if got == nil || ! slices .Equal (got .GetSnapshotFiles (), wantResp .GetSnapshotFiles ()) {
5154 t .Fatalf ("ReuseCheckpoint() = %v, want %v" , got , wantResp )
5255 }
5356
57+ // A marker recorded before the node rebooted is not reused.
58+ if got := ReuseCheckpoint (checkpointDir , "boot-2" , ateworkerpb .SnapshotFidelity_SNAPSHOT_FIDELITY_MEMORY ); got != nil {
59+ t .Fatalf ("ReuseCheckpoint(another boot) = %v, want nil" , got )
60+ }
61+
5462 // Mismatched fidelity is not reused.
55- if got := ReuseCheckpoint (checkpointDir , ateworkerpb .SnapshotFidelity_SNAPSHOT_FIDELITY_VOLUMES ); got != nil {
63+ if got := ReuseCheckpoint (checkpointDir , testBootID , ateworkerpb .SnapshotFidelity_SNAPSHOT_FIDELITY_VOLUMES ); got != nil {
5664 t .Fatalf ("ReuseCheckpoint(different fidelity) = %v, want nil" , got )
5765 }
5866
59- // Once atelet moves/removes the file from checkpoint-state/, the marker is not reused.
67+ // Once the file is gone from checkpoint-state/, the marker is not reused.
6068 if err := os .Remove (imgPath ); err != nil {
6169 t .Fatal (err )
6270 }
63- if got := ReuseCheckpoint (checkpointDir , ateworkerpb .SnapshotFidelity_SNAPSHOT_FIDELITY_MEMORY ); got != nil {
71+ if got := ReuseCheckpoint (checkpointDir , testBootID , ateworkerpb .SnapshotFidelity_SNAPSHOT_FIDELITY_MEMORY ); got != nil {
6472 t .Fatalf ("ReuseCheckpoint(after file removed) = %v, want nil" , got )
6573 }
6674}
@@ -82,10 +90,10 @@ func TestReuseCheckpointDataSnapshotFilesByFidelity(t *testing.T) {
8290 SnapshotFiles : []string {"checkpoint.img" , "fs/fscheckpoint.pb" , "fs/multitar.img" },
8391 DataSnapshotFiles : []string {"fs/fscheckpoint.pb" , "fs/multitar.img" },
8492 }
85- if err := RecordCheckpoint (checkpointDir , ateworkerpb .SnapshotFidelity_SNAPSHOT_FIDELITY_MEMORY , memResp ); err != nil {
93+ if err := RecordCheckpoint (checkpointDir , testBootID , ateworkerpb .SnapshotFidelity_SNAPSHOT_FIDELITY_MEMORY , memResp ); err != nil {
8694 t .Fatalf ("RecordCheckpoint(MEMORY): %v" , err )
8795 }
88- got := ReuseCheckpoint (checkpointDir , ateworkerpb .SnapshotFidelity_SNAPSHOT_FIDELITY_MEMORY )
96+ got := ReuseCheckpoint (checkpointDir , testBootID , ateworkerpb .SnapshotFidelity_SNAPSHOT_FIDELITY_MEMORY )
8997 if got == nil || ! slices .Equal (got .GetSnapshotFiles (), memResp .GetSnapshotFiles ()) || ! slices .Equal (got .GetDataSnapshotFiles (), memResp .GetDataSnapshotFiles ()) {
9098 t .Fatalf ("ReuseCheckpoint(MEMORY) = %v, want %v" , got , memResp )
9199 }
@@ -95,10 +103,10 @@ func TestReuseCheckpointDataSnapshotFilesByFidelity(t *testing.T) {
95103 SnapshotFiles : []string {"checkpoint.img" },
96104 DataSnapshotFiles : []string {"fs/fscheckpoint.pb" },
97105 }
98- if err := RecordCheckpoint (checkpointDir , ateworkerpb .SnapshotFidelity_SNAPSHOT_FIDELITY_MEMORY , badSubset ); err != nil {
106+ if err := RecordCheckpoint (checkpointDir , testBootID , ateworkerpb .SnapshotFidelity_SNAPSHOT_FIDELITY_MEMORY , badSubset ); err != nil {
99107 t .Fatalf ("RecordCheckpoint(badSubset): %v" , err )
100108 }
101- if got := ReuseCheckpoint (checkpointDir , ateworkerpb .SnapshotFidelity_SNAPSHOT_FIDELITY_MEMORY ); got != nil {
109+ if got := ReuseCheckpoint (checkpointDir , testBootID , ateworkerpb .SnapshotFidelity_SNAPSHOT_FIDELITY_MEMORY ); got != nil {
102110 t .Fatalf ("ReuseCheckpoint(data file not in SnapshotFiles) = %v, want nil" , got )
103111 }
104112
@@ -108,19 +116,19 @@ func TestReuseCheckpointDataSnapshotFilesByFidelity(t *testing.T) {
108116 SnapshotFiles : []string {"fs/multitar.img" , "fs/fscheckpoint.pb" },
109117 DataSnapshotFiles : []string {"fs/fscheckpoint.pb" , "fs/multitar.img" },
110118 }
111- if err := RecordCheckpoint (checkpointDir , ateworkerpb .SnapshotFidelity_SNAPSHOT_FIDELITY_VOLUMES , volResp ); err != nil {
119+ if err := RecordCheckpoint (checkpointDir , testBootID , ateworkerpb .SnapshotFidelity_SNAPSHOT_FIDELITY_VOLUMES , volResp ); err != nil {
112120 t .Fatalf ("RecordCheckpoint(VOLUMES): %v" , err )
113121 }
114- got = ReuseCheckpoint (checkpointDir , ateworkerpb .SnapshotFidelity_SNAPSHOT_FIDELITY_VOLUMES )
122+ got = ReuseCheckpoint (checkpointDir , testBootID , ateworkerpb .SnapshotFidelity_SNAPSHOT_FIDELITY_VOLUMES )
115123 if got == nil || ! slices .Equal (got .GetSnapshotFiles (), volResp .GetSnapshotFiles ()) || ! slices .Equal (got .GetDataSnapshotFiles (), volResp .GetDataSnapshotFiles ()) {
116124 t .Fatalf ("ReuseCheckpoint(VOLUMES) = %v, want %v" , got , volResp )
117125 }
118126
119127 // VOLUMES fidelity rejects non-data files in SnapshotFiles.
120- if err := RecordCheckpoint (checkpointDir , ateworkerpb .SnapshotFidelity_SNAPSHOT_FIDELITY_VOLUMES , memResp ); err != nil {
128+ if err := RecordCheckpoint (checkpointDir , testBootID , ateworkerpb .SnapshotFidelity_SNAPSHOT_FIDELITY_VOLUMES , memResp ); err != nil {
121129 t .Fatalf ("RecordCheckpoint(VOLUMES with non-data files): %v" , err )
122130 }
123- if got := ReuseCheckpoint (checkpointDir , ateworkerpb .SnapshotFidelity_SNAPSHOT_FIDELITY_VOLUMES ); got != nil {
131+ if got := ReuseCheckpoint (checkpointDir , testBootID , ateworkerpb .SnapshotFidelity_SNAPSHOT_FIDELITY_VOLUMES ); got != nil {
124132 t .Fatalf ("ReuseCheckpoint(VOLUMES with non-data files) = %v, want nil" , got )
125133 }
126134}
0 commit comments