node-tools: a stopping tool runner takes its subscriptions down, so callers meet no responders (issue 721)
The runner answered each call it did not take once its stop began with the typed fault stopping (#90). Callers built before mesh-sdk read it as the callee's refusal and ended their kept call, and no edge delivered the new answer after its readers. Now, once told to stop, the runner first drains every subscription it answers calls on (a tool's, a seat verb's and a seat proof's) and subscribes none again, then finishes the calls in flight within drain-bound. A call made after the stop meets no responders at once, a transport fault every caller of every mesh-sdk already waits out, until the new runner subscribes. A call that still reached it is answered nothing, as H-A-369 has it. The typed answer goes whole: the reply's error-kind, KindedError, ErrorKindStopping and the bundle's error data. Tests: 721/AC4 in the bus (a call and a proof after the stop meet no responders within a second, the call in flight is answered, a subject served after the stop is refused) and in launch (a call that still reaches the runner gets no answer and no typed fault); the whole test meets no responders while a call is still in flight, before the drain bound. Builds: design 47 H2 H-A-570 (1), (3) (mesh-tools' part), amending §813 (12) as H-A-369 has it
This commit is contained in:
@@ -244,22 +244,20 @@ func TestACallWaitsTheBoundItsVerbNamesAndTimesOutThere(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// stoppingFault is the error a stopping tool runner's drain hands for a call it does not take (launch's afterStop).
|
||||
type stoppingFault struct{}
|
||||
|
||||
func (stoppingFault) Error() string { return "not taken: the tool runner is stopping" }
|
||||
func (stoppingFault) ErrorKind() string { return "stopping" }
|
||||
|
||||
// A call a stopping tool runner does not take is answered the typed fault stopping, never silence, and its caller is
|
||||
// handed that kind as such, beside the answerer's words; a plain refusal carries no kind (design 47 H2 H-A-542).
|
||||
func TestAStoppingRunnersFaultReachesItsCallerByItsKind(t *testing.T) {
|
||||
// 721/AC4: once told to stop, the tool runner unsubscribes from every subject it answers calls on before it finishes the
|
||||
// calls in flight (design 47 H2 H-A-570 (1)): a call heard after the stop began gets no answer from it, no typed fault, and its
|
||||
// caller meets no responders at once; the call in flight at the stop is still answered; a subject served once the stop began
|
||||
// is not subscribed, and says so.
|
||||
func TestARunnerAtItsStopAnswersNoCallAndItsCallersMeetNoResponders(t *testing.T) {
|
||||
url := mt.URL(t)
|
||||
server := dial(t, url, "ledger", "anchor", "")
|
||||
began, release := make(chan struct{}, 1), make(chan struct{})
|
||||
stop, err := server.HandleSubjectCalled("mesh.mod.ledger.tool.who", func(_, _ string, body json.RawMessage) (any, error) {
|
||||
if strings.Contains(string(body), "plain") {
|
||||
return nil, errors.New("ledger keeps no such key")
|
||||
if strings.Contains(string(body), "held") {
|
||||
began <- struct{}{}
|
||||
<-release
|
||||
}
|
||||
return nil, fmt.Errorf("ledger's who: %w", stoppingFault{})
|
||||
return map[string]any{"who": "ledger"}, nil
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -267,13 +265,29 @@ func TestAStoppingRunnersFaultReachesItsCallerByItsKind(t *testing.T) {
|
||||
defer stop()
|
||||
server.Flush()
|
||||
asker := dial(t, url, "node-tools", "shanks", "shanks.node-tools")
|
||||
_, err = asker.Ask("ledger.who", map[string]any{}, "")
|
||||
var kinded interface{ ErrorKind() string }
|
||||
if !errors.As(err, &kinded) || kinded.ErrorKind() != "stopping" || !strings.Contains(err.Error(), "the tool runner is stopping") {
|
||||
t.Errorf("the call was answered %v, want the typed fault stopping with the answerer's words", err)
|
||||
held := make(chan error, 1)
|
||||
go func() {
|
||||
_, err := asker.AskWithin("ledger.who", map[string]any{"held": true}, "", 10*time.Second)
|
||||
held <- err
|
||||
}()
|
||||
select {
|
||||
case <-began:
|
||||
case <-time.After(10 * time.Second):
|
||||
t.Fatal("the call to hold never reached the runner")
|
||||
}
|
||||
_, err = asker.Ask("ledger.who", map[string]any{"plain": true}, "")
|
||||
if err == nil || errors.As(err, &kinded) || err.Error() != "ledger keeps no such key" {
|
||||
t.Errorf("a plain refusal was answered %v, want its words and no kind", err)
|
||||
server.StopAnswering()
|
||||
at := time.Now()
|
||||
answered, err := asker.AskWithin("ledger.who", map[string]any{}, "", 5*time.Second)
|
||||
if took := time.Since(at); !errors.Is(err, bus.ErrNoResponders) || took > time.Second {
|
||||
t.Errorf("a call after the stop began was answered %s, %v in %s; want no responders at once", answered.Result, err, took)
|
||||
}
|
||||
if _, err := server.HandleSubjectCalled("mesh.mod.ledger.tool.late", func(string, string, json.RawMessage) (any, error) {
|
||||
return nil, nil
|
||||
}); err == nil || !strings.Contains(err.Error(), "took down every subscription") {
|
||||
t.Errorf("a subject served once the stop began was subscribed (%v), want it refused and said", err)
|
||||
}
|
||||
close(release)
|
||||
if err := <-held; err != nil {
|
||||
t.Errorf("the call in flight at the stop ended %v, want it answered", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user