oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package wire_test
2
3import (
4 "bytes"
5 "testing"
6
7 "amadan.net/oficina/equipo/internal/wire"
8)
9
10// A timed-out step's pushed work (done, step_timeout) reaches an instance
11// at ProtocolUnfinishedWork as it is, and one below it as the step failing
12// step_timeout with no candidate: an instance that went back to 30 after
13// the report was saved never reads unfinished work as finished. Other
14// reports are unchanged.
15func TestUnfinishedReportDowngrade(t *testing.T) {
16 cand := "2222222222222222222222222222222222222222"
17 unfinished := wire.StepReport{TaskID: "tk1", StepID: "s1", Attempt: 1, State: wire.StepDone, Reason: "step_timeout", CandidateSHA: cand, Pushed: true, Askable: true, Termination: true, Findings: []wire.Finding{}}
18 f, err := wire.NewFrame("r", wire.FrameStep, unfinished)
19 if err != nil {
20 t.Fatal(err)
21 }
22 if same, err := wire.Encode(f, wire.ProtocolUnfinishedWork); err != nil || !bytes.Equal(same.Data, f.Data) {
23 t.Fatalf("at 32: %v %s", err, same.Data)
24 }
25 old, err := wire.Encode(f, wire.ProtocolChangeFiles)
26 if err != nil {
27 t.Fatal(err)
28 }
29 body, err := old.Decode()
30 if err != nil {
31 t.Fatal(err)
32 }
33 if v := body.(*wire.StepReport); v.State != wire.StepFailed || v.Reason != "step_timeout" || v.Pushed || v.CandidateSHA != "" || v.Askable || !v.Termination {
34 t.Fatalf("below 32: %+v", v)
35 }
36 for _, rep := range []wire.StepReport{
37 {TaskID: "tk1", StepID: "s1", Attempt: 1, State: wire.StepDone, CandidateSHA: cand, Pushed: true, Termination: true, Findings: []wire.Finding{}},
38 {TaskID: "tk1", StepID: "s1", Attempt: 1, State: wire.StepDone, Reason: wire.ReasonShellUnavailable, CandidateSHA: cand, Pushed: true, Termination: true, Findings: []wire.Finding{}},
39 {TaskID: "tk1", StepID: "s1", Attempt: 1, State: wire.StepFailed, Reason: "step_timeout", Termination: true, Findings: []wire.Finding{}},
40 } {
41 f, _ := wire.NewFrame("r", wire.FrameStep, rep)
42 if same, err := wire.Encode(f, wire.ProtocolChangeFiles); err != nil || !bytes.Equal(same.Data, f.Data) {
43 t.Fatalf("%+v below 32 changed: %v %s", rep, err, same.Data)
44 }
45 }
46}
47