diff --git a/modules/mesh-build-go/cmd/mesh-build-go/integration_level_test.go b/modules/mesh-build-go/cmd/mesh-build-go/integration_level_test.go index 8a791627..aa1cba11 100644 --- a/modules/mesh-build-go/cmd/mesh-build-go/integration_level_test.go +++ b/modules/mesh-build-go/cmd/mesh-build-go/integration_level_test.go @@ -6,6 +6,7 @@ import ( "net/url" "os" "path/filepath" + "slices" "strings" "sync" "testing" @@ -345,14 +346,7 @@ func TestAStoreThatDoesNotStartEndsTheStepFailedAndLeavesNothing(t *testing.T) { if f.busDir != "" && !f.busDown { t.Errorf("the bus, started beside the store, was not stopped after the store failed") } - var left []string - entries, _ := os.ReadDir(filepath.Join(m.Work, "ws1")) - for _, e := range entries { - if e.Name() != "slots" { // the ask's bound on processes, gone with the workspace (issue 1921, S10) - left = append(left, e.Name()) - } - } - if len(left) != 1 || left[0] != "tree" { + if left := workspaceLeft(filepath.Join(m.Work, "ws1")); len(left) != 1 || left[0] != "tree" { t.Errorf("the workspace holds %v, want only its tree", left) } } @@ -534,3 +528,16 @@ func TestTheIntegrationLevelRunsOnlyTheTestsItsTagsAdd(t *testing.T) { t.Errorf("a tree with no tagged test started the store or ran go:\n%s", g.lines()) } } + +// workspaceLeft is what a workspace holds besides the directories its ask keeps there (askDirs: its cache layer and its +// bound on processes, gone with the workspace; issue 1921, S2 and S10). +func workspaceLeft(dir string) []string { + var left []string + entries, _ := os.ReadDir(dir) + for _, e := range entries { + if !slices.Contains(askDirs, e.Name()) { + left = append(left, e.Name()) + } + } + return left +} diff --git a/modules/mesh-build-go/cmd/mesh-build-go/slots.go b/modules/mesh-build-go/cmd/mesh-build-go/slots.go index 4c44d730..eca8a227 100644 --- a/modules/mesh-build-go/cmd/mesh-build-go/slots.go +++ b/modules/mesh-build-go/cmd/mesh-build-go/slots.go @@ -16,6 +16,13 @@ import ( "syscall" ) +// slotsDir is the directory in a workspace's root holding its slots. +const slotsDir = "slots" + +// askDirs are the directories an ask keeps in its workspace's root beside its tree, gone with the workspace: its cache +// layer and its bound on processes. +var askDirs = []string{cacheLayerDir, slotsDir} + // numCPU is the node's processor count. func numCPU() int { return runtime.NumCPU() } @@ -31,7 +38,7 @@ var slotTurns atomic.Uint32 // slots is the bound of the workspace's processes, m.parallel() slots. func (m *Module) slots(workspace string) slotPool { - return slotPool{dir: filepath.Join(m.Work, workspace, "slots"), n: m.parallel(), next: &slotTurns} + return slotPool{dir: filepath.Join(m.Work, workspace, slotsDir), n: m.parallel(), next: &slotTurns} } // acquire takes a slot of the pool, waiting for one when every slot is taken, and answers what frees it. A free slot is diff --git a/modules/mesh-build-go/cmd/mesh-build-go/test_real_integration_test.go b/modules/mesh-build-go/cmd/mesh-build-go/test_real_integration_test.go index 05175e99..e9377ec3 100644 --- a/modules/mesh-build-go/cmd/mesh-build-go/test_real_integration_test.go +++ b/modules/mesh-build-go/cmd/mesh-build-go/test_real_integration_test.go @@ -161,9 +161,8 @@ func TestIntegrationLevelRunsAgainstARealStoreAndBusAndLeavesNothing(t *testing. if !res.Passed || res.Tests != 1 || res.Setup <= 0 || res.Setup > IntegrationSetup.Seconds() { t.Errorf("result = %+v", res) } - entries, _ := os.ReadDir(filepath.Join(work, "ws1")) - if len(entries) != 1 || entries[0].Name() != "tree" { - t.Errorf("the workspace holds %v, want only its tree: the run directory is gone", entries) + if left := workspaceLeft(filepath.Join(work, "ws1")); len(left) != 1 || left[0] != "tree" { + t.Errorf("the workspace holds %v besides the ask's own directories, want only its tree: the run directory is gone", left) } for deadline := time.Now().Add(5 * time.Second); len(processesNamed(work)) > 0 && time.Now().Before(deadline); time.Sleep(100 * time.Millisecond) { }