The build modules' shared steprun parts of §799: again-delays (15s,60s) read into a Puller's Delay; a fetch's 401/5xx or connection fault and a publish's no responders or exited bundle are transport faults whose why opens fetch: or publish:; the assigner call that named a silent holder goes. The builder reads an exited bundle as no responders and keeps the part in a key's fault words. Builds: design 47 H2 §799 (H-A-390)
75 lines
3.5 KiB
Go
75 lines
3.5 KiB
Go
package steprun
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
sdkstep "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
|
|
)
|
|
|
|
// Design 47 H2 §799: a fetch met by a forge's 401 or a connection fault, and a publish met by no responders or a bundle
|
|
// that exited, end their run `again` after again-delays' delay, with no seat call; a third run's fault ends the step failed
|
|
// with the why `fetch: <words>` or `publish: <words>`.
|
|
func TestAFetchOrAPublishMetAwayIsATransportFault(t *testing.T) {
|
|
delay, err := AgainDelays("")
|
|
if err != nil || delay(1) != 15*time.Second || delay(2) != time.Minute || delay(3) != time.Minute {
|
|
t.Fatalf("the default again-delays: %v", err)
|
|
}
|
|
if own, err := AgainDelays("2s, 5s"); err != nil || own(1) != 2*time.Second || own(2) != 5*time.Second {
|
|
t.Errorf("a setting's own again-delays: %v", err)
|
|
}
|
|
if _, err := AgainDelays("15s,soon"); err == nil || !strings.Contains(err.Error(), AgainDelaysSetting) {
|
|
t.Errorf("a delay that is no duration is refused naming the setting: %v", err)
|
|
}
|
|
for _, tc := range []struct {
|
|
name, why string
|
|
err error
|
|
}{
|
|
{"a fetch met by a 401", "fetch: ", gitFailure("fetch", "fatal: unable to access the forge: The requested URL returned error: 401")},
|
|
{"a fetch met by a 503", "fetch: ", gitFailure("fetch", "remote: HTTP 503 store unavailable")},
|
|
{"a fetch met by a reset connection", "fetch: ", gitFailure("fetch", "kex_exchange_identification: read: Connection reset by peer")},
|
|
{"a publish met by no responders", "publish: ", PublishFault(errors.New("nats: no responders available for request"))},
|
|
{"a publish met by a bundle that exited", "publish: ", PublishFault(errors.New("the bundle exited"))},
|
|
{"a fetch of a commit that is not there", "", gitFailure("fetch", "fatal: unknown revision or path not in the working tree")},
|
|
{"a publish refused", "", PublishFault(errors.New("refused: the digest differs"))},
|
|
} {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
if tc.why == "" {
|
|
if sdkstep.IsPassing(tc.err) {
|
|
t.Fatalf("%v is a transport fault, want a failure", tc.err)
|
|
}
|
|
return
|
|
}
|
|
if !sdkstep.IsPassing(tc.err) || !strings.HasPrefix(tc.err.Error(), tc.why) {
|
|
t.Fatalf("%v: want a transport fault opening with %q", tc.err, tc.why)
|
|
}
|
|
for _, prior := range []int{0, 2} { // its first run ends again after 15 s; its third ends the step failed
|
|
src, st := NewFakeAsks(), newSteps()
|
|
a := testAsk(sdkstep.AskDelivery)
|
|
_ = src.PublishAsk(a)
|
|
p := &Puller{Source: src, Language: sdkstep.AskGo, Node: "shanks", Put: st.put, Capacity: func() int { return 1 },
|
|
PullWait: 10 * time.Millisecond, Prior: func(string) int { return prior },
|
|
Run: func(context.Context, sdkstep.StepAsk) (any, error) { return nil, tc.err }}
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
go p.Pull(ctx)
|
|
key, _ := sdkstep.AskStepKey("", "shanks", a.ID)
|
|
waitFor(t, "the run's end", func() bool { s, ok := st.get(key); return ok && s.State != sdkstep.StepRunning })
|
|
cancel()
|
|
s, _ := st.get(key)
|
|
src.mu.Lock()
|
|
delays := append([]time.Duration(nil), src.Delays...)
|
|
src.mu.Unlock()
|
|
if prior == 0 && (s.State != sdkstep.StepAgain || len(delays) != 1 || delays[0] != 15*time.Second) {
|
|
t.Errorf("the first run: step %+v, delays %v, want again after 15s", s, delays)
|
|
}
|
|
if prior == 2 && (s.State != sdkstep.StepFailed || !strings.HasPrefix(s.Reason, tc.why)) {
|
|
t.Errorf("the third run: step %+v, want failed with the why %q", s, tc.why)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|