The operator's desktop slows while it builds: the Go build runtime took 1650% of shanks' 24 processors with nothing holding it back. A build seat's holder now runs its runtime at idle priority under its node's cpu-cap share (declaration Yields, composed from Seat.Yields and the module's cpu-cap setting), and buildcpu/buildstep give each step its part of that cap in threads.
55 lines
2.1 KiB
Go
55 lines
2.1 KiB
Go
package buildstep
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
// 1887/A7: the node's build capacity is the build module's setting, read at every pull: the control-node at 0 pulls
|
|
// nothing, a change takes effect at the next read, and a setting that cannot be read pulls nothing.
|
|
func TestNodeCapacity(t *testing.T) {
|
|
if got := NodeCapacity("", DefaultCapacities, "novox", nil)(); got != 0 {
|
|
t.Errorf("novox = %d by default, want 0", got)
|
|
}
|
|
if got := NodeCapacity("", DefaultCapacities, "shanks", nil)(); got != 3 {
|
|
t.Errorf("shanks = %d by default, want 3", got)
|
|
}
|
|
file := filepath.Join(t.TempDir(), "settings.json")
|
|
os.WriteFile(file, []byte(`{"capacity":"shanks=1,ace=2"}`), 0o600)
|
|
capacity := NodeCapacity(file, DefaultCapacities, "shanks", nil)
|
|
if got := capacity(); got != 1 {
|
|
t.Errorf("shanks = %d from the file, want 1", got)
|
|
}
|
|
os.WriteFile(file, []byte(`{"capacity":"shanks=4"}`), 0o600)
|
|
if got := capacity(); got != 4 {
|
|
t.Errorf("shanks = %d after the change, want 4", got)
|
|
}
|
|
if got := NodeCapacity(file, "", "pi", nil)(); got != 1 {
|
|
t.Errorf("a node not named = %d, want 1", got)
|
|
}
|
|
os.WriteFile(file, []byte(`{"capacity":"shanks=lots"}`), 0o600)
|
|
if got := capacity(); got != 0 {
|
|
t.Errorf("an unreadable setting = %d, want 0", got)
|
|
}
|
|
if got := NodeCapacity(filepath.Join(t.TempDir(), "none"), DefaultCapacities, "shanks", nil)(); got != 0 {
|
|
t.Errorf("a missing file = %d, want 0", got)
|
|
}
|
|
}
|
|
|
|
// Issue 1806: a step's limits come from the cap in the same settings file, read at every call; a cap that cannot be
|
|
// read still bounds the step, at the default.
|
|
func TestNodeLimits(t *testing.T) {
|
|
file := filepath.Join(t.TempDir(), "settings.json")
|
|
os.WriteFile(file, []byte(`{"capacity":"shanks=3","cpu-cap":"shanks=25"}`), 0o600)
|
|
if l := NodeLimits(file, "shanks", 3, nil); l.Percent != 25 || l.Slots != 3 || l.Threads < 1 {
|
|
t.Errorf("from the file: %+v", l)
|
|
}
|
|
for _, body := range []string{`{"capacity":"shanks=3"}`, `{"cpu-cap":"shanks=0"}`, `not json`} {
|
|
os.WriteFile(file, []byte(body), 0o600)
|
|
if l := NodeLimits(file, "shanks", 1, nil); l.Percent != 50 {
|
|
t.Errorf("%s gives %d%%, want the default 50", body, l.Percent)
|
|
}
|
|
}
|
|
}
|