A process answers its seat's verbs through one call: caller-named and
unproven subjects, one queue group per seat, reply {result, error, node}.
The rule that a process answers no call (issue 1171 AC3) is replaced by one
that AnswerSeat is the only way to serve. A compare-and-set write on a
process's own state already exists (State.Create, Update).
Builds: design 47 G A-107 (G-20-lead-answers)
Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
41 lines
1.5 KiB
Go
41 lines
1.5 KiB
Go
package process
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/nats-io/nats.go"
|
|
)
|
|
|
|
// 1171/AC3 as lead answer A-107 changes it: a process answers its seat's verbs through AnswerSeat alone — no Serve,
|
|
// Handle, Subscribe or Respond of its own — and exposes no raw connection. Checked by reflection over *Conn's whole
|
|
// method set and field list, so a later addition cannot bring one back without this test naming it.
|
|
func TestConnOffersOnlyAnswerSeatToServeAndExposesNoRawConnection(t *testing.T) {
|
|
ptrType := reflect.TypeOf(&Conn{})
|
|
if _, ok := ptrType.MethodByName("AnswerSeat"); !ok {
|
|
t.Error("*Conn has no AnswerSeat: a process answers its seat's verbs through it (A-107)")
|
|
}
|
|
for _, forbidden := range []string{"Serve", "ServeOn", "Handle", "Subscribe", "Respond", "Answer"} {
|
|
if _, ok := ptrType.MethodByName(forbidden); ok {
|
|
t.Errorf("*Conn has a method %s: a process serves only through AnswerSeat", forbidden)
|
|
}
|
|
}
|
|
|
|
natsConnType := reflect.TypeOf(&nats.Conn{})
|
|
structType := reflect.TypeOf(Conn{})
|
|
for i := 0; i < structType.NumField(); i++ {
|
|
f := structType.Field(i)
|
|
if f.IsExported() && (f.Type == natsConnType || f.Type == natsConnType.Elem()) {
|
|
t.Errorf("Conn exposes its raw connection through the exported field %s", f.Name)
|
|
}
|
|
}
|
|
for i := 0; i < ptrType.NumMethod(); i++ {
|
|
m := ptrType.Method(i)
|
|
for o := 0; o < m.Type.NumOut(); o++ {
|
|
if m.Type.Out(o) == natsConnType || m.Type.Out(o) == natsConnType.Elem() {
|
|
t.Errorf("*Conn.%s returns the raw *nats.Conn", m.Name)
|
|
}
|
|
}
|
|
}
|
|
}
|