package thintest import ( "testing" "time" "amadan.net/oficina/equipo/internal/wire" ) // Whole-branch fix 1, #5: an outbound pack declared past the bound (an // older worker, which does not measure it first) fails the step // durably, workspace_too_large with Needs you and Retry, whether the // worker's done came first or not; nothing is published. func TestOutboundPackOversizeIsWorkspaceTooLarge(t *testing.T) { for _, doneFirst := range []bool{true, false} { name := "running" if doneFirst { name = "done first" } t.Run(name, func(t *testing.T) { r := newMacRig(t) w := r.newMacEngineer("Mac A", wire.EngineeringReady) base, cand := sha(1), sha(0xb6) task, d := r.macDispatch(w, "iOS huge commit", base) if !w.lease(d.StepID, d.Attempt) { t.Fatal("start refused") } w.send(wire.FrameStep, wire.StepReport{TaskID: task, StepID: d.StepID, Attempt: d.Attempt, State: wire.StepRunning, CandidateSHA: cand, Phase: wire.OutcomeCommitted, OutcomePhase: wire.OutcomeCommitted, Findings: []wire.Finding{}}) _, body := w.expect(wire.FrameSendPack) h := body.(*wire.SendPackCommand).Transfer if doneFirst { w.send(wire.FrameStep, workerDone(d, cand, wire.OutcomeCommitted)) } big := chunk(h, []byte("PACK huge")) big.Total = wire.MaxTransferChunks + 1 w.send(wire.FrameBlob, big) if !doneFirst { _, body = w.expect(wire.FrameCancelStep) if c := body.(*wire.CancelStepCommand); c.StepID != d.StepID || c.Attempt != d.Attempt { t.Fatalf("cancel %+v", c) } w.send(wire.FrameStep, wire.StepReport{TaskID: task, StepID: d.StepID, Attempt: d.Attempt, State: wire.StepCancelled, Reason: "withdrawn", Termination: true, TerminationKind: wire.TerminationProcessGroup, Findings: []wire.Finding{}}) } s := r.engineeringStep(task) if s.State != wire.StepFailed || s.Reason != wire.ReasonWorkspaceTooLarge || !s.Terminated || s.Pushed || r.needsYou(task) != wire.NeedsRetry { t.Fatalf("oversize %+v needs %q", s, r.needsYou(task)) } r.primary.none(wire.FramePublish, 50*time.Millisecond) if n := r.relayed(r.primary); n != 0 { t.Fatalf("%d chunks reached the primary", n) } // A restart keeps it. r.restartMac(w) if s := r.engineeringStep(task); s.State != wire.StepFailed || s.Reason != wire.ReasonWorkspaceTooLarge || r.needsYou(task) != wire.NeedsRetry { t.Fatalf("after a restart %+v needs %q", s, r.needsYou(task)) } }) } }