H1 integration bound: the runner follows a membership without dropping a call
On every membership of a module, HandleCalled stopped each subscription of a tool and subscribed again on the same subjects; a call the bus routed in that window was dropped by the client in silence, and its caller waited the runner's whole bound (30 s). On the build node this was the 30 s of TestAReplacedBundlesOldToolStaysGoneOnTheNextMembership and of TestTheLedgerRepairsAreToolsOfEveryLedgerOwner, and most of the integration level's 72 s. Now a membership keeps every subscription whose subject and queue it still names, subscribes the new ones, and only then stops those it no longer names (make before break). The test asks the served tool once after each of five memberships, with the tests' own call bound of 2 s (principle 11); it fails without the change. The runtime tests' call helper and the ledger listing wait that bound, not the runner's 30 s. Builds: design 47 H §774, H-A-158; principle 11
This commit is contained in:
@@ -740,25 +740,35 @@ func (c *Conn) HandleCalled(key string, h CalledHandler) (func(), error) {
|
|||||||
"those of the modules it follows", c.self, key)
|
"those of the modules it follows", c.self, key)
|
||||||
}
|
}
|
||||||
var mu sync.Mutex
|
var mu sync.Mutex
|
||||||
var stops []func()
|
stops := map[Served]func(){}
|
||||||
stopped := false
|
stopped := false
|
||||||
|
// **Make before break** (novox/hq design 47 H, H-A-158): a membership issued again keeps every subscription
|
||||||
|
// whose subject and queue it still names, subscribes those it newly names, and only then stops those it no
|
||||||
|
// longer names — a call the bus routes while the membership is followed is never dropped in silence.
|
||||||
serve := func() {
|
serve := func() {
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
defer mu.Unlock()
|
defer mu.Unlock()
|
||||||
if stopped {
|
if stopped {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, s := range stops {
|
named := map[Served]bool{}
|
||||||
s()
|
|
||||||
}
|
|
||||||
stops = nil
|
|
||||||
for _, s := range c.servedOn(module, tool) {
|
for _, s := range c.servedOn(module, tool) {
|
||||||
|
named[s] = true
|
||||||
|
if _, kept := stops[s]; kept {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if stop, err := c.answerBoth(s.Subject, s.Queue, h); err == nil {
|
if stop, err := c.answerBoth(s.Subject, s.Queue, h); err == nil {
|
||||||
stops = append(stops, stop)
|
stops[s] = stop
|
||||||
} else {
|
} else {
|
||||||
c.Logf("[mesh-tools] cannot serve %s on %s: %v", key, s.Subject, err)
|
c.Logf("[mesh-tools] cannot serve %s on %s: %v", key, s.Subject, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for s, stop := range stops {
|
||||||
|
if !named[s] {
|
||||||
|
stop()
|
||||||
|
delete(stops, s)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
serve()
|
serve()
|
||||||
// Its stop drops the membership handler too: a handler left behind would bind the stopped tool again
|
// Its stop drops the membership handler too: a handler left behind would bind the stopped tool again
|
||||||
@@ -773,10 +783,10 @@ func (c *Conn) HandleCalled(key string, h CalledHandler) (func(), error) {
|
|||||||
mu.Lock()
|
mu.Lock()
|
||||||
defer mu.Unlock()
|
defer mu.Unlock()
|
||||||
stopped = true
|
stopped = true
|
||||||
for _, s := range stops {
|
for s, stop := range stops {
|
||||||
s()
|
stop()
|
||||||
|
delete(stops, s)
|
||||||
}
|
}
|
||||||
stops = nil
|
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ func TestTheLedgerRepairsAreToolsOfEveryLedgerOwner(t *testing.T) {
|
|||||||
defer stop()
|
defer stop()
|
||||||
asker := connect(t, "console", "workstation")
|
asker := connect(t, "console", "workstation")
|
||||||
listed := func(module string) (string, error) {
|
listed := func(module string) (string, error) {
|
||||||
answered, err := asker.Ask(module+"."+ToolsVerb, map[string]any{}, "")
|
answered, err := asker.AskWithin(module+"."+ToolsVerb, map[string]any{}, "", callWithin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -263,7 +263,9 @@ func TestAReplacedBundleIsReloaded(t *testing.T) {
|
|||||||
|
|
||||||
// A replaced bundle's old tool stays gone when the module's membership is issued again: a stopped tool
|
// A replaced bundle's old tool stays gone when the module's membership is issued again: a stopped tool
|
||||||
// leaves no membership handler behind to bind it once more, and a call on it starts no unmanaged second
|
// leaves no membership handler behind to bind it once more, and a call on it starts no unmanaged second
|
||||||
// copy of the bundle (issue 1945, review round 2).
|
// copy of the bundle (issue 1945, review round 2). And the tool still served answers the first call asked
|
||||||
|
// after each membership, within the test's own bound: the runner keeps the subscriptions the membership
|
||||||
|
// still names, so no call is dropped while it follows one (design 47 H, H-A-158).
|
||||||
func TestAReplacedBundlesOldToolStaysGoneOnTheNextMembership(t *testing.T) {
|
func TestAReplacedBundlesOldToolStaysGoneOnTheNextMembership(t *testing.T) {
|
||||||
b := newReloadBed(t)
|
b := newReloadBed(t)
|
||||||
place(t, b.entry, "first")
|
place(t, b.entry, "first")
|
||||||
@@ -273,8 +275,13 @@ func TestAReplacedBundlesOldToolStaysGoneOnTheNextMembership(t *testing.T) {
|
|||||||
b.answers(t, "second")
|
b.answers(t, "second")
|
||||||
b.silent(t, "first")
|
b.silent(t, "first")
|
||||||
|
|
||||||
|
for round := 1; round <= 5; round++ {
|
||||||
b.mesh.Issue(t, mt.MembershipOf("ledger", "anchor", false, nil))
|
b.mesh.Issue(t, mt.MembershipOf("ledger", "anchor", false, nil))
|
||||||
b.answers(t, "second")
|
if got, err := call(t, b.asker, "ledger.second@anchor", map[string]any{}); err != nil || !strings.Contains(got, `"tool":"second"`) {
|
||||||
|
t.Fatalf("membership %d issued again: the first call of ledger.second answered %s, %v — dropped while the runner "+
|
||||||
|
"followed the membership\n%s", round, got, err, b.logs.All())
|
||||||
|
}
|
||||||
|
}
|
||||||
// Long enough for the reissued membership to have been heard, before the old tool is asked.
|
// Long enough for the reissued membership to have been heard, before the old tool is asked.
|
||||||
time.Sleep(300 * time.Millisecond)
|
time.Sleep(300 * time.Millisecond)
|
||||||
if got, err := call(t, b.asker, "ledger.first@anchor", map[string]any{}); err == nil {
|
if got, err := call(t, b.asker, "ledger.first@anchor", map[string]any{}); err == nil {
|
||||||
|
|||||||
@@ -26,9 +26,13 @@ func connect(t *testing.T, module, node string) *bus.Conn {
|
|||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// callWithin is the tests' own bound on a call (principle 11, design 47 H, H-A-158): a call that is never answered
|
||||||
|
// fails the try it is part of within it, never after the tool runner's own 30 s.
|
||||||
|
const callWithin = 2 * time.Second
|
||||||
|
|
||||||
func call(t *testing.T, asker *bus.Conn, key string, args any) (string, error) {
|
func call(t *testing.T, asker *bus.Conn, key string, args any) (string, error) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
got, err := asker.Ask(key, args, "")
|
got, err := asker.AskWithin(key, args, "", callWithin)
|
||||||
return string(got.Result), err
|
return string(got.Result), err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user