H1 integration bound: the repairs' refresh keeps the tools it still serves
When a module's ledger binding came or went, refreshRepairs stopped every subscription of its tools and served them all again, so a call in that gap was dropped the same way as on a membership (H-A-158). serve is now the one routine that changes a module's subscriptions, by tool address: it keeps those still named, subscribes the new, then stops those no longer named; refreshRepairs and the first serve both go through it, so no tool is served twice or not at all. The ledger test's later binding now comes and goes ten times, and the module's own tool must answer the first call after each, within the tests' 2 s bound; it failed without the change at GOMAXPROCS=1 and 24. Builds: design 47 H §774, H-A-158, H-A-160; principle 11
This commit is contained in:
@@ -67,6 +67,18 @@ func TestTheLedgerRepairsAreToolsOfEveryLedgerOwner(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
t.Run("a ledger bound later brings them", func(t *testing.T) {
|
t.Run("a ledger bound later brings them", func(t *testing.T) {
|
||||||
|
// Its own tool answers the first call after each binding comes or goes: the repairs' refresh keeps the
|
||||||
|
// subscriptions it still names (design 47 H, H-A-160).
|
||||||
|
for round := 1; round <= 10; round++ {
|
||||||
|
plain.Bindings = nil
|
||||||
|
if round%2 == 1 {
|
||||||
|
plain.Bindings = owner.Bindings
|
||||||
|
}
|
||||||
|
mesh.Issue(t, plain)
|
||||||
|
if _, err := asker.AskWithin("plain.who@anchor", map[string]any{}, "", callWithin); err != nil {
|
||||||
|
t.Fatalf("binding change %d: the first call of plain.who failed: %v — dropped while its tools were served again", round, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
plain.Bindings = owner.Bindings
|
plain.Bindings = owner.Bindings
|
||||||
mesh.Issue(t, plain)
|
mesh.Issue(t, plain)
|
||||||
mt.Until(t, func() error {
|
mt.Until(t, func() error {
|
||||||
|
|||||||
@@ -185,10 +185,6 @@ func (r *runner) refreshRepairs() {
|
|||||||
if served == (repairs != nil) {
|
if served == (repairs != nil) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for i := len(l.serving) - 1; i >= 0; i-- {
|
|
||||||
l.serving[i]()
|
|
||||||
}
|
|
||||||
l.serving, l.names = nil, nil
|
|
||||||
l.own, l.regs = withRepairs(l.own, repairs), withRepairs(l.regs, repairs)
|
l.own, l.regs = withRepairs(l.own, repairs), withRepairs(l.regs, repairs)
|
||||||
r.serve(l)
|
r.serve(l)
|
||||||
changed = true
|
changed = true
|
||||||
@@ -208,13 +204,13 @@ type loadedModule struct {
|
|||||||
own []registration // those under the name of a module served here
|
own []registration // those under the name of a module served here
|
||||||
failed string
|
failed string
|
||||||
names []string // the tools it serves, as module.tool
|
names []string // the tools it serves, as module.tool
|
||||||
serving []func() // its tools' subscriptions
|
serving map[string]func() // its tools' subscriptions, by module.tool; serve alone changes it
|
||||||
}
|
}
|
||||||
|
|
||||||
// unload stops serving the module's tools and stops its bundles.
|
// unload stops serving the module's tools and stops its bundles.
|
||||||
func (l *loadedModule) unload() {
|
func (l *loadedModule) unload() {
|
||||||
for i := len(l.serving) - 1; i >= 0; i-- {
|
for _, stop := range l.serving {
|
||||||
l.serving[i]()
|
stop()
|
||||||
}
|
}
|
||||||
l.serving, l.names = nil, nil
|
l.serving, l.names = nil, nil
|
||||||
for i := len(l.children) - 1; i >= 0; i-- {
|
for i := len(l.children) - 1; i >= 0; i-- {
|
||||||
@@ -493,25 +489,47 @@ func refusal(own []registration) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// serve binds a loaded module's tools. r.mu is held.
|
// serve binds a loaded module's tools as its registrations name them now, and is the one routine that changes its
|
||||||
|
// subscriptions (design 47 H, H-A-158, H-A-160): a tool still named keeps its subscription, a newly named one is
|
||||||
|
// subscribed, and only then is one no longer named stopped — no tool is served twice, and none is dropped while the
|
||||||
|
// module's tools are served again. r.mu is held.
|
||||||
func (r *runner) serve(l *loadedModule) {
|
func (r *runner) serve(l *loadedModule) {
|
||||||
|
if l.serving == nil {
|
||||||
|
l.serving = map[string]func(){}
|
||||||
|
}
|
||||||
|
named := map[string]bool{}
|
||||||
|
l.names = nil
|
||||||
for _, reg := range l.own {
|
for _, reg := range l.own {
|
||||||
for _, t := range reg.tools {
|
for _, t := range reg.tools {
|
||||||
t := t
|
t := t
|
||||||
|
address := reg.module + "." + t.Name
|
||||||
|
if named[address] {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
named[address] = true
|
||||||
|
if _, kept := l.serving[address]; !kept {
|
||||||
// Told who called, from the subject the call arrived on, never from its body (novox/hq issue 365).
|
// Told who called, from the subject the call arrived on, never from its body (novox/hq issue 365).
|
||||||
// Through the approval gate, before the bundle or the runner's own tool (design 46 7-approval-mark §20).
|
// Through the approval gate, before the bundle or the runner's own tool (design 46 7-approval-mark §20).
|
||||||
module, own := reg.module, reg.repairs
|
module, own := reg.module, reg.repairs
|
||||||
stop, err := r.conn.HandleCalled(reg.module+"."+t.Name, func(caller string, body json.RawMessage) (any, error) {
|
stop, err := r.conn.HandleCalled(address, func(caller string, body json.RawMessage) (any, error) {
|
||||||
return r.events.gated(approval.Call{Address: module + "." + t.Name, Module: module, Name: t.Name, Own: own,
|
return r.events.gated(approval.Call{Address: module + "." + t.Name, Module: module, Name: t.Name, Own: own,
|
||||||
Fingerprint: r.fingerprintOf(module), Env: r.envOf(module), Caller: caller, Args: argsOf(body),
|
Fingerprint: r.fingerprintOf(module), Env: r.envOf(module), Caller: caller, Args: argsOf(body),
|
||||||
Description: t.Description}, t, caller)
|
Description: t.Description}, t, caller)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
r.logf("[mesh-tools] cannot serve %s.%s: %v", reg.module, t.Name, err)
|
r.logf("[mesh-tools] cannot serve %s.%s: %v", reg.module, t.Name, err)
|
||||||
|
delete(named, address)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
l.names = append(l.names, reg.module+"."+t.Name)
|
l.serving[address] = stop
|
||||||
l.serving = append(l.serving, stop)
|
}
|
||||||
|
l.names = append(l.names, address)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for address, stop := range l.serving {
|
||||||
|
if !named[address] {
|
||||||
|
stop()
|
||||||
|
delete(l.serving, address)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user