Read drain-bound through the one settings reader, a duration text, 30 s by default

The runner reads its setting drain-bound as the node-engine composes it (MESH_CONFIG_DRAIN_BOUND)
with the SDK's duration reader, and stops before it serves on a value that is no duration.

Builds: design 47 H2 §813 (12), §781, H-A-369, H-A-370, H-A-377
This commit is contained in:
2026-11-21 23:58:54 +01:00
parent 858beb2b63
commit 5cca1fceba
4 changed files with 52 additions and 9 deletions
+12 -3
View File
@@ -29,6 +29,7 @@ import (
handacts "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshhandacts"
"git.novox.be/novox/mesh-contracts/operator-and-conversation/go/clients/operatorchannelclient"
stdio "git.novox.be/novox/mesh-sdk/go"
"git.novox.be/novox/mesh-sdk/go/approval"
"github.com/novox/mesh-tools/node-tools/internal/alive"
@@ -65,6 +66,11 @@ func main() {
// serve is the tool runner: it reads its credential and serves until ctx ends, then shuts down in order. It is the entry a whole test
// starts, beside the process's own (design 47 H §774, H-A-61).
func serve(ctx context.Context) error {
// The drain bound, read first so a setting that is no duration stops the runner before it serves (design 47 H2 §813 (12)).
drainBound, err := drainBoundSetting()
if err != nil {
return err
}
until := time.Now().Add(startWait)
cred := credential(until)
conn := connectPatiently(cred, until)
@@ -168,9 +174,12 @@ func serve(ctx context.Context) error {
return nil
}
// drainBound is how long the runner, told to stop, waits for the calls in flight to finish: the setting drain-bound (design 47
// H2 §813 (12)).
var drainBound = launch.DefaultDrainBound
// drainBoundSetting is how long the runner, told to stop, waits for the calls in flight to finish: the module's setting
// drain-bound, a duration text the node-engine composes as MESH_CONFIG_DRAIN_BOUND, read through the one settings reader, 30 s
// when none is composed (design 47 H2 §813 (12), H-A-369, H-A-370, H-A-377).
func drainBoundSetting() (time.Duration, error) {
return stdio.SettingDuration(launch.DrainBoundSetting, launch.DefaultDrainBound)
}
// startWait is how long a runtime waits, from its start, for its broker credential to be on the machine and for the bus
// to accept the account it names (issue 1496): the node-engine starts a module's runtime before the provisioner's client
+32
View File
@@ -130,3 +130,35 @@ func connectsWithin(t *testing.T) {
})
}
}
// **The drain bound is the setting drain-bound** (design 47 H2 §813 (12), H-A-369, H-A-370, H-A-377): a duration text the
// node-engine composes as MESH_CONFIG_DRAIN_BOUND, 30 s when none is composed; a value that is no duration stops the runner
// before it serves, naming the setting.
func TestTheRunnersDrainBoundIsItsSettingDrainBound(t *testing.T) {
for _, row := range []struct {
composed string
want time.Duration
refused bool
}{
{"", 30 * time.Second, false},
{"5s", 5 * time.Second, false},
{"30", 0, true},
} {
t.Run(row.composed, func(t *testing.T) {
t.Setenv("MESH_CONFIG_DRAIN_BOUND", row.composed)
got, err := drainBoundSetting()
if row.refused {
if err == nil || !strings.Contains(err.Error(), "drain-bound") {
t.Errorf("drain-bound %q read %s, %v; want it refused by name", row.composed, got, err)
}
if err := serve(t.Context()); err == nil || !strings.Contains(err.Error(), "drain-bound") {
t.Errorf("the runner with drain-bound %q served (%v); want it stopped before it serves", row.composed, err)
}
return
}
if err != nil || got != row.want {
t.Errorf("drain-bound %q read %s, %v; want %s", row.composed, got, err, row.want)
}
})
}
}
@@ -112,9 +112,8 @@ func TestTheToolRunnerStartedByItsEntryServesABundleOverTheSeatListItReads(t *te
journal := &said{}
log.SetOutput(journal)
t.Cleanup(func() { log.SetOutput(os.Stderr) })
savedBound := drainBound
drainBound = 2 * time.Second
t.Cleanup(func() { drainBound = savedBound })
// the setting drain-bound as the node-engine composes it (H-A-370, H-A-377)
t.Setenv("MESH_CONFIG_DRAIN_BOUND", "2s")
ctx, stop := context.WithCancel(context.Background())
ended := make(chan error, 1)
+6 -3
View File
@@ -7,9 +7,12 @@ import (
"time"
)
// DefaultDrainBound is how long the tool runner, once told to stop, waits for the calls in flight in its bundles to finish:
// the setting drain-bound's default (design 47 H2 §813 (12), H-A-342 (2)).
const DefaultDrainBound = 30 * time.Second
// DrainBoundSetting is the tool runner module's setting of how long, once told to stop, it waits for the calls in flight in its
// bundles to finish, a duration text; DefaultDrainBound is its default (design 47 H2 §813 (12), H-A-342 (2), H-A-377).
const (
DrainBoundSetting = "drain-bound"
DefaultDrainBound = 30 * time.Second
)
// inFlight is one ask the runner made of a bundle and is still waiting on: the bundle, the verb (a tool's name, else the
// method), when it was asked, and closed when the drain cuts it.