H1 integration bound: a reload's stand-in serves no repairs; stop waits its Say
Review round 1. A ledger binding heard while a module was loaded again made refreshRepairs serve the repairs on the reload's stand-in, whose subscriptions nobody stopped: the repairs were served twice, and still answered after the runtime stopped. The stand-in is now marked as reloading and the refresh leaves it alone; the reload serves the module's repairs as its binding is when the load ends. The reload test holds a bundle's start, issues the binding inside the reload, and asks a repair after the runtime stopped: without the change it still answered (6 of 6 runs, GOMAXPROCS=1 and 24). No test failed without keep's stop waiting for the heartbeat's goroutine. The heartbeat test now holds one Say and stops meanwhile: stop must not return before that Say has; without the wait it failed 50 of 50 runs at GOMAXPROCS=1 and at 24. Builds: design 47 H §774, H-A-160; principle 11
This commit is contained in:
@@ -2,6 +2,7 @@ package runtime
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -10,6 +11,8 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||
"git.novox.be/novox/mesh-sdk/go/membership"
|
||||
"github.com/nats-io/nats.go"
|
||||
"github.com/nats-io/nats.go/micro"
|
||||
|
||||
@@ -154,13 +157,17 @@ func newReloadBed(t *testing.T) *reloadBed {
|
||||
}
|
||||
}
|
||||
|
||||
func (b *reloadBed) run(t *testing.T) {
|
||||
// run starts the runtime, stopped at the test's end or once by what it returns.
|
||||
func (b *reloadBed) run(t *testing.T) func() {
|
||||
t.Helper()
|
||||
stop, err := Run(b.nodeTools, []Served{{"ledger", []string{b.entry}}}, nil, b.logs.Logf)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(stop)
|
||||
var once sync.Once
|
||||
stopOnce := func() { once.Do(stop) }
|
||||
t.Cleanup(stopOnce)
|
||||
return stopOnce
|
||||
}
|
||||
|
||||
func (b *reloadBed) answers(t *testing.T, tool string) {
|
||||
@@ -269,7 +276,7 @@ func TestAReplacedBundleIsReloaded(t *testing.T) {
|
||||
func TestAReplacedBundlesOldToolStaysGoneOnTheNextMembership(t *testing.T) {
|
||||
b := newReloadBed(t)
|
||||
place(t, b.entry, "first")
|
||||
b.run(t)
|
||||
stop := b.run(t)
|
||||
b.answers(t, "first")
|
||||
place(t, b.entry, "second")
|
||||
b.answers(t, "second")
|
||||
@@ -287,6 +294,42 @@ func TestAReplacedBundlesOldToolStaysGoneOnTheNextMembership(t *testing.T) {
|
||||
if got, err := call(t, b.asker, "ledger.first@anchor", map[string]any{}); err == nil {
|
||||
t.Fatalf("ledger.first is served again after the membership was reissued, and answered %s\n%s", got, b.logs.All())
|
||||
}
|
||||
|
||||
// A ledger bound while the bundle is loaded again: its repairs are served once, by the module loaded, and none is
|
||||
// left behind on the stand-in the reload served nothing on (design 47 H, H-A-160). The bundle placed holds its
|
||||
// start until the test lets it go, so the membership is heard inside the reload.
|
||||
held, release := filepath.Join(t.TempDir(), "held"), filepath.Join(t.TempDir(), "release")
|
||||
placeScript(t, b.entry, strings.Replace(bundleServing("third"), "import json, os, sys\n",
|
||||
"import json, os, sys, time\nopen("+fmt.Sprintf("%q", held)+", \"w\").close()\nwhile not os.path.exists("+
|
||||
fmt.Sprintf("%q", release)+"):\n time.sleep(0.01)\n", 1))
|
||||
mt.Until(t, func() error { _, err := os.Stat(held); return err })
|
||||
bound := mt.MembershipOf("ledger", "anchor", false, nil)
|
||||
bound.Bindings = []membership.BusBinding{{Local: "records", Storage: catalogue.StorageLedger, Template: catalogue.TemplateLedger,
|
||||
History: "LEDGER_ledger_records", Subject: "mesh.ledger.ledger.records.history", State: "ledger_records",
|
||||
Snapshot: "mesh.ledger.ledger.records.snapshot"}}
|
||||
b.mesh.Issue(t, bound)
|
||||
mt.Until(t, func() error {
|
||||
if m := b.nodeTools.Membership("ledger"); m == nil || len(m.Bindings) == 0 {
|
||||
return errors.New("the ledger's binding is not heard yet")
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err := os.WriteFile(release, nil, 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b.answers(t, "third")
|
||||
mt.Until(t, func() error {
|
||||
_, err := call(t, b.asker, "ledger."+RepairLag+"@anchor", map[string]any{})
|
||||
if errors.Is(err, bus.ErrNoResponders) || (err != nil && err.Error() == "timeout") {
|
||||
return fmt.Errorf("the ledger's repairs are not served after its reload: %v", err)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
stop()
|
||||
if _, err := call(t, b.asker, "ledger."+RepairLag+"@anchor", map[string]any{}); !errors.Is(err, bus.ErrNoResponders) {
|
||||
t.Fatalf("the runtime stopped, and ledger.%s still answered (%v): served on the reload's stand-in and never stopped\n%s",
|
||||
RepairLag, err, b.logs.All())
|
||||
}
|
||||
}
|
||||
|
||||
// 1945/AC21: a bundle removed while served is no longer served, and its module says why.
|
||||
|
||||
Reference in New Issue
Block a user