diff --git a/modules/mesh-build-node/cmd/mesh-build-node/check.go b/modules/mesh-build-node/cmd/mesh-build-node/check.go index 8f4a6ec57..61f739b96 100644 --- a/modules/mesh-build-node/cmd/mesh-build-node/check.go +++ b/modules/mesh-build-node/cmd/mesh-build-node/check.go @@ -37,16 +37,30 @@ const ( // test helpers take a setup bound of half of it. const LevelBoundEnv = "MESH_TEST_LEVEL_BOUND" -// levelBound is a level's bound. -func levelBound(level string) time.Duration { +// levelBound is a level's bound while inHand steps are in hand (design 47 H2 H-A-488): its default that many times. +func levelBound(level string, inHand int) time.Duration { if level == "unit" { - return UnitBound + return UnitBound * time.Duration(inHand) } - return IntegrationRunBound + return IntegrationRunBound * time.Duration(inHand) } // integrationSetupBound is the integration level's setup bound: half of its bound (§800). -func integrationSetupBound() time.Duration { return IntegrationRunBound / 2 } +func integrationSetupBound(inHand int) time.Duration { return levelBound("integration", inHand) / 2 } + +// stepsInHand is how many steps the seat has in hand at a step's start, this one counted, at least 1 (design 47 H2 +// H-A-488): a level's bounds are their defaults that many times, so a level set up slowly on a build node running +// several steps at once is not a failure. +func (m *Module) stepsInHand() int { + n := 0 + switch { + case m.inHand != nil: + n = m.inHand() + case m.Held != nil: + n = m.Held.InHand() + } + return max(1, n) +} // TestResult is what a test step passes with, with the field names of mesh-build-go's (issue 1290). The step ends // passed whenever the level ran, whatever its verdict, and Passed is the verdict; it ends failed only when the tests @@ -146,6 +160,8 @@ func (m *Module) testLevel(ctx context.Context, args map[string]any) (*TestResul return nil, err } res := &TestResult{Workspace: workspace, Module: module, Level: level, By: sdkstep.By("mesh-build-node")} + // The level's bounds, read once at the step's start (H-A-488): the result's bound and setup_bound name them. + inHand := m.stepsInHand() script := "test" if level == "integration" { script = "test:integration" @@ -213,7 +229,7 @@ func (m *Module) testLevel(ctx context.Context, args map[string]any) (*TestResul report := filepath.Join(root, ".mesh-node-test-"+level+".tap") _ = os.Remove(report) env := []string{"PATH=" + binDir(root) + ":" + pathOrDefault(), "npm_config_cache=" + filepath.Join(m.Toolchain.Paths.Cache, "npm"), - "NODE_OPTIONS=" + steprun.NodeTestOptions(report), LevelBoundEnv + "=" + levelBound(level).String()} + "NODE_OPTIONS=" + steprun.NodeTestOptions(report), LevelBoundEnv + "=" + levelBound(level, inHand).String()} r := m.runIn(ctx, root, false, tg.dir, env, "npm", scriptArgs(script)...) run += m.now().Sub(start) tap, _ := os.ReadFile(report) @@ -238,19 +254,20 @@ func (m *Module) testLevel(ctx context.Context, args map[string]any) (*TestResul why = append(why, failureWhy(f)) } if level == "unit" { - res.Elapsed, res.Bound = (check + run).Seconds(), UnitBound.Seconds() - res.OverBound = check+run > UnitBound + bound := levelBound(level, inHand) + res.Elapsed, res.Bound = (check + run).Seconds(), bound.Seconds() + res.OverBound = check+run > bound if res.OverBound { - why = append(why, fmt.Sprintf("the unit level took %.2f s, over its bound of %s", res.Elapsed, UnitBound)) + why = append(why, fmt.Sprintf("the unit level took %.2f s, over its bound of %s", res.Elapsed, bound)) } } else { res.Setup, res.Elapsed = check.Seconds(), run.Seconds() - setup := integrationSetupBound() - res.SetupBound, res.Bound = setup.Seconds(), IntegrationRunBound.Seconds() - res.OverBound = check > setup || run > IntegrationRunBound + setup, bound := integrationSetupBound(inHand), levelBound(level, inHand) + res.SetupBound, res.Bound = setup.Seconds(), bound.Seconds() + res.OverBound = check > setup || run > bound if res.OverBound { why = append(why, fmt.Sprintf("the integration level took %.2f s of setup and %.2f s of running, over its bounds of %s and %s", - res.Setup, res.Elapsed, setup, IntegrationRunBound)) + res.Setup, res.Elapsed, setup, bound)) } } res.Passed = len(failed) == 0 diff --git a/modules/mesh-build-node/cmd/mesh-build-node/check_test.go b/modules/mesh-build-node/cmd/mesh-build-node/check_test.go index 144e38a0f..61a196003 100644 --- a/modules/mesh-build-node/cmd/mesh-build-node/check_test.go +++ b/modules/mesh-build-node/cmd/mesh-build-node/check_test.go @@ -140,6 +140,17 @@ func TestTheIntegrationLevelRunsItsScriptAndReportsSetupAndRunningApart(t *testi if !out.(*TestResult).OverBound { t.Errorf("61 s of running is within the bound") } + // Design 47 H2 H-A-488: with four steps in hand at the step's start, the bounds are four times their defaults: the + // script gets 240 s as its level's bound, 40 s of setup is within its 120 s, and the result names both. + f.cost["tsc"], f.cost["npm"] = 40*time.Second, 61*time.Second + m.inHand = func() int { return 4 } + out, _ = m.test(context.Background(), testArgs("integration")) + if r := out.(*TestResult); r.OverBound || r.Bound != 240 || r.SetupBound != 120 { + t.Errorf("40 s of setup and 61 s of running with four steps in hand: %+v", r) + } + if last := f.calls[len(f.calls)-1]; !slices.Contains(last.env, "MESH_TEST_LEVEL_BOUND=4m0s") { + t.Errorf("with four steps in hand the integration script ran with %v, not MESH_TEST_LEVEL_BOUND=4m0s", last.env) + } } // The commands of a step get an environment built from scratch: no word of this process's, the level's bound alone (§800). diff --git a/modules/mesh-build-node/cmd/mesh-build-node/module.go b/modules/mesh-build-node/cmd/mesh-build-node/module.go index b121d41fd..3104d7317 100644 --- a/modules/mesh-build-node/cmd/mesh-build-node/module.go +++ b/modules/mesh-build-node/cmd/mesh-build-node/module.go @@ -107,6 +107,8 @@ type Module struct { // when set, answers it instead (a test). Settings string Capacity func() int + // inHand answers how many steps the seat has in hand in place of Held's (a test's; design 47 H2 H-A-488). + inHand func() int spacesOnce sync.Once workspaces *steprun.Workspaces