| 1 | package thintest |
| 2 | |
| 3 | import ( |
| 4 | "strings" |
| 5 | "testing" |
| 6 | |
| 7 | "amadan.net/oficina/equipo/internal/wire" |
| 8 | ) |
| 9 | |
| 10 | // TestShellUnavailableRoundIsFree (stopped-jobs audit, fix 4): a fix |
| 11 | // round the engineer ran without a working shell (the runner reports it |
| 12 | // done with shell_unavailable) does not count against the task's two |
| 13 | // automatic rounds; at most two such rounds are free. The next round is |
| 14 | // still told it is round 1 of 2. |
| 15 | func TestShellUnavailableRoundIsFree(t *testing.T) { |
| 16 | for _, free := range []int{0, 1, 3} { |
| 17 | r := newToolRigAt(t, wire.ProtocolCurrent) |
| 18 | base := strings.Repeat("1", 40) |
| 19 | sha := func(n int) string { return strings.Repeat(string(rune('2'+n)), 40) } |
| 20 | id, _ := r.pushed("f", "Add project rename control", base, sha(0)) |
| 21 | task := r.task(id) |
| 22 | r.expect(wire.FrameWatchMerge) |
| 23 | rounds := 0 |
| 24 | for n := 0; ; n++ { |
| 25 | c := r.dispatched(wire.SpecialistChecks, base, sha(n), n) |
| 26 | r.step("f-c"+itoa(n), hostedReport(c, task.Branch, wire.HostedFailure, "compile")) |
| 27 | if r.task(id).NeedsYou == wire.NeedsFixRounds { |
| 28 | break |
| 29 | } |
| 30 | fix := r.dispatched(wire.SpecialistEngineering, sha(n), "", n+1) |
| 31 | reason := "" |
| 32 | if n < free { |
| 33 | reason = "shell_unavailable" |
| 34 | } |
| 35 | counted := n + 1 - min(n, free, wire.MaxFixRounds) |
| 36 | if want := "Fix round " + itoa(counted) + " of 2."; !strings.Contains(fix.Feedback, want) { |
| 37 | t.Fatalf("free %d, round %d: feedback lacks %q: %q", free, n+1, want, fix.Feedback) |
| 38 | } |
| 39 | r.step("f-e"+itoa(n), wire.StepReport{TaskID: id, StepID: fix.StepID, Attempt: 1, State: wire.StepDone, Reason: reason, BaseSHA: sha(n), CandidateSHA: sha(n + 1), Pushed: true, Termination: true}) |
| 40 | r.expect(wire.FrameWatchMerge) |
| 41 | rounds++ |
| 42 | } |
| 43 | if want := wire.MaxFixRounds + min(free, wire.MaxFixRounds); rounds != want { |
| 44 | t.Fatalf("free %d: %d automatic rounds, want %d", free, rounds, want) |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | // shell_unavailable is a done step's reason only: a step that stopped |
| 50 | // with it is recorded as stopped for an unknown reason. |
| 51 | func TestShellUnavailableOnlyOnDone(t *testing.T) { |
| 52 | r := newToolRigAt(t, wire.ProtocolCurrent) |
| 53 | id, d := r.started("x", "Stopped oddly") |
| 54 | r.stop("x", d, wire.ReasonShellUnavailable) |
| 55 | if s := r.task(id).Steps[0]; s.State != wire.StepFailed || s.Reason != wire.ReasonUnknown { |
| 56 | t.Fatalf("step %+v", s) |
| 57 | } |
| 58 | } |
| 59 | |