S2 ask-once-go: Ask calls once; the kind stopping goes

Builds: design 47 H2 H-A-570 (2) (3) (4), H-A-624 (3)
This commit is contained in:
2026-11-25 17:04:29 +01:00
parent cedfa71169
commit e5b66a77ba
6 changed files with 68 additions and 104 deletions
+7 -17
View File
@@ -189,15 +189,6 @@ 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} }
@@ -290,21 +281,20 @@ func (c *Conn) requestAsk(subject string, data []byte, ask string) (json.RawMess
return result, nil
}
// readReply reads one reply ({result, error, error-kind, node, held}): a reply naming an error is the call's failure,
// of the kind stopping a transport fault a kept call paces on (design 47 H2 H-A-549 (1)); a held call names its hold.
// readReply reads one reply ({result, error, error-kind, node, held}): a reply naming an error is the call's failure; a held
// call names its hold.
func readReply(subject string, data []byte) (json.RawMessage, *approval.Held, error) {
var r struct {
Result json.RawMessage `json:"result"`
Error string `json:"error"`
ErrorKind string `json:"error-kind"`
Node string `json:"node"`
Held *approval.Held `json:"held"`
Result json.RawMessage `json:"result"`
Error string `json:"error"`
Node string `json:"node"`
Held *approval.Held `json:"held"`
}
if err := json.Unmarshal(data, &r); err != nil {
return nil, nil, fmt.Errorf("%s answered something that is not a seat's answer: %w", subject, err)
}
if r.Error != "" {
return nil, nil, replyError(r.Error, r.ErrorKind)
return nil, nil, answered(r.Error)
}
return r.Result, r.Held, nil
}
+11 -5
View File
@@ -143,8 +143,8 @@ func TestACallIsAskedAgainOnlyWhenItReachedNoOne(t *testing.T) {
}
}
// 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.
// refusal of another kind is the caller's answer at once, and so is a reply of the withdrawn kind stopping
// (H-A-570 (3)).
for _, row := range []struct {
name string
answers []string
@@ -153,9 +153,9 @@ func TestACallIsAskedAgainOnlyWhenItReachedNoOne(t *testing.T) {
want string // the call's answer, where it is not the last answer
}{
{"away, then answered", []string{`{"error":"x","error-kind":"away","part":"the forge's store","words":"401"}`, `{"merged":true}`}, 2, false, ""},
// H-A-549 (1): the runner's reply of the kind stopping, read from its bytes, is paced on until the new runner answers.
{"stopping, then answered by the new runner", []string{`{"error":"git's trees was not taken: the tool runner is stopping","error-kind":"stopping"}`,
`{"result":{"merged":true}}`}, 2, true, `{"merged":true}`},
// H-A-570 (3): a reply of the kind stopping, read from its bytes, is the callee's answer, asked once.
{"stopping withdrawn: answered at once", []string{`{"error":"git's trees was not taken: the tool runner is stopping","error-kind":"stopping"}`,
`{"result":{"merged":true}}`}, 1, true, ""},
{"refused: answered at once", []string{`{"error":"no","error-kind":"refused"}`}, 1, false, ""},
} {
asks := 0
@@ -173,6 +173,12 @@ func TestACallIsAskedAgainOnlyWhenItReachedNoOne(t *testing.T) {
want = row.answers[len(row.answers)-1]
}
got, err := callKeptWith(busretry.Kept{Seat: "git", Verb: "merge-pull"}, request, "called", "fallback", nil)
if row.replies && row.want == "" {
if asks != row.asks || err == nil {
t.Errorf("%s: asked %d times, %s, %v", row.name, asks, got, err)
}
continue
}
if asks != row.asks || err != nil || string(got) != want {
t.Errorf("%s: asked %d times, %s, %v", row.name, asks, got, err)
}