| index 8046b1c29..298622c99 100644 |
| --- a/internal/activator/hawake_test.go |
| +++ b/internal/activator/hawake_test.go |
| @@ -1050,6 +1050,8 @@ func TestHASpawnRefusedAfterLayoutChange(t *testing.T) { |
| // the wake before anything is moved, restored or replicated. |
| func TestSetAsideFailsWhenLitestreamStateCannotBeRemoved(t *testing.T) { |
| ctx := context.Background() |
| + orig := removeTreeBeneath |
| + t.Cleanup(func() { removeTreeBeneath = orig }) |
| for _, meta := range []func(db string) string{ |
| func(db string) string { |
| return filepath.Join(filepath.Dir(db), ".activator-"+filepath.Base(db)+"-litestream") |
| @@ -1060,15 +1062,19 @@ func TestSetAsideFailsWhenLitestreamStateCannotBeRemoved(t *testing.T) { |
| l1 := haFixOf(b).lifetime |
| writeDBAndRecord(t, b, rt, hafresh.Marker{V: 1, Box: "a", IID: "i-a", Lifetime: l1, TXID: 5, Clean: true}) |
| dir := meta(dbPathOf(b, rt)) |
| - // Deeper than the checked removal descends (64): it refuses, as |
| - // a directory it cannot write would, for any user, root included. |
| - deep := dir |
| - for range 66 { |
| - deep = filepath.Join(deep, "d") |
| - } |
| - if err := os.MkdirAll(deep, 0o700); err != nil { |
| + if err := os.MkdirAll(filepath.Join(dir, "d"), 0o700); err != nil { |
| t.Fatal(err) |
| } |
| + // The removal refuses this tree, as it would one it cannot write, |
| + // for any user, root included. (A tree past 64 levels stood in for |
| + // that until the removal took any depth, F6.) |
| + prev := removeTreeBeneath |
| + removeTreeBeneath = func(d, name string) error { |
| + if name == filepath.Base(dir) { |
| + return errors.New("injected: cannot remove") |
| + } |
| + return prev(d, name) |
| + } |
| putLockFor(t, b, rt, markerBody(t, "b", "i-b", l1, 6, true)) |
| l, err := b.Acquire(ctx, rt) |
| if err != nil { |
| @@ -1078,6 +1084,7 @@ func TestSetAsideFailsWhenLitestreamStateCannotBeRemoved(t *testing.T) { |
| if _, err := b.Restore(ctx, rt); err == nil { |
| t.Fatalf("%s: the wake went on over litestream state it could not remove", filepath.Base(dir)) |
| } |
| + removeTreeBeneath = prev |
| if restoreCalls(b) != 0 || !exists(dbPathOf(b, rt)) || exists(dbPathOf(b, rt)+".stale") { |
| t.Fatalf("%s: the copy was moved or restored over (%d restores)", filepath.Base(dir), restoreCalls(b)) |
| } |