| index 92416516..561a7175 100644 |
| --- a/internal/thintest/mac_publication_contract_test.go |
| +++ b/internal/thintest/mac_publication_contract_test.go |
| @@ -332,9 +332,12 @@ func TestContractPublicationBoundToItsPrimary(t *testing.T) { |
| r.shown(task, base, cand, swipeDiff) |
| } |
| |
| -// Slice F fields read from a runner count only at protocol 37: a worker |
| -// that reconnected below it cannot set the outcome, and a primary below |
| -// it cannot set change files, a diff collection or a publication's diffs. |
| +// Slice F fields read from a runner count only at protocol 37. A worker |
| +// that reconnected below it has its Engineering reports refused whole, |
| +// before anything changes, and unacked: it keeps them in its outbox |
| +// (task 16 holds them there below 37) and they count once it is back at |
| +// 37. A primary below 37 cannot set change files, a diff collection or a |
| +// publication's diffs. |
| func TestContractSliceFFieldsBelow37(t *testing.T) { |
| for _, protocol := range []int{36, wire.ProtocolMacEngineering} { |
| t.Run(itoa(protocol), func(t *testing.T) { |
| @@ -347,30 +350,54 @@ func TestContractSliceFFieldsBelow37(t *testing.T) { |
| } |
| // The worker comes back at protocol. |
| c := r.creds[w.fr] |
| - wh := macEngineerHello(c[1], wire.EngineeringReady, protocol, false) |
| - wh.Generation = w.fr.Welcome.Generation |
| - w.fr.Close() |
| - fr, err := DialRunnerHello(r.ctx, r.inst.URL, c[0], wh) |
| - if err != nil || fr.Welcome.Protocol != protocol { |
| - t.Fatalf("worker at %d: %+v %v", protocol, fr, err) |
| + reconnect := func(protocol int) *peer { |
| + wh := macEngineerHello(c[1], wire.EngineeringReady, protocol, false) |
| + wh.Generation = w.fr.Welcome.Generation |
| + w.fr.Close() |
| + fr, err := DialRunnerHello(r.ctx, r.inst.URL, c[0], wh) |
| + if err != nil || fr.Welcome.Protocol != protocol { |
| + t.Fatalf("worker at %d: %+v %v", protocol, fr, err) |
| + } |
| + t.Cleanup(fr.Close) |
| + r.creds[fr] = c |
| + return &peer{t: t, r: r.toolRig, fr: fr} |
| } |
| - t.Cleanup(fr.Close) |
| - r.creds[fr] = c |
| - w = &peer{t: t, r: r.toolRig, fr: fr} |
| + w = reconnect(protocol) |
| // Raw frames carrying the slice F keys, whatever Encode would do. |
| - w.send(wire.FrameStep, wire.StepReport{TaskID: task, StepID: d.StepID, Attempt: d.Attempt, State: wire.StepRunning, CandidateSHA: cand, Phase: wire.OutcomeCommitted, OutcomePhase: wire.OutcomeUnfinished, XcodeAccess: wire.XcodeAccessSandboxed, SessionID: "sess-1", Findings: []wire.Finding{}}) |
| + committed := wire.StepReport{TaskID: task, StepID: d.StepID, Attempt: d.Attempt, State: wire.StepRunning, CandidateSHA: cand, Phase: wire.OutcomeCommitted, OutcomePhase: wire.OutcomeUnfinished, XcodeAccess: wire.XcodeAccessSandboxed, SessionID: "sess-1", Findings: []wire.Finding{}} |
| + done := workerDone(d, cand, wire.OutcomeUnfinished) |
| + if protocol < wire.ProtocolMacEngineering { |
| + for i, rep := range []wire.StepReport{committed, done} { |
| + if w.sendHeld("held-"+itoa(i), wire.FrameStep, rep) { |
| + t.Fatalf("at %d the worker's Engineering report %d was acked", protocol, i) |
| + } |
| + } |
| + if s := r.engineeringStep(task); s.CandidateSHA != "" || wire.StepTerminal(s.State) || s.Terminated { |
| + t.Fatalf("at %d the step changed: %+v", protocol, s) |
| + } |
| + var n int |
| + if err := r.inst.DB.Writer().QueryRow("SELECT count(*) FROM runner_transfers WHERE step_id = ? AND direction = ?", d.StepID, wire.TransferOutbound).Scan(&n); err != nil || n != 0 { |
| + t.Fatalf("at %d an outbound transfer opened: %d %v", protocol, n, err) |
| + } |
| + w.none(wire.FrameSendPack, 50*time.Millisecond) |
| + // Back at 37, its outbox sends them again. |
| + w = reconnect(wire.ProtocolMacEngineering) |
| + w.sendAs("held-0", wire.FrameStep, committed) |
| + } else { |
| + w.send(wire.FrameStep, committed) |
| + } |
| _, body := w.expect(wire.FrameSendPack) |
| h := body.(*wire.SendPackCommand).Transfer |
| - w.send(wire.FrameStep, workerDone(d, cand, wire.OutcomeUnfinished)) |
| + if protocol < wire.ProtocolMacEngineering { |
| + w.sendAs("held-1", wire.FrameStep, done) |
| + } else { |
| + w.send(wire.FrameStep, done) |
| + } |
| w.send(wire.FrameBlob, chunk(h, []byte("PACK commit"))) |
| r.fromPrimary(wire.FrameBlob) |
| pub := r.fromPrimary(wire.FramePublish).(*wire.PublishCommand) |
| - want := "" |
| - if protocol >= wire.ProtocolMacEngineering { |
| - want = wire.OutcomeUnfinished |
| - } |
| - if pub.OutcomePhase != want { |
| - t.Fatalf("at %d the outcome is %q, want %q", protocol, pub.OutcomePhase, want) |
| + if pub.OutcomePhase != wire.OutcomeUnfinished { |
| + t.Fatalf("at %d the outcome is %q", protocol, pub.OutcomePhase) |
| } |
| // The primary comes back at protocol. |
| ph := primaryHello(r.primary.fr.Welcome.Generation) |
| @@ -387,17 +414,17 @@ func TestContractSliceFFieldsBelow37(t *testing.T) { |
| rows := r.diffRows(d.StepID) |
| r.primary.send(wire.FramePublished, publishedWith(pub, base, swipeDiff)) |
| s := r.task(task).Steps[0] |
| - if !s.Pushed { |
| - t.Fatalf("at %d not published: %+v", protocol, s) |
| + if !s.Pushed || s.Reason != "step_timeout" { |
| + t.Fatalf("at %d not published as unfinished: %+v", protocol, s) |
| } |
| if protocol < wire.ProtocolMacEngineering { |
| - if rows != 0 || s.ChangeFiles != nil || s.Reason == "step_timeout" { |
| - t.Fatalf("at %d slice F fields counted: %d rows, files %+v, reason %q", protocol, rows, s.ChangeFiles, s.Reason) |
| + if rows != 0 || s.ChangeFiles != nil { |
| + t.Fatalf("at %d slice F fields counted: %d rows, files %+v", protocol, rows, s.ChangeFiles) |
| } |
| return |
| } |
| - if rows != 1 || s.Reason != "step_timeout" { |
| - t.Fatalf("at 37: %d rows, reason %q", rows, s.Reason) |
| + if rows != 1 { |
| + t.Fatalf("at 37: %d rows", rows) |
| } |
| r.shown(task, base, cand, swipeDiff) |
| }) |