| index 57257f31e..abcd88902 100644 |
| --- a/internal/release/adopt_test.go |
| +++ b/internal/release/adopt_test.go |
| @@ -3833,3 +3833,59 @@ func TestFirstAdoptionRestartFailureStartsNothing(t *testing.T) { |
| t.Fatal("a build whose restart failed was stamped") |
| } |
| } |
| + |
| +// TestRefusedPromotionIsNeitherStagedNorRelayed: a refusal naming the current |
| +// pointer stops adoptHost before ensureStaged, so the agent never relays a |
| +// root pass for it and nothing restarts. |
| +func TestRefusedPromotionIsNeitherStagedNorRelayed(t *testing.T) { |
| + host := "console.example.com" |
| + ctx, reg, s, pub, opt := startUnitFixture(t, host) |
| + bake := t.TempDir() |
| + ptr, err := Channel(ctx, s, pub, "bab", "console", "canary/x") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := WriteRefusal(bake, Refusal{Host: host, App: "console", Version: ptr.Version, |
| + PointerPromotedAt: ptr.PromotedAt, Reason: "exited: status=2"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + restart := func(h string) error { t.Fatalf("restart consulted for refused %s", h); return nil } |
| + relayed := false |
| + var out bytes.Buffer |
| + withCapturedStdout(t, &out, func() { |
| + if err := Pass(ctx, reg, s, pub, opt, restart, BakeDir(bake), |
| + OnStageBlocked(func(string, string, error) { relayed = true })); err != nil { |
| + t.Fatalf("Pass: %v", err) |
| + } |
| + }) |
| + if v, _ := LiveVersion(opt, host); v != "old" { |
| + t.Fatalf("live = %q, want old", v) |
| + } |
| + if relayed { |
| + t.Fatal("a refused promotion was relayed to root") |
| + } |
| + if !strings.Contains(out.String(), "promote --retry") { |
| + t.Fatalf("printed %q, want the retry hint", out.String()) |
| + } |
| +} |
| + |
| +// TestRePromotionClearsTheBlock: a pointer re-signed for the same version |
| +// (what promote --retry does) is adopted, and the stale record is removed. |
| +func TestRePromotionClearsTheBlock(t *testing.T) { |
| + host := "console.example.com" |
| + ctx, reg, s, pub, opt := startUnitFixture(t, host) |
| + bake := t.TempDir() |
| + if err := WriteRefusal(bake, Refusal{Host: host, App: "console", Version: "new", |
| + PointerPromotedAt: time.Unix(1, 0).UTC(), Reason: "older promotion"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := Pass(ctx, reg, s, pub, opt, func(string) error { return nil }, BakeDir(bake)); err != nil { |
| + t.Fatalf("Pass: %v", err) |
| + } |
| + if v, _ := LiveVersion(opt, host); v != "new" { |
| + t.Fatalf("live = %q, want new (the record names an older promotion)", v) |
| + } |
| + if r, _ := ReadRefusal(bake, host); r != nil { |
| + t.Fatalf("stale refusal survived a successful adoption: %+v", r) |
| + } |
| +} |