process, stdio: a kept call paces on a stopping tool runner; the ask's bound is a setting (H-A-549)
Review round 1: the process caller read only a reply's error, so a kept call (CallKept, e.g. seat:git.trees) ended at once on stopping instead of pacing until the new runner answers. requestAsk now reads error-kind stopping as busretry.Stopping, which busretry.Fault counts as a transport fault, as away. The Go stdio Ask's 60 s bound becomes the setting ask-bound (default 60 s), read by the settings reader. Builds: design 47 H2 H-A-542, H-A-549
This commit is contained in:
+16
-2
@@ -163,12 +163,26 @@ func (u *Unanswered) Error() string {
|
||||
func (u *Unanswered) Unwrap() error { return u.Last }
|
||||
|
||||
// Fault says err is a transport fault of a kept call (§775): a request that reached no one, a call's own deadline
|
||||
// passing, or a holder's answer of the kind away (§776); a callee's refusal never is.
|
||||
// passing, a holder's answer of the kind away (§776), or a stopping tool runner's answer of the kind stopping (design 47
|
||||
// H2 H-A-542, H-A-549); a callee's refusal never is.
|
||||
func Fault(err error) bool {
|
||||
var away *Away
|
||||
return TimedOut(err) || Undelivered(err) || errors.As(err, &away)
|
||||
var stopping *Stopping
|
||||
return TimedOut(err) || Undelivered(err) || errors.As(err, &away) || errors.As(err, &stopping)
|
||||
}
|
||||
|
||||
// ErrorKindStopping is the typed fault a stopping tool runner answers each call it does not take with (design 47 H2
|
||||
// H-A-542): its reply's `error-kind`. Nothing was done, and the new runner answers the call.
|
||||
const ErrorKindStopping = "stopping"
|
||||
|
||||
// Stopping is a tool runner's answer of the kind stopping, read as an error: the runner's words.
|
||||
type Stopping struct{ Words string }
|
||||
|
||||
func (s *Stopping) Error() string { return s.Words }
|
||||
|
||||
// ErrorKind is the typed fault the answer named: stopping.
|
||||
func (s *Stopping) ErrorKind() string { return ErrorKindStopping }
|
||||
|
||||
// ErrorKindAway is the seat error kind a holder answers when a part it depends on is away (design 47 H2 §776): its
|
||||
// answer's `error-kind`, beside `part` (what did not answer) and `words`. A caller reads it as a transport fault.
|
||||
const ErrorKindAway = "away"
|
||||
|
||||
@@ -179,6 +179,10 @@ func subAKeptCallIsPaced(t *testing.T) {
|
||||
!strings.Contains(string(raw), `"error-kind":"away"`) {
|
||||
t.Fatalf("%s read as %+v", raw, a)
|
||||
}
|
||||
// A stopping tool runner's answer is a transport fault too (design 47 H2 H-A-549), wrapped or not.
|
||||
if !Fault(&Stopping{Words: "not taken"}) || !Fault(fmt.Errorf("asked: %w", &Stopping{Words: "not taken"})) {
|
||||
t.Fatal("a stopping tool runner's answer is no transport fault")
|
||||
}
|
||||
if AwayIn([]byte(`{"error":"no","error-kind":"refused"}`)) != nil || AwayIn([]byte(`[1]`)) != nil || Fault(&Answered{Words: "away"}) {
|
||||
t.Fatal("a refusal reads as away")
|
||||
}
|
||||
|
||||
+15
-5
@@ -189,6 +189,15 @@ func callWith(request func(string, []byte) (json.RawMessage, error), blackout fu
|
||||
return busretry.Do("the call on "+fallback, askBoth(request, called, fallback, data), blackout)
|
||||
}
|
||||
|
||||
// replyError is the error a reply naming one is the call's: a stopping tool runner's kind stopping is a transport fault a
|
||||
// kept call's pacing asks again on, as away is (design 47 H2 H-A-542, H-A-549); any other is the callee's answer.
|
||||
func replyError(words, kind string) error {
|
||||
if kind == busretry.ErrorKindStopping {
|
||||
return &busretry.Stopping{Words: words}
|
||||
}
|
||||
return answered(words)
|
||||
}
|
||||
|
||||
// answered is the error a callee answered with: delivered, never asked again (busretry.Answered).
|
||||
func answered(words string) error { return &busretry.Answered{Words: words} }
|
||||
|
||||
@@ -272,16 +281,17 @@ func (c *Conn) requestAsk(subject string, data []byte, ask string) (json.RawMess
|
||||
return nil, err
|
||||
}
|
||||
var r struct {
|
||||
Result json.RawMessage `json:"result"`
|
||||
Error string `json:"error"`
|
||||
Node string `json:"node"`
|
||||
Held *approval.Held `json:"held"`
|
||||
Result json.RawMessage `json:"result"`
|
||||
Error string `json:"error"`
|
||||
ErrorKind string `json:"error-kind"`
|
||||
Node string `json:"node"`
|
||||
Held *approval.Held `json:"held"`
|
||||
}
|
||||
if err := json.Unmarshal(msg.Data, &r); err != nil {
|
||||
return nil, fmt.Errorf("%s answered something that is not a seat's answer: %w", subject, err)
|
||||
}
|
||||
if r.Error != "" {
|
||||
return nil, answered(r.Error)
|
||||
return nil, replyError(r.Error, r.ErrorKind)
|
||||
}
|
||||
if r.Held != nil {
|
||||
return c.awaitGated(subject, *r.Held)
|
||||
|
||||
@@ -142,20 +142,25 @@ func TestACallIsAskedAgainOnlyWhenItReachedNoOne(t *testing.T) {
|
||||
t.Errorf("%s: asked %d times (%v), want %d", row.name, asks, err, row.asks)
|
||||
}
|
||||
}
|
||||
// Design 47 H2 §776: a holder's answer of the kind away is a transport fault, called again at the pace; a refusal
|
||||
// of another kind is the caller's answer at once.
|
||||
// Design 47 H2 §776: a holder's answer of the kind away is a transport fault, called again at the pace; so is a
|
||||
// stopping tool runner's reply of the kind stopping (H-A-542, H-A-549); a refusal of another kind is the caller's
|
||||
// answer at once.
|
||||
for _, row := range []struct {
|
||||
name string
|
||||
answers []string
|
||||
asks int
|
||||
}{
|
||||
{"away, then answered", []string{`{"error":"x","error-kind":"away","part":"the forge's store","words":"401"}`, `{"merged":true}`}, 2},
|
||||
{"stopping, then answered by the new runner", []string{"stopping", `{"merged":true}`}, 2},
|
||||
{"refused: answered at once", []string{`{"error":"no","error-kind":"refused"}`}, 1},
|
||||
} {
|
||||
asks := 0
|
||||
request := func(string, []byte) (json.RawMessage, error) {
|
||||
a := row.answers[min(asks, len(row.answers)-1)]
|
||||
asks++
|
||||
if a == "stopping" {
|
||||
return nil, replyError("git's trees was not taken: the tool runner is stopping", "stopping")
|
||||
}
|
||||
return json.RawMessage(a), nil
|
||||
}
|
||||
got, err := callKeptWith(busretry.Kept{Seat: "git", Verb: "merge-pull"}, request, "called", "fallback", nil)
|
||||
|
||||
+17
-7
@@ -170,7 +170,7 @@ func (r *refused) ErrorKind() string { return r.kind }
|
||||
|
||||
// ErrorKindStopping is the typed fault a stopping tool runner answers each call it does not take with (design 47 H2 H-A-542):
|
||||
// the answer's `error-kind`. Ask asks again after a pause until the new runner answers or its bound ends.
|
||||
const ErrorKindStopping = "stopping"
|
||||
const ErrorKindStopping = busretry.ErrorKindStopping
|
||||
|
||||
// ErrStopping is a call a stopping tool runner did not take (ErrorKindStopping): nothing was done, and the new runner answers
|
||||
// it. Told apart by its kind, never by its words.
|
||||
@@ -604,7 +604,12 @@ func Ask(key string, body any) (json.RawMessage, error) {
|
||||
return nil, err
|
||||
}
|
||||
// A call a stopping tool runner did not take is asked again after a pause, at the kept-call pace, until the new runner
|
||||
// answers or Ask's own bound ends; then its fault is the caller's as such, ErrStopping (design 47 H2 H-A-542).
|
||||
// answers or Ask's own bound (the setting ask-bound) ends; then its fault is the caller's as such, ErrStopping (design 47 H2
|
||||
// H-A-542, H-A-549).
|
||||
askBound, err := SettingDuration(AskBoundSetting, DefaultAskBound)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
start, wait := askNow(), busretry.KeptPace().First
|
||||
for {
|
||||
left := askBound - askNow().Sub(start)
|
||||
@@ -621,12 +626,17 @@ func Ask(key string, body any) (json.RawMessage, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// askBound is how long Ask waits for its answer, asks again included; pause is how it waits between two asks and askNow its
|
||||
// clock, a test's to replace so nothing sleeps.
|
||||
// AskBoundSetting is the module's setting of how long Ask waits for its answer, asks again included, a duration text;
|
||||
// DefaultAskBound is its default (design 47 H2 H-A-549).
|
||||
const (
|
||||
AskBoundSetting = "ask-bound"
|
||||
DefaultAskBound = 60 * time.Second
|
||||
)
|
||||
|
||||
// pause is how Ask waits between two asks and askNow its clock, a test's to replace so nothing sleeps.
|
||||
var (
|
||||
askBound = 60 * time.Second
|
||||
pause = time.Sleep
|
||||
askNow = time.Now
|
||||
pause = time.Sleep
|
||||
askNow = time.Now
|
||||
)
|
||||
|
||||
// TopicMatches says whether an event's type matches a pattern: `*` is one dot-separated segment, `#`
|
||||
|
||||
+4
-3
@@ -424,11 +424,12 @@ func TestAStoppingRunnersCallIsAskedAgainUntilTheNewRunnerAnswers(t *testing.T)
|
||||
t.Setenv(ServedAs, "builder")
|
||||
clock := time.Unix(0, 0)
|
||||
var paused []time.Duration
|
||||
wasPause, wasNow, wasBound := pause, askNow, askBound
|
||||
t.Cleanup(func() { pause, askNow, askBound = wasPause, wasNow, wasBound })
|
||||
wasPause, wasNow := pause, askNow
|
||||
t.Cleanup(func() { pause, askNow = wasPause, wasNow })
|
||||
pause = func(d time.Duration) { paused = append(paused, d); clock = clock.Add(d) }
|
||||
askNow = func() time.Time { return clock }
|
||||
askBound = 10 * time.Second
|
||||
// The bound is the setting ask-bound (H-A-549), here 10 s for its default 60 s.
|
||||
t.Setenv("MESH_CONFIG_ASK_BOUND", "10s")
|
||||
inR, inW := io.Pipe()
|
||||
outR, outW := io.Pipe()
|
||||
go func() {
|
||||
|
||||
Reference in New Issue
Block a user