adopt: refuse a restart success reached after the limit
RestartAndWait checks the limit again once until has answered, so a success whose probe or classification finishes past the deadline is a restart-timeout, not a pass.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 files changed,
+32
−1
adopt/restart.go+10 −1adopt/restart_test.go+22 −0
diff --git a/adopt/restart.go b/adopt/restart.go| index 6775e8a..af41341 100644 |
| --- a/adopt/restart.go |
| +++ b/adopt/restart.go |
| @@ -126,7 +126,16 @@ func RestartAndWait(ctx context.Context, c *carlosop.Client, h *http.Client, app |
| continue |
| } |
| last = d |
| - if reason = until(d); reason == nil { |
| + reason = until(d) |
| + // Accepted only if the limit still holds once until has answered: |
| + // a success reached after the deadline is a timeout. |
| + if poll.Err() != nil { |
| + if reason == nil { |
| + reason = errors.New("adopt: the app came back only after the limit") |
| + } |
| + return stopped() |
| + } |
| + if reason == nil { |
| return d, nil |
| } |
| } |
diff --git a/adopt/restart_test.go b/adopt/restart_test.go| index a5f2b44..13582bc 100644 |
| --- a/adopt/restart_test.go |
| +++ b/adopt/restart_test.go |
| @@ -415,3 +415,25 @@ func (s *site) delivery(t *testing.T, x *carlosFixture) Delivery { |
| } |
| return d |
| } |
| + |
| +// A success that is only reached after the limit does not count: here the |
| +// classification itself finishes past the deadline. |
| +func TestRestartAndWaitRefusesSuccessAfterLimit(t *testing.T) { |
| + fastPolls(t, 10*time.Millisecond, 100*time.Millisecond) |
| + x := newCarlosFixture(t, "docs") |
| + id := x.identity(t) |
| + until := func(Delivery) error { |
| + time.Sleep(200 * time.Millisecond) |
| + return nil |
| + } |
| + _, err := RestartAndWait(context.Background(), x.c, x.h, x.app, id, until, true) |
| + if err == nil || !strings.Contains(err.Error(), "restart-timeout") { |
| + t.Fatalf("err = %v, want restart-timeout for a success after the limit", err) |
| + } |
| + if !strings.Contains(err.Error(), "only after the limit") { |
| + t.Fatalf("err = %v, want it to say the success came after the limit", err) |
| + } |
| + if errors.Is(err, context.DeadlineExceeded) || errors.Is(err, context.Canceled) { |
| + t.Fatalf("err = %v: the limit read as the caller's context", err) |
| + } |
| +} |