carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package host
2
3import (
4 "errors"
5 "github.com/carlosframework/platform/internal/hostwrite"
6 "github.com/carlosframework/platform/internal/release"
7 "testing"
8)
9
10func TestPlan14Fix2RecoveryContinuesPastBadAttempt(t *testing.T) {
11 t.Parallel()
12 e, _, u, c, pub := plan14AdoptionFixture(t)
13 u.crashNew = true
14 restart := rootRestartRouteWith(e.root.reg, u, u.opt, func(string) string { return "5s" }, nil, c)
15 crashed := errors.New("crash")
16 func() {
17 defer func() {
18 if recover() != crashed {
19 t.Fatal("missing crash")
20 }
21 }()
22 _ = release.Pass(t.Context(), e.root.reg, e.store, pub, u.opt, func(host string) error { _ = restart(host); panic(crashed) }, release.WithRestartFailurePropagation())
23 }()
24 state, err := c.attempts()
25 if err != nil {
26 t.Fatal(err)
27 }
28 if err := state.Write("0.attempt", []byte("malformed")); err != nil {
29 t.Fatal(err)
30 }
31 if err := recoverRootRestarts(t.Context(), u, u.opt, func(string) string { return "5s" }, c, hostwrite.Config{}); err == nil {
32 t.Fatal("corrupt attempt not reported")
33 }
34 if u.props.MainPID <= 0 || u.exe != release.VersionPath(u.opt, "bab", "v1", "console") {
35 t.Fatal("bad attempt skipped other host recovery")
36 }
37 if err := state.Remove("0.attempt"); err != nil {
38 t.Fatal(err)
39 }
40 state.(*rollbackMemory).failWrite = true
41 if err := recoverRootRestarts(t.Context(), u, u.opt, func(string) string { return "5s" }, c, hostwrite.Config{}); err != nil {
42 t.Fatal("settled attempt rewritten", err)
43 }
44}
45