Download this file
| 1 | package runner |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "errors" |
| 6 | "io" |
| 7 | "net/http" |
| 8 | "strings" |
| 9 | "testing" |
| 10 | "time" |
| 11 | ) |
| 12 | |
| 13 | func TestBudgetRefusalStopsRetry(t *testing.T) { |
| 14 | calls := 0 |
| 15 | c := &HTTPInstance{origin: "https://equipo.example", client: &http.Client{Transport: transportFunc(func(*http.Request) (*http.Response, error) { |
| 16 | calls++ |
| 17 | return &http.Response{StatusCode: 409, Body: io.NopCloser(strings.NewReader(`{"version":2,"error":"runner.budget"}`))}, nil |
| 18 | })}} |
| 19 | ctx, cancel := context.WithTimeout(context.Background(), time.Second) |
| 20 | defer cancel() |
| 21 | err := retryAuthority(ctx, func() error { return c.post(ctx, "admit", struct{}{}, "", nil) }) |
| 22 | var refusal *RefusalError |
| 23 | if calls != 1 || !errors.As(err, &refusal) || refusal.Reason != "runner.budget" { |
| 24 | t.Fatalf("budget retry lost final reason: calls=%d err=%v", calls, err) |
| 25 | } |
| 26 | s, r, _, _, _ := directNamespaceFixture(t) |
| 27 | _ = s.finishAttempt(context.Background(), r, err) |
| 28 | var states []attemptState |
| 29 | wfMust(t, s.journal.readStates(context.Background(), "attempt", &states)) |
| 30 | if len(states) != 1 || states[0].FailureReason != "runner.budget" { |
| 31 | t.Fatal("attempt lost typed budget reason", states) |
| 32 | } |
| 33 | } |
| 34 | |