Revert the revert of G's mesh-sdk merge (#191): G's sdk stands again over reader release 3
Main reverted G's half merge (#189, reverted by8afc3ebin #191) and then took the reader release's S1-S5, which copied G's code. G's form holds where they differ (process_bus.go, seats.go, state.go and their tests); the release's kept names stay so main's callers keep building: SeatViewPrefix beside SeatReadPrefix, and QueueInvoke's empty strings on not-ok (with its test TestQueueInvoke). The tree differs from G's headf30dee54only by those and the release's two tests (objects cap option, seat states and stream kinds). Builds: design 47 G (the milestone's sdk part, as atf30dee54) Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
This commit is contained in:
@@ -6,6 +6,10 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"git.novox.be/novox/mesh-sdk/go/seatdef"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -281,3 +285,94 @@ func TestCallOnReachesTheNamedNodeAlone(t *testing.T) {
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
// brokerSeat is the fixture seat's definition as a seat list holds it: its three verbs, each its class's default.
|
||||
func brokerSeat() (seatdef.Definition, bool) {
|
||||
return seatdef.Definition{Seat: "broker-seat", Verbs: []seatdef.Verb{{Name: "ping"}, {Name: "fail"}, {Name: "boom"}}}, true
|
||||
}
|
||||
|
||||
// A-107: a process answers its seat's verbs over the bus. Given two instances of one holder answering seat
|
||||
// `broker-seat`'s verbs, a call on the caller-named subject reaches exactly one, which is handed the caller the
|
||||
// subject names (dots written `~`) and replies {result, node}; a call on the subject naming none is refused; a
|
||||
// handler's error is the reply's error, a panic too; and after stop nothing answers.
|
||||
func TestAnswerSeatServesVerbsWithTheProvedCallerInOneQueueGroup(t *testing.T) {
|
||||
url, account := grantedSendProcess(t)
|
||||
adminNC, _ := adminJS(t, url)
|
||||
account.User, account.Password, account.Node = adminUser, adminPass, "novox"
|
||||
|
||||
var heard sync.Map
|
||||
count := func(name string) SeatHandler {
|
||||
return func(caller string, body json.RawMessage) (any, error) {
|
||||
n, _ := heard.LoadOrStore(name, new(int32))
|
||||
atomic.AddInt32(n.(*int32), 1)
|
||||
return map[string]string{"caller": caller, "body": string(body)}, nil
|
||||
}
|
||||
}
|
||||
verbs := func(name string) map[string]SeatHandler {
|
||||
return map[string]SeatHandler{
|
||||
"ping": count(name),
|
||||
"fail": func(string, json.RawMessage) (any, error) { return nil, errors.New("refused: not yours") },
|
||||
"boom": func(string, json.RawMessage) (any, error) { panic("oops") },
|
||||
}
|
||||
}
|
||||
var stops []func()
|
||||
for _, name := range []string{"a", "b"} {
|
||||
conn, err := Connect(account)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer conn.Close()
|
||||
stop, err := conn.AnswerSeat("broker-seat", brokerSeat, verbs(name))
|
||||
if err != nil {
|
||||
t.Fatalf("AnswerSeat: %v", err)
|
||||
}
|
||||
stops = append(stops, stop)
|
||||
}
|
||||
ask := func(subject string) (struct {
|
||||
Result map[string]string `json:"result"`
|
||||
Error string `json:"error"`
|
||||
Node string `json:"node"`
|
||||
}, error) {
|
||||
var r struct {
|
||||
Result map[string]string `json:"result"`
|
||||
Error string `json:"error"`
|
||||
Node string `json:"node"`
|
||||
}
|
||||
msg, err := adminNC.Request(subject, []byte(`{"x":1}`), 5*time.Second)
|
||||
if err != nil {
|
||||
return r, err
|
||||
}
|
||||
return r, json.Unmarshal(msg.Data, &r)
|
||||
}
|
||||
|
||||
r, err := ask("mesh.seat.broker-seat.call.ping.novox~mesh-delivery-builder")
|
||||
if err != nil || r.Result["caller"] != "novox.mesh-delivery-builder" || r.Result["body"] != `{"x":1}` || r.Node != "novox" {
|
||||
t.Fatalf("a caller-named call: %+v, %v", r, err)
|
||||
}
|
||||
// An unproven caller is refused before the handler runs (design 47 G §610; lead answers A-165, A-179, A-186).
|
||||
r, err = ask("mesh.seat.broker-seat.tool.ping")
|
||||
if err != nil || r.Result != nil || !strings.Contains(r.Error, "broker-seat.ping takes no unproven caller") {
|
||||
t.Fatalf("an unproven call: %+v, %v", r, err)
|
||||
}
|
||||
if _, err := ask("mesh.seat.broker-seat.call.ping.novox~mesh-delivery-builder"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
total := int32(0)
|
||||
heard.Range(func(_, v any) bool { total += atomic.LoadInt32(v.(*int32)); return true })
|
||||
if total != 2 {
|
||||
t.Errorf("two proven calls were answered %d times in all, want once each (one queue group) and the unproven none", total)
|
||||
}
|
||||
if r, err = ask("mesh.seat.broker-seat.call.fail.x"); err != nil || r.Error != "refused: not yours" {
|
||||
t.Errorf("a handler's error: %+v, %v", r, err)
|
||||
}
|
||||
if r, err = ask("mesh.seat.broker-seat.call.boom.x"); err != nil || !strings.Contains(r.Error, "oops") {
|
||||
t.Errorf("a handler's panic: %+v, %v", r, err)
|
||||
}
|
||||
for _, stop := range stops {
|
||||
stop()
|
||||
}
|
||||
_ = adminNC.Flush()
|
||||
if _, err := adminNC.Request("mesh.seat.broker-seat.call.ping.x", nil, time.Second); !errors.Is(err, nats.ErrNoResponders) {
|
||||
t.Errorf("after stop a call reached someone: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user