From 9afbd3575950e2fd0ce576d937e0350fb5890704 Mon Sep 17 00:00:00 2001 From: jochen Date: Sun, 22 Nov 2026 01:18:06 +0100 Subject: [PATCH] NP1: the NFS server and package manager modules' tests fold into one test per file, within 50 as the check counts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The check counts every test the integration level runs, untagged ones in: the NFS server module held 51 and the package manager module 121, over the budget of 50. Each folded file's tests run in order as rows of one test that keeps the first one's name and logs each case before it runs; the root helper's test sockets are numbered per call, as one test now holds several listeners, and the case that skips without pacman-conf runs last. Counts now 48 and 42. Builds: design 47 H2 §819; H-A-349 DQ-14 --- .../cmd/nfs-server/reconcile_test.go | 25 +++++++-- .../cmd/pacman-tools/aftercheck_test.go | 28 ++++++++-- modules/pacman/cmd/pacman-tools/dkms_test.go | 28 ++++++++-- .../cmd/pacman-tools/keeper_manifest_test.go | 31 ++++++++-- .../pacman/cmd/pacman-tools/keeper_test.go | 34 ++++++++--- .../pacman/cmd/pacman-tools/manifest_test.go | 32 +++++++++-- .../pacman/cmd/pacman-tools/pacman_test.go | 52 ++++++++++++----- .../pacman/cmd/pacman-tools/rollback_test.go | 28 ++++++++-- modules/pacman/cmd/pacman-tools/root_test.go | 56 ++++++++++++++----- .../pacman/cmd/pacman-tools/rounds_test.go | 31 ++++++++-- modules/pacman/cmd/pacman-tools/runs_test.go | 31 ++++++++-- .../cmd/pacman-tools/transaction_test.go | 40 ++++++++++--- .../cmd/pacman-tools/upgrade_health_test.go | 37 +++++++++--- modules/pacman/cmd/pacman-tools/view_test.go | 28 ++++++++-- 14 files changed, 382 insertions(+), 99 deletions(-) diff --git a/modules/nfs-server/cmd/nfs-server/reconcile_test.go b/modules/nfs-server/cmd/nfs-server/reconcile_test.go index d6be1ada7..94194c704 100644 --- a/modules/nfs-server/cmd/nfs-server/reconcile_test.go +++ b/modules/nfs-server/cmd/nfs-server/reconcile_test.go @@ -21,7 +21,7 @@ func countExportfs(ran []string) int { // and the kernel still exported the refused folder while the module said it was healthy. A failed reload // is tried again on the next pass, and while the kernel exports anything of the module's that the file no // longer carries, the module is unhealthy and says what. -func TestARefusalWhoseReloadFailedIsReloadedAgainAndIsUnhealthyUntilItIs(t *testing.T) { +func testARefusalWhoseReloadFailedIsReloadedAgainAndIsUnhealthyUntilItIs(t *testing.T) { f := newFake(t) f.mountinfo("/", "/srv/pool") f.dir("/srv/pool") @@ -72,7 +72,7 @@ func TestARefusalWhoseReloadFailedIsReloadedAgainAndIsUnhealthyUntilItIs(t *test // that never happened — is reconciled: the first pass always reloads, a later pass reloads when the kernel // exports one of the module's folders to a client the file no longer has, and the module is unhealthy // while it cannot. -func TestAWithdrawnGrantIsTakenFromTheKernel(t *testing.T) { +func testAWithdrawnGrantIsTakenFromTheKernel(t *testing.T) { f := newFake(t) f.mountinfo("/", "/srv/library") f.dir("/srv/library") @@ -122,7 +122,7 @@ func TestAWithdrawnGrantIsTakenFromTheKernel(t *testing.T) { // The review of #142: SIGTERM in the middle of a pass on a plain restart (the config is still there) ends // the pass, and the exports stay: the export file is unchanged and the kernel's table keeps the share. -func TestSIGTERMDuringAPassOnARestartLeavesTheExports(t *testing.T) { +func testSIGTERMDuringAPassOnARestartLeavesTheExports(t *testing.T) { f := newFake(t) f.mountinfo("/", "/srv/library") f.dir("/srv/library") @@ -173,7 +173,7 @@ func TestSIGTERMDuringAPassOnARestartLeavesTheExports(t *testing.T) { // unassignment then stops it with the config still there. The node-engine disables a process's unit before // it stops it (`systemctl disable --now`), and a restart or a shutdown leaves it enabled, so a process // whose own unit is disabled when it is stopped is being taken away, whatever the config says. -func TestAProcessWhoseUnitIsDisabledAtStopCleansUpWithTheConfigStillThere(t *testing.T) { +func testAProcessWhoseUnitIsDisabledAtStopCleansUpWithTheConfigStillThere(t *testing.T) { f := newFake(t) f.mountinfo("/", "/srv/library") f.dir("/srv/library") @@ -199,3 +199,20 @@ func TestAProcessWhoseUnitIsDisabledAtStopCleansUpWithTheConfigStillThere(t *tes t.Errorf("the kernel still exports the library after an unassignment with the config in place: %q", f.read(Etab)) } } + +// TestARefusalWhoseReloadFailedIsReloadedAgainAndIsUnhealthyUntilItIs runs this file's cases in order as one test, each a row: the check counts every top-level test against the +// module's budget of 50 (design 47 H2 §819). A failing case is named by the line logged before it. +func TestARefusalWhoseReloadFailedIsReloadedAgainAndIsUnhealthyUntilItIs(t *testing.T) { + for _, c := range []struct { + name string + run func(*testing.T) + }{ + {"TestARefusalWhoseReloadFailedIsReloadedAgainAndIsUnhealthyUntilItIs", testARefusalWhoseReloadFailedIsReloadedAgainAndIsUnhealthyUntilItIs}, + {"TestAWithdrawnGrantIsTakenFromTheKernel", testAWithdrawnGrantIsTakenFromTheKernel}, + {"TestSIGTERMDuringAPassOnARestartLeavesTheExports", testSIGTERMDuringAPassOnARestartLeavesTheExports}, + {"TestAProcessWhoseUnitIsDisabledAtStopCleansUpWithTheConfigStillThere", testAProcessWhoseUnitIsDisabledAtStopCleansUpWithTheConfigStillThere}, + } { + t.Logf("case %s", c.name) + c.run(t) + } +} diff --git a/modules/pacman/cmd/pacman-tools/aftercheck_test.go b/modules/pacman/cmd/pacman-tools/aftercheck_test.go index 5410f8bb6..9b4d80f3d 100644 --- a/modules/pacman/cmd/pacman-tools/aftercheck_test.go +++ b/modules/pacman/cmd/pacman-tools/aftercheck_test.go @@ -74,7 +74,7 @@ func checkUpgrades(t *testing.T, m *Machine) *Upgrades { return &Upgrades{Node: "node-a", Machine: m, Runs: runs} } -func TestTheCheckNamesTheFilesTheTransactionLeftAndTheNewsSinceThePreviousUpgrade(t *testing.T) { +func testTheCheckNamesTheFilesTheTransactionLeftAndTheNewsSinceThePreviousUpgrade(t *testing.T) { u := checkUpgrades(t, checkMachine("", "7.2.8-arch1-2")) c := u.AfterCheck(checkedRun(StepStarted, StepFinished), &Record{}) if strings.Join(c.Pacnew, " ") != "/etc/pacman.d/mirrorlist.pacnew" || strings.Join(c.Pacsave, " ") != "/etc/lemurs/config.toml.pacsave" { @@ -88,7 +88,7 @@ func TestTheCheckNamesTheFilesTheTransactionLeftAndTheNewsSinceThePreviousUpgrad } } -func TestNewsThatCannotBeReadIsSaidNotShownAsNone(t *testing.T) { +func testNewsThatCannotBeReadIsSaidNotShownAsNone(t *testing.T) { u := checkUpgrades(t, checkMachine("", "7.2.8-arch1-2")) fetch = func(string) ([]byte, error) { return nil, errors.New("no route to host") } c := u.AfterCheck(checkedRun(StepStarted, StepFinished), &Record{}) @@ -97,7 +97,7 @@ func TestNewsThatCannotBeReadIsSaidNotShownAsNone(t *testing.T) { } } -func TestAUnitNewlyFailedFailsTheCheckAndOneFailedBeforeDoesNot(t *testing.T) { +func testAUnitNewlyFailedFailsTheCheckAndOneFailedBeforeDoesNot(t *testing.T) { u := checkUpgrades(t, checkMachine("backup.service loaded failed failed The backup\nweb.service loaded failed failed The web\n", "7.2.8-arch1-2")) c := u.AfterCheck(checkedRun(StepStarted, StepFinished), &Record{FailedUnits: []string{"backup.service"}}) if strings.Join(c.NewlyFailed, " ") != "web.service" || c.Passed { @@ -105,7 +105,7 @@ func TestAUnitNewlyFailedFailsTheCheckAndOneFailedBeforeDoesNot(t *testing.T) { } } -func TestARestartIsNeededWhenTheRunningKernelIsNoLongerTheInstalledOne(t *testing.T) { +func testARestartIsNeededWhenTheRunningKernelIsNoLongerTheInstalledOne(t *testing.T) { u := checkUpgrades(t, checkMachine("", "7.2.9-arch1-1")) c := u.AfterCheck(checkedRun(StepStarted, StepFinished), &Record{}) if !c.RestartNeeded || c.InstalledKernel != "7.2.9-arch1-1" || !c.Passed { @@ -113,9 +113,27 @@ func TestARestartIsNeededWhenTheRunningKernelIsNoLongerTheInstalledOne(t *testin } } -func TestTheCheckPassesOnlyWhenTheTransactionSucceeded(t *testing.T) { +func testTheCheckPassesOnlyWhenTheTransactionSucceeded(t *testing.T) { u := checkUpgrades(t, checkMachine("", "7.2.8-arch1-2")) if c := u.AfterCheck(checkedRun(StepStarted, StepFailed), &Record{}); c.Passed { t.Errorf("%+v", c) } } + +// TestTheCheckNamesTheFilesTheTransactionLeftAndTheNewsSinceThePreviousUpgrade runs this file's cases in order as one test, each a row: the check counts every top-level test against the +// module's budget of 50 (design 47 H2 §819). A failing case is named by the line logged before it. +func TestTheCheckNamesTheFilesTheTransactionLeftAndTheNewsSinceThePreviousUpgrade(t *testing.T) { + for _, c := range []struct { + name string + run func(*testing.T) + }{ + {"TestTheCheckNamesTheFilesTheTransactionLeftAndTheNewsSinceThePreviousUpgrade", testTheCheckNamesTheFilesTheTransactionLeftAndTheNewsSinceThePreviousUpgrade}, + {"TestNewsThatCannotBeReadIsSaidNotShownAsNone", testNewsThatCannotBeReadIsSaidNotShownAsNone}, + {"TestAUnitNewlyFailedFailsTheCheckAndOneFailedBeforeDoesNot", testAUnitNewlyFailedFailsTheCheckAndOneFailedBeforeDoesNot}, + {"TestARestartIsNeededWhenTheRunningKernelIsNoLongerTheInstalledOne", testARestartIsNeededWhenTheRunningKernelIsNoLongerTheInstalledOne}, + {"TestTheCheckPassesOnlyWhenTheTransactionSucceeded", testTheCheckPassesOnlyWhenTheTransactionSucceeded}, + } { + t.Logf("case %s", c.name) + c.run(t) + } +} diff --git a/modules/pacman/cmd/pacman-tools/dkms_test.go b/modules/pacman/cmd/pacman-tools/dkms_test.go index 1c3961381..ca3124570 100644 --- a/modules/pacman/cmd/pacman-tools/dkms_test.go +++ b/modules/pacman/cmd/pacman-tools/dkms_test.go @@ -9,7 +9,7 @@ import ( "testing" ) -func TestTheNewKernelsReleaseIsDerivedAsTheInstalledOnesIs(t *testing.T) { +func testTheNewKernelsReleaseIsDerivedAsTheInstalledOnesIs(t *testing.T) { for _, c := range [][4]string{ {"7.2.8.arch1-2", "7.2.8-arch1-2", "7.3.1.arch1-1", "7.3.1-arch1-1"}, {"6.18.54-2", "6.18.54-2-lts", "6.18.60-1", "6.18.60-1-lts"}, @@ -72,7 +72,7 @@ func gateUpgrades(t *testing.T, m *Machine, linuxTo string, reachable bool) *Upg const zfsStatus = "zfs/2.4.4, 7.2.8-arch1-2, x86_64: installed\nzfs/2.4.4, 6.18.54-2-lts, x86_64: installed\n" -func TestAKernelPastAModulesLinuxMaximumIsHeldWithItsHeaders(t *testing.T) { +func testAKernelPastAModulesLinuxMaximumIsHeldWithItsHeaders(t *testing.T) { u := gateUpgrades(t, gateMachine(t, zfsStatus, capturedZFSSource(t)), "7.3.1.arch1-1", true) held, ignore, why := u.Gate() if why != "" { @@ -86,14 +86,14 @@ func TestAKernelPastAModulesLinuxMaximumIsHeldWithItsHeaders(t *testing.T) { } } -func TestAKernelWithinTheBoundIsNotHeld(t *testing.T) { +func testAKernelWithinTheBoundIsNotHeld(t *testing.T) { u := gateUpgrades(t, gateMachine(t, zfsStatus, capturedZFSSource(t)), "7.2.9.arch1-1", true) if held, ignore, why := u.Gate(); why != "" || len(held) != 0 || len(ignore) != 0 { t.Errorf("%+v %v %q", held, ignore, why) } } -func TestABuildExclusivePatternHoldsTheKernelsItDoesNotMatch(t *testing.T) { +func testABuildExclusivePatternHoldsTheKernelsItDoesNotMatch(t *testing.T) { src := map[string]string{"/usr/src/made-up-driver-1.0/dkms.conf": "PACKAGE_NAME=\"made-up-driver\"\nBUILD_EXCLUSIVE_KERNEL=\"^(6\\.|7\\.[0-2]\\.)\"\n"} u := gateUpgrades(t, gateMachine(t, "made-up-driver/1.0, 7.2.8-arch1-2, x86_64: installed\n", src), "7.3.1.arch1-1", true) held, ignore, why := u.Gate() @@ -103,7 +103,7 @@ func TestABuildExclusivePatternHoldsTheKernelsItDoesNotMatch(t *testing.T) { } } -func TestNoRunWhenWhatTheUpgradeWouldChangeIsNotKnown(t *testing.T) { +func testNoRunWhenWhatTheUpgradeWouldChangeIsNotKnown(t *testing.T) { u := gateUpgrades(t, gateMachine(t, zfsStatus, capturedZFSSource(t)), "7.3.1.arch1-1", false) if _, _, why := u.Gate(); !strings.Contains(why, "could not reach its mirrors") { t.Errorf("unreachable: %q", why) @@ -113,3 +113,21 @@ func TestNoRunWhenWhatTheUpgradeWouldChangeIsNotKnown(t *testing.T) { t.Errorf("no updates key: %q", why) } } + +// TestTheNewKernelsReleaseIsDerivedAsTheInstalledOnesIs runs this file's cases in order as one test, each a row: the check counts every top-level test against the +// module's budget of 50 (design 47 H2 §819). A failing case is named by the line logged before it. +func TestTheNewKernelsReleaseIsDerivedAsTheInstalledOnesIs(t *testing.T) { + for _, c := range []struct { + name string + run func(*testing.T) + }{ + {"TestTheNewKernelsReleaseIsDerivedAsTheInstalledOnesIs", testTheNewKernelsReleaseIsDerivedAsTheInstalledOnesIs}, + {"TestAKernelPastAModulesLinuxMaximumIsHeldWithItsHeaders", testAKernelPastAModulesLinuxMaximumIsHeldWithItsHeaders}, + {"TestAKernelWithinTheBoundIsNotHeld", testAKernelWithinTheBoundIsNotHeld}, + {"TestABuildExclusivePatternHoldsTheKernelsItDoesNotMatch", testABuildExclusivePatternHoldsTheKernelsItDoesNotMatch}, + {"TestNoRunWhenWhatTheUpgradeWouldChangeIsNotKnown", testNoRunWhenWhatTheUpgradeWouldChangeIsNotKnown}, + } { + t.Logf("case %s", c.name) + c.run(t) + } +} diff --git a/modules/pacman/cmd/pacman-tools/keeper_manifest_test.go b/modules/pacman/cmd/pacman-tools/keeper_manifest_test.go index 658c1e7da..7576e9bd2 100644 --- a/modules/pacman/cmd/pacman-tools/keeper_manifest_test.go +++ b/modules/pacman/cmd/pacman-tools/keeper_manifest_test.go @@ -40,7 +40,7 @@ func strs(v any) []string { return out } -func TestTheWeeklyTimerAndItsServiceAreGone(t *testing.T) { +func testTheWeeklyTimerAndItsServiceAreGone(t *testing.T) { m := manifest(t) for _, r := range m.Resources { id, _ := r["id"].(string) @@ -58,7 +58,7 @@ func TestTheWeeklyTimerAndItsServiceAreGone(t *testing.T) { } } -func TestTheKeeperIsAProcessUnderItsOwnAccountWithABusAccountOfItsOwn(t *testing.T) { +func testTheKeeperIsAProcessUnderItsOwnAccountWithABusAccountOfItsOwn(t *testing.T) { m := manifest(t) user := m.resource(t, "keeper-account") if user["type"] != "user" || user["name"] != "pacman-keeper" || user["shell"] != "/usr/bin/nologin" { @@ -95,7 +95,7 @@ func TestTheKeeperIsAProcessUnderItsOwnAccountWithABusAccountOfItsOwn(t *testing } } -func TestTheKeeperDeclaresTheModulesStatesAndEvents(t *testing.T) { +func testTheKeeperDeclaresTheModulesStatesAndEvents(t *testing.T) { raw := rawManifest(t) k := manifest(t).resource(t, "keeper") bus, _ := k["bus"].(map[string]any) @@ -152,7 +152,7 @@ func configValue(t *testing.T, key string) map[string]any { return v } -func TestTheConfigValuesLandInTheKeepersConfigFileWhichRestartsIt(t *testing.T) { +func testTheConfigValuesLandInTheKeepersConfigFileWhichRestartsIt(t *testing.T) { order := configValue(t, "upgrade-order") if order["type"] != "list" || order["trusted"] != true || order["predefined"] != "upgrade-order" || !reflect.DeepEqual(order["default"], []any{}) || order["required"] != nil { @@ -191,7 +191,7 @@ func TestTheConfigValuesLandInTheKeepersConfigFileWhichRestartsIt(t *testing.T) } } -func TestUpgradeOrderIsATrustedListOfTheMesh(t *testing.T) { +func testUpgradeOrderIsATrustedListOfTheMesh(t *testing.T) { raw, err := os.ReadFile(filepath.Join(moduleDir, "..", "..", "predefined.json")) if err != nil { t.Fatal(err) @@ -216,7 +216,7 @@ func TestUpgradeOrderIsATrustedListOfTheMesh(t *testing.T) { // never place "." or a placement by default: for this module both resolve under /var/lib/pacman, the package manager's // own database directory (issue 1841: the node-engine used it as found and reported it unhealthy, and wrote keeper.json // into it). What the keeper and its root helper keep there is still named through ${dir:state}. -func TestTheStateDirectoryIsOutsideThePackageManagersOwn(t *testing.T) { +func testTheStateDirectoryIsOutsideThePackageManagersOwn(t *testing.T) { m := rawManifest(t) resources, _ := m["resources"].([]any) var state map[string]any @@ -245,3 +245,22 @@ func TestTheStateDirectoryIsOutsideThePackageManagersOwn(t *testing.T) { } } } + +// TestTheWeeklyTimerAndItsServiceAreGone runs this file's cases in order as one test, each a row: the check counts every top-level test against the +// module's budget of 50 (design 47 H2 §819). A failing case is named by the line logged before it. +func TestTheWeeklyTimerAndItsServiceAreGone(t *testing.T) { + for _, c := range []struct { + name string + run func(*testing.T) + }{ + {"TestTheWeeklyTimerAndItsServiceAreGone", testTheWeeklyTimerAndItsServiceAreGone}, + {"TestTheKeeperIsAProcessUnderItsOwnAccountWithABusAccountOfItsOwn", testTheKeeperIsAProcessUnderItsOwnAccountWithABusAccountOfItsOwn}, + {"TestTheKeeperDeclaresTheModulesStatesAndEvents", testTheKeeperDeclaresTheModulesStatesAndEvents}, + {"TestTheConfigValuesLandInTheKeepersConfigFileWhichRestartsIt", testTheConfigValuesLandInTheKeepersConfigFileWhichRestartsIt}, + {"TestUpgradeOrderIsATrustedListOfTheMesh", testUpgradeOrderIsATrustedListOfTheMesh}, + {"TestTheStateDirectoryIsOutsideThePackageManagersOwn", testTheStateDirectoryIsOutsideThePackageManagersOwn}, + } { + t.Logf("case %s", c.name) + c.run(t) + } +} diff --git a/modules/pacman/cmd/pacman-tools/keeper_test.go b/modules/pacman/cmd/pacman-tools/keeper_test.go index 21ddf0946..beb9826d2 100644 --- a/modules/pacman/cmd/pacman-tools/keeper_test.go +++ b/modules/pacman/cmd/pacman-tools/keeper_test.go @@ -342,7 +342,7 @@ func installedOf(t *testing.T, s *fakeStore, key string) InstalledValue { // 1840/AC1: at the start every package is written with its version, its reason and its repository or foreign, // and written again only when it differs from the key. -func TestAtItsStartTheKeeperWritesEveryPackageOnlyWhenItDiffersFromTheKey(t *testing.T) { +func testAtItsStartTheKeeperWritesEveryPackageOnlyWhenItDiffersFromTheKey(t *testing.T) { db := &pacmanDB{sl: syncDBs, checkup: Ran{Status: 2}} db.set("glibc 2.42-1\nlinux 6.17.1-1\nyay 12.0-1\nzsh 5.9-1\n", "linux\nyay\nzsh\n") k, states, ev, _, _ := newTestKeeper(db) @@ -375,7 +375,7 @@ func TestAtItsStartTheKeeperWritesEveryPackageOnlyWhenItDiffersFromTheKey(t *tes // 1840/AC2: a transaction that adds, removes and changes packages is one package.changed naming the node and // exactly those; one that changes nothing writes and emits nothing; a lock held again waits for its release. -func TestAReleasedLockSaysExactlyWhatTheTransactionChangedOnce(t *testing.T) { +func testAReleasedLockSaysExactlyWhatTheTransactionChangedOnce(t *testing.T) { db := &pacmanDB{sl: syncDBs, checkup: Ran{Status: 2}} db.set("glibc 2.42-1\nlinux 6.17.1-1\nzsh 5.9-1\n", "linux\nzsh\n") k, states, ev, clock, _ := newTestKeeper(db) @@ -440,7 +440,7 @@ func bigDB(n int) string { // 1840/AC3: a value over the bus's cap is not written: the key keeps its last value and `.not-current` // holds the size and since when, written once; the next write that fits deletes it. -func TestAValueOverTheCapKeepsTheLastAndMarksTheNodeNotCurrent(t *testing.T) { +func testAValueOverTheCapKeepsTheLastAndMarksTheNodeNotCurrent(t *testing.T) { db := &pacmanDB{sl: syncDBs, checkup: Ran{Status: 2}} db.set("glibc 2.42-1\n", "") k, states, ev, clock, _ := newTestKeeper(db) @@ -483,7 +483,7 @@ func TestAValueOverTheCapKeepsTheLastAndMarksTheNodeNotCurrent(t *testing.T) { } // The mark goes too when the node's packages come back to what the key holds: the key is current again. -func TestTheMarkGoesWhenThePackagesComeBackToTheKey(t *testing.T) { +func testTheMarkGoesWhenThePackagesComeBackToTheKey(t *testing.T) { db := &pacmanDB{sl: syncDBs, checkup: Ran{Status: 2}} db.set("glibc 2.42-1\n", "") k, states, _, _, _ := newTestKeeper(db) @@ -501,7 +501,7 @@ func TestTheMarkGoesWhenThePackagesComeBackToTheKey(t *testing.T) { // The loop: a released lock is read, a hook runs after it with what it changed, a watched state's change reaches // its hook, and a wake comes at the time it asked. -func TestTheLoopRunsTheHooksOnItsOneGoroutine(t *testing.T) { +func testTheLoopRunsTheHooksOnItsOneGoroutine(t *testing.T) { db := &pacmanDB{sl: syncDBs, checkup: Ran{Status: 2}} db.set("glibc 2.42-1\n", "") k, states, _, clock, w := newTestKeeper(db) @@ -567,7 +567,7 @@ func waitFor(t *testing.T, mu *sync.Mutex, seen *[]string, want string) { } // The watch ending ends the keeper, loudly. -func TestTheKeeperStopsWhenTheWatchEnds(t *testing.T) { +func testTheKeeperStopsWhenTheWatchEnds(t *testing.T) { db := &pacmanDB{sl: syncDBs, checkup: Ran{Status: 2}} k, _, _, _, w := newTestKeeper(db) close(w.c) @@ -578,7 +578,7 @@ func TestTheKeeperStopsWhenTheWatchEnds(t *testing.T) { // The machine's watch: the lock deleted and the mirror list written or moved in are each a signal; anything else // in those directories is none. -func TestTheWatchSeesTheLockReleasedAndTheMirrorListRewritten(t *testing.T) { +func testTheWatchSeesTheLockReleasedAndTheMirrorListRewritten(t *testing.T) { lockDir, mirrorDir := t.TempDir(), t.TempDir() w, err := WatchMachine(lockDir, LockName, mirrorDir, MirrorName) if err != nil { @@ -628,3 +628,23 @@ func TestTheWatchSeesTheLockReleasedAndTheMirrorListRewritten(t *testing.T) { } } } + +// TestAtItsStartTheKeeperWritesEveryPackageOnlyWhenItDiffersFromTheKey runs this file's cases in order as one test, each a row: the check counts every top-level test against the +// module's budget of 50 (design 47 H2 §819). A failing case is named by the line logged before it. +func TestAtItsStartTheKeeperWritesEveryPackageOnlyWhenItDiffersFromTheKey(t *testing.T) { + for _, c := range []struct { + name string + run func(*testing.T) + }{ + {"TestAtItsStartTheKeeperWritesEveryPackageOnlyWhenItDiffersFromTheKey", testAtItsStartTheKeeperWritesEveryPackageOnlyWhenItDiffersFromTheKey}, + {"TestAReleasedLockSaysExactlyWhatTheTransactionChangedOnce", testAReleasedLockSaysExactlyWhatTheTransactionChangedOnce}, + {"TestAValueOverTheCapKeepsTheLastAndMarksTheNodeNotCurrent", testAValueOverTheCapKeepsTheLastAndMarksTheNodeNotCurrent}, + {"TestTheMarkGoesWhenThePackagesComeBackToTheKey", testTheMarkGoesWhenThePackagesComeBackToTheKey}, + {"TestTheLoopRunsTheHooksOnItsOneGoroutine", testTheLoopRunsTheHooksOnItsOneGoroutine}, + {"TestTheKeeperStopsWhenTheWatchEnds", testTheKeeperStopsWhenTheWatchEnds}, + {"TestTheWatchSeesTheLockReleasedAndTheMirrorListRewritten", testTheWatchSeesTheLockReleasedAndTheMirrorListRewritten}, + } { + t.Logf("case %s", c.name) + c.run(t) + } +} diff --git a/modules/pacman/cmd/pacman-tools/manifest_test.go b/modules/pacman/cmd/pacman-tools/manifest_test.go index 45cd3f68e..2aaafdee5 100644 --- a/modules/pacman/cmd/pacman-tools/manifest_test.go +++ b/modules/pacman/cmd/pacman-tools/manifest_test.go @@ -14,7 +14,7 @@ import ( "testing" ) -func TestItHoldsThePackageManagerSeatAndDeclaresItsPackage(t *testing.T) { +func testItHoldsThePackageManagerSeatAndDeclaresItsPackage(t *testing.T) { m := manifest(t) if len(m.Claims) != 1 || m.Claims[0]["name"] != "node-package-manager" || m.Claims[0]["scope"] != "node" || m.Claims[0]["serves"] != nil { t.Fatalf("claims: %v", m.Claims) @@ -34,7 +34,7 @@ func TestItHoldsThePackageManagerSeatAndDeclaresItsPackage(t *testing.T) { } } -func TestPacmanConfIsWholeTheUnionOfRepositoriesAndTheImprovedOptions(t *testing.T) { +func testPacmanConfIsWholeTheUnionOfRepositoriesAndTheImprovedOptions(t *testing.T) { f := manifest(t).resource(t, "config") content := templateText(t, f) if f["path"] != "/etc/pacman.conf" || f["into"] != nil || !strings.HasPrefix(content, MeshHeader) { @@ -79,7 +79,7 @@ func TestPacmanConfIsWholeTheUnionOfRepositoriesAndTheImprovedOptions(t *testing // Every repository of the shipped file reads the mirror list reflector writes, and the file pacman-conf proves reads // nothing of the machine: the unit level runs shut off (novox/hq ADR 0448), where /etc/pacman.d is not there // (issue 1891). -func TestTheProvenConfReadsNothingOfTheMachine(t *testing.T) { +func testTheProvenConfReadsNothingOfTheMachine(t *testing.T) { content := templateText(t, manifest(t).resource(t, "config")) if n := strings.Count(content, "Include = "+Mirrorlist+"\n"); n != 3 || strings.Count(content, "Include") != n { t.Fatalf("every repository reads %s, and nothing else is included: %d of 3\n%s", Mirrorlist, n, content) @@ -105,7 +105,7 @@ func provenConf(t *testing.T, content, dir string) string { return strings.ReplaceAll(content, "Include = "+Mirrorlist, "Include = "+list) } -func TestReflectorRanksWithTheModulesOptionsAndSavesNoList(t *testing.T) { +func testReflectorRanksWithTheModulesOptionsAndSavesNoList(t *testing.T) { content := templateText(t, manifest(t).resource(t, "mirrors")) opts := map[string]string{} for _, l := range strings.Split(content, "\n") { @@ -124,7 +124,7 @@ func TestReflectorRanksWithTheModulesOptionsAndSavesNoList(t *testing.T) { } } -func TestTheReflectorPackageIsDeclaredBeforeTheFileItShips(t *testing.T) { +func testTheReflectorPackageIsDeclaredBeforeTheFileItShips(t *testing.T) { order := map[string]int{} for i, r := range manifest(t).Resources { order[r["id"].(string)] = i @@ -136,7 +136,7 @@ func TestTheReflectorPackageIsDeclaredBeforeTheFileItShips(t *testing.T) { // TestThePackageManagersConfigIsDeclaredBeforeItsPackage holds design 42 zfs-owns-zfs §1 and A-26: the // apply stops at the first failure, and the package fails while its config file is missing. -func TestThePackageManagersConfigIsDeclaredBeforeItsPackage(t *testing.T) { +func testThePackageManagersConfigIsDeclaredBeforeItsPackage(t *testing.T) { order := map[string]int{} for i, r := range manifest(t).Resources { order[r["id"].(string)] = i @@ -145,3 +145,23 @@ func TestThePackageManagersConfigIsDeclaredBeforeItsPackage(t *testing.T) { t.Fatalf("the config file comes before the package: %v", order) } } + +// TestItHoldsThePackageManagerSeatAndDeclaresItsPackage runs this file's cases in order as one test, each a row: the check counts every top-level test against the +// module's budget of 50 (design 47 H2 §819). A failing case is named by the line logged before it; the case that +// skips where pacman-conf is not installed runs last, so its skip ends no other case. +func TestItHoldsThePackageManagerSeatAndDeclaresItsPackage(t *testing.T) { + for _, c := range []struct { + name string + run func(*testing.T) + }{ + {"TestItHoldsThePackageManagerSeatAndDeclaresItsPackage", testItHoldsThePackageManagerSeatAndDeclaresItsPackage}, + {"TestTheProvenConfReadsNothingOfTheMachine", testTheProvenConfReadsNothingOfTheMachine}, + {"TestReflectorRanksWithTheModulesOptionsAndSavesNoList", testReflectorRanksWithTheModulesOptionsAndSavesNoList}, + {"TestTheReflectorPackageIsDeclaredBeforeTheFileItShips", testTheReflectorPackageIsDeclaredBeforeTheFileItShips}, + {"TestThePackageManagersConfigIsDeclaredBeforeItsPackage", testThePackageManagersConfigIsDeclaredBeforeItsPackage}, + {"TestPacmanConfIsWholeTheUnionOfRepositoriesAndTheImprovedOptions", testPacmanConfIsWholeTheUnionOfRepositoriesAndTheImprovedOptions}, + } { + t.Logf("case %s", c.name) + c.run(t) + } +} diff --git a/modules/pacman/cmd/pacman-tools/pacman_test.go b/modules/pacman/cmd/pacman-tools/pacman_test.go index f980d2b5e..a93360bca 100644 --- a/modules/pacman/cmd/pacman-tools/pacman_test.go +++ b/modules/pacman/cmd/pacman-tools/pacman_test.go @@ -16,7 +16,7 @@ core/base-devel 1-2 (base-devel) Basic tools to build Arch Linux packages ` -func TestSearchReadsHeaderAndDescriptionAndWhatIsInstalled(t *testing.T) { +func testSearchReadsHeaderAndDescriptionAndWhatIsInstalled(t *testing.T) { f := ParseSearch(searchOut) if len(f) != 3 { t.Fatalf("%+v", f) @@ -32,7 +32,7 @@ func TestSearchReadsHeaderAndDescriptionAndWhatIsInstalled(t *testing.T) { } } -func TestASearchThatFindsNothingIsEmptyAndAFailureIsAnError(t *testing.T) { +func testASearchThatFindsNothingIsEmptyAndAFailureIsAnError(t *testing.T) { m := machine(fake(func(c call) Ran { return Ran{Status: 1} }, nil), 1000) r, err := m.Search("nothing", 50) if err != nil || r["count"] != 0 { @@ -54,7 +54,7 @@ Install Reason : Explicitly installed ` -func TestInfoReadsListsAsListsAndFallsBackToTheRepositories(t *testing.T) { +func testInfoReadsListsAsListsAndFallsBackToTheRepositories(t *testing.T) { p := ParseInfo(infoOut) if len(p) != 1 { t.Fatalf("%v", p) @@ -79,7 +79,7 @@ func TestInfoReadsListsAsListsAndFallsBackToTheRepositories(t *testing.T) { } } -func TestReadInstalledSaysWhyAndWhichRepositoryOrForeign(t *testing.T) { +func testReadInstalledSaysWhyAndWhichRepositoryOrForeign(t *testing.T) { m := machine(byLine(map[string]Ran{ "pacman -Q": {Stdout: "zsh 5.9-1\nglibc 2.42-1\nyay 12.0-1\n"}, "pacman -Qeq": {Stdout: "yay\nzsh\n"}, @@ -95,7 +95,7 @@ func TestReadInstalledSaysWhyAndWhichRepositoryOrForeign(t *testing.T) { } } -func TestOwnsAnswersNoOwnerAsAnAnswer(t *testing.T) { +func testOwnsAnswersNoOwnerAsAnAnswer(t *testing.T) { m := machine(byLine(map[string]Ran{ "pacman -Qo -- /usr/bin/zsh": {Stdout: "/usr/bin/zsh is owned by zsh 5.9.2-1\n"}, "pacman -Qo -- /etc/hostname": {Status: 1, Stderr: "error: No package owns /etc/hostname\n"}, @@ -115,7 +115,7 @@ func TestOwnsAnswersNoOwnerAsAnAnswer(t *testing.T) { } } -func TestUpdateListReadsCheckupdatesAndItsNothingToDo(t *testing.T) { +func testUpdateListReadsCheckupdatesAndItsNothingToDo(t *testing.T) { m := machine(byLine(map[string]Ran{"checkupdates": {Stdout: "zsh 5.9-1 -> 5.9-2\nlinux 6.1-1 -> 6.2-1\n"}}, nil), 1000) r, err := m.UpdateList() if err != nil || len(r) != 2 || r[0] != (VersionChange{"linux", "6.1-1", "6.2-1"}) { @@ -136,7 +136,7 @@ func lockless(m *Machine) *Machine { return m } -func TestAnUpgradesUnitIsReadBack(t *testing.T) { +func testAnUpgradesUnitIsReadBack(t *testing.T) { unit := "mesh-pacman-upgrade-1791115200" m := machine(byLine(map[string]Ran{ "systemctl show " + unit + " --no-pager --property=LoadState --property=ActiveState --property=SubState --property=Result --property=ExecMainStatus": {Stdout: "LoadState=loaded\nActiveState=failed\nSubState=failed\nResult=exit-code\nExecMainStatus=1\n"}, @@ -165,7 +165,7 @@ func orphanMachine(calls *[]call) *Machine { }, calls), 1000)) } -func TestRemovingOrphansTakesOnlyOrphansNamedOrAll(t *testing.T) { +func testRemovingOrphansTakesOnlyOrphansNamedOrAll(t *testing.T) { var calls []call m := orphanMachine(&calls) if _, err := m.RemoveOrphans(nil, false); err == nil || !strings.Contains(err.Error(), "name the orphans") { @@ -193,7 +193,7 @@ func TestRemovingOrphansTakesOnlyOrphansNamedOrAll(t *testing.T) { } } -func TestCacheSaysWhatCleaningWouldFreeAndCleansThroughSudo(t *testing.T) { +func testCacheSaysWhatCleaningWouldFreeAndCleansThroughSudo(t *testing.T) { var calls []call m := machine(fake(func(c call) Ran { switch c.String() { @@ -227,7 +227,7 @@ const pacmanLog = `[2026-09-24T17:47:36+0200] [PACMAN] starting full system upgr [2022-01-01 10:00] [ALPM] installed old (1-1) ` -func TestHistoryReadsTheLogSinceADayAndTheLastFullUpgrade(t *testing.T) { +func testHistoryReadsTheLogSinceADayAndTheLastFullUpgrade(t *testing.T) { m := machine(nil, 1000) m.ReadFile = func(p string) ([]byte, error) { return []byte(pacmanLog), nil } r, err := m.History("2026-09-01", "", "", 10) @@ -263,7 +263,7 @@ const feed = ` Old newshttps://example.org/news/b/oldMon, 01 Jun 2026 09:00:00 +0000 ` -func TestNewsSinceTheLastUpgrade(t *testing.T) { +func testNewsSinceTheLastUpgrade(t *testing.T) { items, err := ParseNews([]byte(feed), time.Date(2026, 9, 1, 0, 0, 0, 0, time.UTC)) if err != nil || len(items) != 1 || items[0].Title != "Manual intervention needed" || items[0].Summary != "Do this first ." { t.Fatalf("%+v %v", items, err) @@ -314,7 +314,7 @@ var rankedAt = time.Date(2026, 11, 1, 15, 0, 0, 0, time.UTC) // and never its --save; a ranking that fails or keeps none is no list. pacman_mirrors answers the shared list, its // ranker and age and whether this node's file matches it (the file as found when not); with refresh it asks this node's // keeper to rank again, refused while a round runs, naming it. -func TestTheMeshsMirrorListIsRankedFreshAndAnsweredWithThisNodesFile(t *testing.T) { +func testTheMeshsMirrorListIsRankedFreshAndAnsweredWithThisNodesFile(t *testing.T) { conf := "# comment\n--save /etc/pacman.d/mirrorlist\n--country Belgium,Netherlands\n--sort rate\n" if o := strings.Join(ReflectorOptions(conf), " "); o != "--country Belgium,Netherlands --sort rate" { t.Errorf("the options are %q", o) @@ -381,7 +381,7 @@ func TestTheMeshsMirrorListIsRankedFreshAndAnsweredWithThisNodesFile(t *testing. } } -func TestConfigIsReadAsPacmanConfResolvesIt(t *testing.T) { +func testConfigIsReadAsPacmanConfResolvesIt(t *testing.T) { c := ParseConf("[options]\nHoldPkg = pacman\nHoldPkg = glibc\nCheckSpace\nParallelDownloads = 5\n[core]\nUsage = All\nServer = https://a/core\nServer = https://b/core\n[extra]\nServer = https://a/extra\n") if len(c.Options["HoldPkg"]) != 2 || c.Options["ParallelDownloads"][0] != "5" || len(c.Repositories) != 2 || c.Repositories[0].Servers != 2 || c.Repositories[0].FirstServer != "https://a/core" { t.Fatalf("%+v", c) @@ -430,3 +430,29 @@ func checkFreshest(t *testing.T) { t.Errorf("unknown syncs not detected: %+v", r) } } + +// TestSearchReadsHeaderAndDescriptionAndWhatIsInstalled runs this file's cases in order as one test, each a row: the check counts every top-level test against the +// module's budget of 50 (design 47 H2 §819). A failing case is named by the line logged before it. +func TestSearchReadsHeaderAndDescriptionAndWhatIsInstalled(t *testing.T) { + for _, c := range []struct { + name string + run func(*testing.T) + }{ + {"TestSearchReadsHeaderAndDescriptionAndWhatIsInstalled", testSearchReadsHeaderAndDescriptionAndWhatIsInstalled}, + {"TestASearchThatFindsNothingIsEmptyAndAFailureIsAnError", testASearchThatFindsNothingIsEmptyAndAFailureIsAnError}, + {"TestInfoReadsListsAsListsAndFallsBackToTheRepositories", testInfoReadsListsAsListsAndFallsBackToTheRepositories}, + {"TestReadInstalledSaysWhyAndWhichRepositoryOrForeign", testReadInstalledSaysWhyAndWhichRepositoryOrForeign}, + {"TestOwnsAnswersNoOwnerAsAnAnswer", testOwnsAnswersNoOwnerAsAnAnswer}, + {"TestUpdateListReadsCheckupdatesAndItsNothingToDo", testUpdateListReadsCheckupdatesAndItsNothingToDo}, + {"TestAnUpgradesUnitIsReadBack", testAnUpgradesUnitIsReadBack}, + {"TestRemovingOrphansTakesOnlyOrphansNamedOrAll", testRemovingOrphansTakesOnlyOrphansNamedOrAll}, + {"TestCacheSaysWhatCleaningWouldFreeAndCleansThroughSudo", testCacheSaysWhatCleaningWouldFreeAndCleansThroughSudo}, + {"TestHistoryReadsTheLogSinceADayAndTheLastFullUpgrade", testHistoryReadsTheLogSinceADayAndTheLastFullUpgrade}, + {"TestNewsSinceTheLastUpgrade", testNewsSinceTheLastUpgrade}, + {"TestTheMeshsMirrorListIsRankedFreshAndAnsweredWithThisNodesFile", testTheMeshsMirrorListIsRankedFreshAndAnsweredWithThisNodesFile}, + {"TestConfigIsReadAsPacmanConfResolvesIt", testConfigIsReadAsPacmanConfResolvesIt}, + } { + t.Logf("case %s", c.name) + c.run(t) + } +} diff --git a/modules/pacman/cmd/pacman-tools/rollback_test.go b/modules/pacman/cmd/pacman-tools/rollback_test.go index ff7ac532d..54bdf82fd 100644 --- a/modules/pacman/cmd/pacman-tools/rollback_test.go +++ b/modules/pacman/cmd/pacman-tools/rollback_test.go @@ -45,7 +45,7 @@ func rollbackStates(t *testing.T) (*fakeStates, *Machine, *[]call) { return states, m, &calls } -func TestThePlanSaysEachPackageNowToTheRecordWithItsSourceTheAddedAndNoForeign(t *testing.T) { +func testThePlanSaysEachPackageNowToTheRecordWithItsSourceTheAddedAndNoForeign(t *testing.T) { _, m, calls := rollbackStates(t) p, err := PlanRollback(m, m.States(StateInstalled), m.States(StateRecords), "node-a", rollbackRecord.Run, false, true) if err != nil { @@ -79,7 +79,7 @@ func TestThePlanSaysEachPackageNowToTheRecordWithItsSourceTheAddedAndNoForeign(t } } -func TestAnotherNodesPlanReadsNoCacheAndTakesUnknownArchitecturesFromTheDatedRepository(t *testing.T) { +func testAnotherNodesPlanReadsNoCacheAndTakesUnknownArchitecturesFromTheDatedRepository(t *testing.T) { _, m, calls := rollbackStates(t) m.Node = "node-b" r, err := m.Rollback("node-a", rollbackRecord.Run, false, false) @@ -97,7 +97,7 @@ func TestAnotherNodesPlanReadsNoCacheAndTakesUnknownArchitecturesFromTheDatedRep } } -func TestNoPlanFromPackagesNotCurrentOrWithoutARecord(t *testing.T) { +func testNoPlanFromPackagesNotCurrentOrWithoutARecord(t *testing.T) { states, m, _ := rollbackStates(t) if _, err := m.Rollback("node-a", "20250101T000000Z", false, false); err == nil || !strings.Contains(err.Error(), "no record") { t.Errorf("no record: %v", err) @@ -108,7 +108,7 @@ func TestNoPlanFromPackagesNotCurrentOrWithoutARecord(t *testing.T) { } } -func TestApplyWritesAnAskForTheNodesKeeper(t *testing.T) { +func testApplyWritesAnAskForTheNodesKeeper(t *testing.T) { _, m, _ := rollbackStates(t) asks := newBucket() saved := upgradeState @@ -125,7 +125,7 @@ func TestApplyWritesAnAskForTheNodesKeeper(t *testing.T) { } } -func TestAnAskedRollbackIsOneTransactionWithItsEventsAndTheCheck(t *testing.T) { +func testAnAskedRollbackIsOneTransactionWithItsEventsAndTheCheck(t *testing.T) { k := newKeeperBed(t) k.records.Put(NodeKey("node-a", rollbackRecord.Run), rollbackRecord) k.installed.Put("node-a", rollbackNow) @@ -193,3 +193,21 @@ func (k *keeperBed) takeAsk(t *testing.T, a Ask) error { raw, _ := json.Marshal(a) return k.u.TakeAsk(stdio.StateChange{State: StateAsks, Key: key, Op: "put", Value: raw, Revision: rev}) } + +// TestThePlanSaysEachPackageNowToTheRecordWithItsSourceTheAddedAndNoForeign runs this file's cases in order as one test, each a row: the check counts every top-level test against the +// module's budget of 50 (design 47 H2 §819). A failing case is named by the line logged before it. +func TestThePlanSaysEachPackageNowToTheRecordWithItsSourceTheAddedAndNoForeign(t *testing.T) { + for _, c := range []struct { + name string + run func(*testing.T) + }{ + {"TestThePlanSaysEachPackageNowToTheRecordWithItsSourceTheAddedAndNoForeign", testThePlanSaysEachPackageNowToTheRecordWithItsSourceTheAddedAndNoForeign}, + {"TestAnotherNodesPlanReadsNoCacheAndTakesUnknownArchitecturesFromTheDatedRepository", testAnotherNodesPlanReadsNoCacheAndTakesUnknownArchitecturesFromTheDatedRepository}, + {"TestNoPlanFromPackagesNotCurrentOrWithoutARecord", testNoPlanFromPackagesNotCurrentOrWithoutARecord}, + {"TestApplyWritesAnAskForTheNodesKeeper", testApplyWritesAnAskForTheNodesKeeper}, + {"TestAnAskedRollbackIsOneTransactionWithItsEventsAndTheCheck", testAnAskedRollbackIsOneTransactionWithItsEventsAndTheCheck}, + } { + t.Logf("case %s", c.name) + c.run(t) + } +} diff --git a/modules/pacman/cmd/pacman-tools/root_test.go b/modules/pacman/cmd/pacman-tools/root_test.go index c5303f7e6..b0bf3f231 100644 --- a/modules/pacman/cmd/pacman-tools/root_test.go +++ b/modules/pacman/cmd/pacman-tools/root_test.go @@ -15,6 +15,7 @@ import ( "path/filepath" "reflect" "strings" + "sync/atomic" "testing" ) @@ -64,13 +65,16 @@ func (s stubProc) Readlink(name string) (string, error) { const aRun = "20261024T040000Z" -// testSocket is a socket in the abstract namespace, named for the test: a path under a test's temporary -// directory can pass the 108 bytes a socket's path may hold. +// testSocket is a socket in the abstract namespace, named for the test and numbered per call, as one test runs +// several cases whose listeners live until its end: a path under a test's temporary directory can pass the 108 +// bytes a socket's path may hold. func testSocket(t *testing.T) string { - return fmt.Sprintf("@pacman-root-test-%d-%s", os.Getpid(), t.Name()) + return fmt.Sprintf("@pacman-root-test-%d-%s-%d", os.Getpid(), t.Name(), sockets.Add(1)) } -func TestTheRootHelperStartsAnUpgradeAsTheRunsUnit(t *testing.T) { +var sockets atomic.Int64 + +func testTheRootHelperStartsAnUpgradeAsTheRunsUnit(t *testing.T) { b := newRootBed(t) a := b.h.Handle(RootRequest{Verb: VerbTransaction, Kind: RunUpgrade, Run: aRun, Ignore: []string{"linux", "linux-headers"}}) if a.Error != "" { @@ -83,7 +87,7 @@ func TestTheRootHelperStartsAnUpgradeAsTheRunsUnit(t *testing.T) { } } -func TestTheRootHelperStartsARollbackWithThePlanInTheRequest(t *testing.T) { +func testTheRootHelperStartsARollbackWithThePlanInTheRequest(t *testing.T) { b := newRootBed(t) plan := []RollbackItem{ {Name: "bash", From: "5.3.20-1", To: "5.3.15-1", Source: SourceCache, Location: CacheDir + "/bash-5.3.15-1-x86_64.pkg.tar.zst"}, @@ -115,7 +119,7 @@ func TestTheRootHelperStartsARollbackWithThePlanInTheRequest(t *testing.T) { } // And (ADR 0585 §3) the verb mirrorlist writes the mirror list file whole from the servers it is sent, running nothing. -func TestTheRootHelperReadsTheReplacedFilesMappings(t *testing.T) { +func testTheRootHelperReadsTheReplacedFilesMappings(t *testing.T) { b := newRootBed(t) servers := []string{"https://a.example/$repo/os/$arch", "https://b.example/archlinux/$repo/os/$arch"} if a := b.h.Handle(RootRequest{Verb: VerbMirrorlist, Servers: servers}); a.Error != "" { @@ -131,7 +135,7 @@ func TestTheRootHelperReadsTheReplacedFilesMappings(t *testing.T) { } } -func TestTheRootHelperReadsATransactionUnitsJournal(t *testing.T) { +func testTheRootHelperReadsATransactionUnitsJournal(t *testing.T) { b := newRootBed(t) unit := TransactionUnit(RunUpgrade, aRun) a := b.h.Handle(RootRequest{Verb: VerbJournal, Unit: unit, Lines: 40}) @@ -144,7 +148,7 @@ func TestTheRootHelperReadsATransactionUnitsJournal(t *testing.T) { } } -func TestTheRootHelperRefusesEverythingOffItsList(t *testing.T) { +func testTheRootHelperRefusesEverythingOffItsList(t *testing.T) { good := RollbackItem{Name: "bash", From: "5.3.20-1", To: "5.3.15-1", Source: SourceCache, Location: CacheDir + "/bash-5.3.15-1-x86_64.pkg.tar.zst"} with := func(f func(*RollbackItem)) []RollbackItem { i := good; f(&i); return []RollbackItem{i} } cases := map[string]RootRequest{ @@ -211,14 +215,14 @@ func serveOnce(t *testing.T, peer int, req RootRequest) (RootAnswer, error) { return rootClient{Socket: sock}.ask(req) } -func TestTheRootHelperAnswersTheKeepersAccountOverItsSocket(t *testing.T) { +func testTheRootHelperAnswersTheKeepersAccountOverItsSocket(t *testing.T) { a, err := serveOnce(t, os.Getuid(), RootRequest{Verb: VerbMaps}) if err != nil || a.Error != "" || len(a.Mapped) != 1 { t.Fatalf("the keeper's own account was answered %+v, %v", a, err) } } -func TestTheRootHelperRefusesAnyOtherAccount(t *testing.T) { +func testTheRootHelperRefusesAnyOtherAccount(t *testing.T) { a, err := serveOnce(t, os.Getuid()+1, RootRequest{Verb: VerbMaps}) if err == nil && a.Error == "" { t.Fatalf("another account was answered: %+v", a) @@ -228,7 +232,7 @@ func TestTheRootHelperRefusesAnyOtherAccount(t *testing.T) { } } -func TestTheClientCarriesTheRootActsAndSaysARefusal(t *testing.T) { +func testTheClientCarriesTheRootActsAndSaysARefusal(t *testing.T) { b := newRootBed(t) b.h.Peer = os.Getuid() sock := testSocket(t) @@ -254,7 +258,7 @@ func TestTheClientCarriesTheRootActsAndSaysARefusal(t *testing.T) { } } -func TestTheRootHelperIsRootWithNoBusAndNoSudoRule(t *testing.T) { +func testTheRootHelperIsRootWithNoBusAndNoSudoRule(t *testing.T) { m := manifest(t) r := m.resource(t, "root-helper") if r["type"] != "process" || r["name"] != "pacman-root" || r["artifact"] != "tools" || @@ -283,7 +287,7 @@ func TestTheRootHelperIsRootWithNoBusAndNoSudoRule(t *testing.T) { } } -func TestTheRollbackUnitInstallsThePlanThenRemovesWhatWasAskedInOrder(t *testing.T) { +func testTheRollbackUnitInstallsThePlanThenRemovesWhatWasAskedInOrder(t *testing.T) { dir := t.TempDir() plan := []RollbackItem{ {Name: "bash", To: "5.3.15-1", Source: SourceCache, Location: CacheDir + "/bash-5.3.15-1-x86_64.pkg.tar.zst"}, @@ -314,7 +318,7 @@ func TestTheRollbackUnitInstallsThePlanThenRemovesWhatWasAskedInOrder(t *testing } } -func TestTheRollbackUnitChangesNothingWhenAPackageIsNotFound(t *testing.T) { +func testTheRollbackUnitChangesNothingWhenAPackageIsNotFound(t *testing.T) { file := filepath.Join(t.TempDir(), aRun+".json") raw, _ := json.Marshal([]RollbackItem{{Name: "zlib", To: "1.3.1-2", Source: SourceRepository, Location: ArchiveURL + "/repos/2026/10/04/core/os/$arch"}}) _ = os.WriteFile(file, raw, 0o600) @@ -324,3 +328,27 @@ func TestTheRollbackUnitChangesNothingWhenAPackageIsNotFound(t *testing.T) { t.Fatalf("exit %d, ran %q: a package the archive does not hold fails the unit before any change", code, ran) } } + +// TestTheRootHelperStartsAnUpgradeAsTheRunsUnit runs this file's cases in order as one test, each a row: the check counts every top-level test against the +// module's budget of 50 (design 47 H2 §819). A failing case is named by the line logged before it. +func TestTheRootHelperStartsAnUpgradeAsTheRunsUnit(t *testing.T) { + for _, c := range []struct { + name string + run func(*testing.T) + }{ + {"TestTheRootHelperStartsAnUpgradeAsTheRunsUnit", testTheRootHelperStartsAnUpgradeAsTheRunsUnit}, + {"TestTheRootHelperStartsARollbackWithThePlanInTheRequest", testTheRootHelperStartsARollbackWithThePlanInTheRequest}, + {"TestTheRootHelperReadsTheReplacedFilesMappings", testTheRootHelperReadsTheReplacedFilesMappings}, + {"TestTheRootHelperReadsATransactionUnitsJournal", testTheRootHelperReadsATransactionUnitsJournal}, + {"TestTheRootHelperRefusesEverythingOffItsList", testTheRootHelperRefusesEverythingOffItsList}, + {"TestTheRootHelperAnswersTheKeepersAccountOverItsSocket", testTheRootHelperAnswersTheKeepersAccountOverItsSocket}, + {"TestTheRootHelperRefusesAnyOtherAccount", testTheRootHelperRefusesAnyOtherAccount}, + {"TestTheClientCarriesTheRootActsAndSaysARefusal", testTheClientCarriesTheRootActsAndSaysARefusal}, + {"TestTheRootHelperIsRootWithNoBusAndNoSudoRule", testTheRootHelperIsRootWithNoBusAndNoSudoRule}, + {"TestTheRollbackUnitInstallsThePlanThenRemovesWhatWasAskedInOrder", testTheRollbackUnitInstallsThePlanThenRemovesWhatWasAskedInOrder}, + {"TestTheRollbackUnitChangesNothingWhenAPackageIsNotFound", testTheRollbackUnitChangesNothingWhenAPackageIsNotFound}, + } { + t.Logf("case %s", c.name) + c.run(t) + } +} diff --git a/modules/pacman/cmd/pacman-tools/rounds_test.go b/modules/pacman/cmd/pacman-tools/rounds_test.go index 65463f51b..5a9545e67 100644 --- a/modules/pacman/cmd/pacman-tools/rounds_test.go +++ b/modules/pacman/cmd/pacman-tools/rounds_test.go @@ -85,7 +85,7 @@ func (b *roundBed) state(t *testing.T) map[string]NodeInRound { return out } -func TestTheRoundOpensSaturdayAtFourAndThePassedCheckGivesTheNextItsTurn(t *testing.T) { +func testTheRoundOpensSaturdayAtFourAndThePassedCheckGivesTheNextItsTurn(t *testing.T) { if o := RoundOpening(time.Date(2026, 10, 22, 15, 0, 0, 0, time.UTC)); !o.Equal(time.Date(2026, 10, 24, 4, 0, 0, 0, time.UTC)) { t.Fatalf("the opening of the week of Thursday 22 October: %s", o) } @@ -144,7 +144,7 @@ func TestTheRoundOpensSaturdayAtFourAndThePassedCheckGivesTheNextItsTurn(t *test } } -func TestNoOrderNoRound(t *testing.T) { +func testNoOrderNoRound(t *testing.T) { b := newRoundBed(t) b.now = time.Date(2026, 10, 24, 5, 0, 0, 0, time.UTC) if next := b.step(t, "node-a"); !next.IsZero() { @@ -155,7 +155,7 @@ func TestNoOrderNoRound(t *testing.T) { } } -func TestANodeOffAtItsTurnRunsAtItsNextStartAndAStalledTurnIsSaid(t *testing.T) { +func testANodeOffAtItsTurnRunsAtItsNextStartAndAStalledTurnIsSaid(t *testing.T) { b := newRoundBed(t, "node-a", "node-b", "node-c") b.now = time.Date(2026, 10, 24, 4, 0, 0, 0, time.UTC) b.step(t, "node-a") @@ -183,7 +183,7 @@ func warrant(a oc.Ask, option string, level string, at time.Time) json.RawMessag return raw } -func TestOnlyTheOperatorsApprovePassesANodeAndAPassNeedsAReason(t *testing.T) { +func testOnlyTheOperatorsApprovePassesANodeAndAPassNeedsAReason(t *testing.T) { b := newRoundBed(t, "node-a", "node-b", "node-c") b.now = time.Date(2026, 10, 24, 4, 0, 0, 0, time.UTC) b.step(t, "node-a") @@ -254,7 +254,7 @@ func TestOnlyTheOperatorsApprovePassesANodeAndAPassNeedsAReason(t *testing.T) { } } -func TestAPassTheOperatorKeepsWaitingPassesNothing(t *testing.T) { +func testAPassTheOperatorKeepsWaitingPassesNothing(t *testing.T) { b := newRoundBed(t, "node-a", "node-b") b.now = time.Date(2026, 10, 24, 4, 0, 0, 0, time.UTC) b.step(t, "node-a") // node-a runs and never ends @@ -287,7 +287,7 @@ func TestAPassTheOperatorKeepsWaitingPassesNothing(t *testing.T) { } } -func TestPacmanRoundReadsTheRounds(t *testing.T) { +func testPacmanRoundReadsTheRounds(t *testing.T) { b := newRoundBed(t, "node-a", "node-b") b.now = time.Date(2026, 10, 24, 4, 0, 0, 0, time.UTC) b.step(t, "node-a") @@ -304,3 +304,22 @@ func TestPacmanRoundReadsTheRounds(t *testing.T) { t.Error("a round that is not there") } } + +// TestTheRoundOpensSaturdayAtFourAndThePassedCheckGivesTheNextItsTurn runs this file's cases in order as one test, each a row: the check counts every top-level test against the +// module's budget of 50 (design 47 H2 §819). A failing case is named by the line logged before it. +func TestTheRoundOpensSaturdayAtFourAndThePassedCheckGivesTheNextItsTurn(t *testing.T) { + for _, c := range []struct { + name string + run func(*testing.T) + }{ + {"TestTheRoundOpensSaturdayAtFourAndThePassedCheckGivesTheNextItsTurn", testTheRoundOpensSaturdayAtFourAndThePassedCheckGivesTheNextItsTurn}, + {"TestNoOrderNoRound", testNoOrderNoRound}, + {"TestANodeOffAtItsTurnRunsAtItsNextStartAndAStalledTurnIsSaid", testANodeOffAtItsTurnRunsAtItsNextStartAndAStalledTurnIsSaid}, + {"TestOnlyTheOperatorsApprovePassesANodeAndAPassNeedsAReason", testOnlyTheOperatorsApprovePassesANodeAndAPassNeedsAReason}, + {"TestAPassTheOperatorKeepsWaitingPassesNothing", testAPassTheOperatorKeepsWaitingPassesNothing}, + {"TestPacmanRoundReadsTheRounds", testPacmanRoundReadsTheRounds}, + } { + t.Logf("case %s", c.name) + c.run(t) + } +} diff --git a/modules/pacman/cmd/pacman-tools/runs_test.go b/modules/pacman/cmd/pacman-tools/runs_test.go index d339b695f..98352a4e5 100644 --- a/modules/pacman/cmd/pacman-tools/runs_test.go +++ b/modules/pacman/cmd/pacman-tools/runs_test.go @@ -24,7 +24,7 @@ func capturedLog(t *testing.T) string { // The captured log holds three full upgrades among other commands: one that ended before any transaction, one // whose transaction completed, and a later one that upgraded one package. -func TestEveryFullUpgradeOfTheLogIsARunReadFromIt(t *testing.T) { +func testEveryFullUpgradeOfTheLogIsARunReadFromIt(t *testing.T) { runs := PastUpgrades("node-a", capturedLog(t)) if len(runs) != 3 { t.Fatalf("%d runs, want the three full upgrades and none of the other commands: %+v", len(runs), runs) @@ -61,7 +61,7 @@ func TestEveryFullUpgradeOfTheLogIsARunReadFromIt(t *testing.T) { } } -func TestATransactionWithoutAnEndOrThatFailedIsAFailedRun(t *testing.T) { +func testATransactionWithoutAnEndOrThatFailedIsAFailedRun(t *testing.T) { log := "[2026-10-10T04:00:00+0000] [PACMAN] Running 'pacman -Syu --noconfirm'\n" + "[2026-10-10T04:00:01+0000] [PACMAN] starting full system upgrade\n" + "[2026-10-10T04:00:05+0000] [ALPM] transaction started\n" + @@ -82,7 +82,7 @@ func TestATransactionWithoutAnEndOrThatFailedIsAFailedRun(t *testing.T) { } } -func TestTheLogIsReadIntoRunsOnceAndASecondStartReadsNothing(t *testing.T) { +func testTheLogIsReadIntoRunsOnceAndASecondStartReadsNothing(t *testing.T) { m := machine(nil, 1000) reads := 0 log := capturedLog(t) @@ -116,7 +116,7 @@ func TestTheLogIsReadIntoRunsOnceAndASecondStartReadsNothing(t *testing.T) { // A run's key is created at its first step and then only updated from the revision its writer holds: a step // is written once, and a run another writer changed meanwhile is refused, never overwritten. -func TestAStepIsWrittenOnceAndAnotherWritersChangeIsNeverOverwritten(t *testing.T) { +func testAStepIsWrittenOnceAndAnotherWritersChangeIsNeverOverwritten(t *testing.T) { runs := newBucket() u := &Upgrades{Node: "node-a", Runs: runs} r := &openRun{Run: Run{Node: "node-a", Run: "20261024T040000Z", Kind: RunUpgrade, From: FromAsk}} @@ -142,7 +142,7 @@ func TestAStepIsWrittenOnceAndAnotherWritersChangeIsNeverOverwritten(t *testing. } } -func TestPacmanUpgradesAnswersAllOneNodeDaysAndOneRun(t *testing.T) { +func testPacmanUpgradesAnswersAllOneNodeDaysAndOneRun(t *testing.T) { runs := newBucket() put := func(node, id string, steps ...Step) { r := Run{Node: node, Run: id, Kind: RunUpgrade, From: FromRound, Round: "2026-W43", Steps: steps} @@ -194,7 +194,7 @@ func TestPacmanUpgradesAnswersAllOneNodeDaysAndOneRun(t *testing.T) { } } -func TestTheUpgradesToolReadsTheRunsState(t *testing.T) { +func testTheUpgradesToolReadsTheRunsState(t *testing.T) { runs := newBucket() saved := upgradeState upgradeState = func(name string) Bucket { @@ -215,3 +215,22 @@ func TestTheUpgradesToolReadsTheRunsState(t *testing.T) { } t.Fatal("no pacman_upgrades") } + +// TestEveryFullUpgradeOfTheLogIsARunReadFromIt runs this file's cases in order as one test, each a row: the check counts every top-level test against the +// module's budget of 50 (design 47 H2 §819). A failing case is named by the line logged before it. +func TestEveryFullUpgradeOfTheLogIsARunReadFromIt(t *testing.T) { + for _, c := range []struct { + name string + run func(*testing.T) + }{ + {"TestEveryFullUpgradeOfTheLogIsARunReadFromIt", testEveryFullUpgradeOfTheLogIsARunReadFromIt}, + {"TestATransactionWithoutAnEndOrThatFailedIsAFailedRun", testATransactionWithoutAnEndOrThatFailedIsAFailedRun}, + {"TestTheLogIsReadIntoRunsOnceAndASecondStartReadsNothing", testTheLogIsReadIntoRunsOnceAndASecondStartReadsNothing}, + {"TestAStepIsWrittenOnceAndAnotherWritersChangeIsNeverOverwritten", testAStepIsWrittenOnceAndAnotherWritersChangeIsNeverOverwritten}, + {"TestPacmanUpgradesAnswersAllOneNodeDaysAndOneRun", testPacmanUpgradesAnswersAllOneNodeDaysAndOneRun}, + {"TestTheUpgradesToolReadsTheRunsState", testTheUpgradesToolReadsTheRunsState}, + } { + t.Logf("case %s", c.name) + c.run(t) + } +} diff --git a/modules/pacman/cmd/pacman-tools/transaction_test.go b/modules/pacman/cmd/pacman-tools/transaction_test.go index 1ea5466a2..18306804f 100644 --- a/modules/pacman/cmd/pacman-tools/transaction_test.go +++ b/modules/pacman/cmd/pacman-tools/transaction_test.go @@ -180,7 +180,7 @@ func steps(r Run) string { return strings.Join(s, " ") } -func TestAnAskedUpgradeIsARunWrittenAndEmittedAtEachStep(t *testing.T) { +func testAnAskedUpgradeIsARunWrittenAndEmittedAtEachStep(t *testing.T) { k := newKeeperBed(t) key, err := k.ask(t, "node-a", ActUpgrade) if err != nil { @@ -238,7 +238,7 @@ func TestAnAskedUpgradeIsARunWrittenAndEmittedAtEachStep(t *testing.T) { } } -func TestAFailedTransactionIsWrittenWithItsExitAndLastErrorAndChecked(t *testing.T) { +func testAFailedTransactionIsWrittenWithItsExitAndLastErrorAndChecked(t *testing.T) { k := newKeeperBed(t) if _, err := k.ask(t, "node-a", ActUpgrade); err != nil { t.Fatal(err) @@ -259,7 +259,7 @@ func TestAFailedTransactionIsWrittenWithItsExitAndLastErrorAndChecked(t *testing } } -func TestATransactionThatCannotStartFailsAndIsChecked(t *testing.T) { +func testATransactionThatCannotStartFailsAndIsChecked(t *testing.T) { k := newKeeperBed(t) k.root.fail = errors.New("the root helper's socket is not there") if _, err := k.ask(t, "node-a", ActUpgrade); err != nil { @@ -271,7 +271,7 @@ func TestATransactionThatCannotStartFailsAndIsChecked(t *testing.T) { } } -func TestAnAskIsTakenByItsNodesKeeperAlone(t *testing.T) { +func testAnAskIsTakenByItsNodesKeeperAlone(t *testing.T) { k := newKeeperBed(t) key, err := k.ask(t, "node-b", ActUpgrade) if err != nil { @@ -288,7 +288,7 @@ func TestAnAskIsTakenByItsNodesKeeperAlone(t *testing.T) { } } -func TestAnAskARunAlreadyNamesIsDeletedAndNotRunAgain(t *testing.T) { +func testAnAskARunAlreadyNamesIsDeletedAndNotRunAgain(t *testing.T) { k := newKeeperBed(t) done := Run{Node: "node-a", Run: "20261004T115900Z", Kind: RunUpgrade, From: FromAsk, Ask: RunID(k.now) + "-abc123", Steps: []Step{{Step: StepRefused, At: k.now, Why: "x"}}} @@ -307,7 +307,7 @@ func TestAnAskARunAlreadyNamesIsDeletedAndNotRunAgain(t *testing.T) { } } -func TestARunDoesNotStartWhileTheDatabaseIsLockedOrAnotherRunGoesOn(t *testing.T) { +func testARunDoesNotStartWhileTheDatabaseIsLockedOrAnotherRunGoesOn(t *testing.T) { k := newKeeperBed(t) k.locked = true if _, err := k.ask(t, "node-a", ActUpgrade); err != nil { @@ -336,7 +336,7 @@ func TestARunDoesNotStartWhileTheDatabaseIsLockedOrAnotherRunGoesOn(t *testing.T } } -func TestAKeeperStartedAgainFollowsItsRunToItsEnd(t *testing.T) { +func testAKeeperStartedAgainFollowsItsRunToItsEnd(t *testing.T) { k := newKeeperBed(t) if _, err := k.ask(t, "node-a", ActUpgrade); err != nil { t.Fatal(err) @@ -357,7 +357,7 @@ func TestAKeeperStartedAgainFollowsItsRunToItsEnd(t *testing.T) { } } -func TestAKeeperStartedAgainTakesUpARunStoppedBetweenItsSteps(t *testing.T) { +func testAKeeperStartedAgainTakesUpARunStoppedBetweenItsSteps(t *testing.T) { // Stopped after the gate, before the transaction started: nothing started, so the run is refused. k := newKeeperBed(t) stopped := Run{Node: "node-a", Run: "20261004T115900Z", Kind: RunUpgrade, From: FromAsk, @@ -401,7 +401,7 @@ func TestAKeeperStartedAgainTakesUpARunStoppedBetweenItsSteps(t *testing.T) { } } -func TestPacmanUpgradeWritesAnAskForTheNodeAndStartsNothing(t *testing.T) { +func testPacmanUpgradeWritesAnAskForTheNodeAndStartsNothing(t *testing.T) { asks := newBucket() savedState, savedNode, savedFetch := upgradeState, thisNode, fetch upgradeState = func(name string) Bucket { @@ -445,3 +445,25 @@ func TestPacmanUpgradeWritesAnAskForTheNodeAndStartsNothing(t *testing.T) { } t.Fatal("no pacman_upgrade") } + +// TestAnAskedUpgradeIsARunWrittenAndEmittedAtEachStep runs this file's cases in order as one test, each a row: the check counts every top-level test against the +// module's budget of 50 (design 47 H2 §819). A failing case is named by the line logged before it. +func TestAnAskedUpgradeIsARunWrittenAndEmittedAtEachStep(t *testing.T) { + for _, c := range []struct { + name string + run func(*testing.T) + }{ + {"TestAnAskedUpgradeIsARunWrittenAndEmittedAtEachStep", testAnAskedUpgradeIsARunWrittenAndEmittedAtEachStep}, + {"TestAFailedTransactionIsWrittenWithItsExitAndLastErrorAndChecked", testAFailedTransactionIsWrittenWithItsExitAndLastErrorAndChecked}, + {"TestATransactionThatCannotStartFailsAndIsChecked", testATransactionThatCannotStartFailsAndIsChecked}, + {"TestAnAskIsTakenByItsNodesKeeperAlone", testAnAskIsTakenByItsNodesKeeperAlone}, + {"TestAnAskARunAlreadyNamesIsDeletedAndNotRunAgain", testAnAskARunAlreadyNamesIsDeletedAndNotRunAgain}, + {"TestARunDoesNotStartWhileTheDatabaseIsLockedOrAnotherRunGoesOn", testARunDoesNotStartWhileTheDatabaseIsLockedOrAnotherRunGoesOn}, + {"TestAKeeperStartedAgainFollowsItsRunToItsEnd", testAKeeperStartedAgainFollowsItsRunToItsEnd}, + {"TestAKeeperStartedAgainTakesUpARunStoppedBetweenItsSteps", testAKeeperStartedAgainTakesUpARunStoppedBetweenItsSteps}, + {"TestPacmanUpgradeWritesAnAskForTheNodeAndStartsNothing", testPacmanUpgradeWritesAnAskForTheNodeAndStartsNothing}, + } { + t.Logf("case %s", c.name) + c.run(t) + } +} diff --git a/modules/pacman/cmd/pacman-tools/upgrade_health_test.go b/modules/pacman/cmd/pacman-tools/upgrade_health_test.go index 866902368..884e60e93 100644 --- a/modules/pacman/cmd/pacman-tools/upgrade_health_test.go +++ b/modules/pacman/cmd/pacman-tools/upgrade_health_test.go @@ -32,14 +32,14 @@ func passedRun(node string, at time.Time) Run { {Step: StepFinished, At: at.Add(5 * time.Minute)}, {Step: StepCheckedAfter, At: at.Add(6 * time.Minute), Check: &Check{Passed: true}}}} } -func TestWithNoOrderEveryNodesHealthSaysWhy(t *testing.T) { +func testWithNoOrderEveryNodesHealthSaysWhy(t *testing.T) { m, _ := healthBed(t, nil) if h := m.UpgradeHealth(); h.Healthy || !strings.Contains(h.Why, "upgrade-order") { t.Fatalf("%+v", h) } } -func TestANodeWithNoRunYetIsHealthy(t *testing.T) { +func testANodeWithNoRunYetIsHealthy(t *testing.T) { m, _ := healthBed(t, []string{"node-a", "node-b"}) if h := m.UpgradeHealth(); !h.Healthy { t.Fatalf("%+v", h) @@ -48,7 +48,7 @@ func TestANodeWithNoRunYetIsHealthy(t *testing.T) { // issue 1579: a run that failed is unhealthy until a later run passes, whenever the node woke; a run read from // the log is history and judges nothing. -func TestTheLatestRunJudgesTheNodeNotAUnitsAge(t *testing.T) { +func testTheLatestRunJudgesTheNodeNotAUnitsAge(t *testing.T) { m, states := healthBed(t, []string{"node-a", "node-b"}) exit := 1 failedAt := healthNow.Add(-7 * 24 * time.Hour) @@ -68,7 +68,7 @@ func TestTheLatestRunJudgesTheNodeNotAUnitsAge(t *testing.T) { } } -func TestAFailedCheckIsUnhealthy(t *testing.T) { +func testAFailedCheckIsUnhealthy(t *testing.T) { m, states := healthBed(t, []string{"node-b"}) r := passedRun("node-b", healthNow.Add(-time.Hour)) r.Steps[len(r.Steps)-1].Check = &Check{Passed: false, Unbuilt: []DKMSBuild{{Module: "made-up-dkms", Version: "1.0", Kernel: "7.3.1-arch1-1"}}} @@ -78,7 +78,7 @@ func TestAFailedCheckIsUnhealthy(t *testing.T) { } } -func TestARunPastTheLimitIsHungAndOneWithinItIsHealthy(t *testing.T) { +func testARunPastTheLimitIsHungAndOneWithinItIsHealthy(t *testing.T) { m, states := healthBed(t, []string{"node-b"}) started := healthNow.Add(-3 * time.Hour) putRun(states, Run{Node: "node-b", Run: RunID(started), Kind: RunUpgrade, From: FromAsk, Steps: []Step{{Step: StepRecorded, At: started}, {Step: StepStarted, At: started, Unit: TransactionUnit(RunUpgrade, RunID(started))}}}) @@ -94,7 +94,7 @@ func TestARunPastTheLimitIsHungAndOneWithinItIsHealthy(t *testing.T) { } // 1841/AC4: a held kernel keeps the health unhealthy, naming it, until a later run upgrades it. -func TestAHeldKernelIsSaidUntilARunUpgradesIt(t *testing.T) { +func testAHeldKernelIsSaidUntilARunUpgradesIt(t *testing.T) { m, states := healthBed(t, []string{"node-b"}) r := passedRun("node-b", healthNow.Add(-2*time.Hour)) r.Steps[1].Held = []HeldKernel{{Package: "linux", Version: "7.3.1.arch1-1", Module: "zfs", Bound: "Linux-Maximum 7.2"}} @@ -111,7 +111,7 @@ func TestAHeldKernelIsSaidUntilARunUpgradesIt(t *testing.T) { // 1841/AC7: a turn not started within round-start-minutes makes the waiting node's health name the node it // waits for and since when; the stalled node's own health says it too. -func TestAStalledRoundIsSaidByTheNodesWaitingOnIt(t *testing.T) { +func testAStalledRoundIsSaidByTheNodesWaitingOnIt(t *testing.T) { order := []string{"node-a", "node-b", "node-c"} m, states := healthBed(t, order) round := RoundID(healthNow) @@ -131,7 +131,7 @@ func TestAStalledRoundIsSaidByTheNodesWaitingOnIt(t *testing.T) { } } -func TestARoundStoppedByAFailureIsSaidByTheNodesWaitingOnIt(t *testing.T) { +func testARoundStoppedByAFailureIsSaidByTheNodesWaitingOnIt(t *testing.T) { order := []string{"node-a", "node-b"} m, states := healthBed(t, order) round := RoundID(healthNow) @@ -145,3 +145,24 @@ func TestARoundStoppedByAFailureIsSaidByTheNodesWaitingOnIt(t *testing.T) { t.Fatalf("%+v", h) } } + +// TestWithNoOrderEveryNodesHealthSaysWhy runs this file's cases in order as one test, each a row: the check counts every top-level test against the +// module's budget of 50 (design 47 H2 §819). A failing case is named by the line logged before it. +func TestWithNoOrderEveryNodesHealthSaysWhy(t *testing.T) { + for _, c := range []struct { + name string + run func(*testing.T) + }{ + {"TestWithNoOrderEveryNodesHealthSaysWhy", testWithNoOrderEveryNodesHealthSaysWhy}, + {"TestANodeWithNoRunYetIsHealthy", testANodeWithNoRunYetIsHealthy}, + {"TestTheLatestRunJudgesTheNodeNotAUnitsAge", testTheLatestRunJudgesTheNodeNotAUnitsAge}, + {"TestAFailedCheckIsUnhealthy", testAFailedCheckIsUnhealthy}, + {"TestARunPastTheLimitIsHungAndOneWithinItIsHealthy", testARunPastTheLimitIsHungAndOneWithinItIsHealthy}, + {"TestAHeldKernelIsSaidUntilARunUpgradesIt", testAHeldKernelIsSaidUntilARunUpgradesIt}, + {"TestAStalledRoundIsSaidByTheNodesWaitingOnIt", testAStalledRoundIsSaidByTheNodesWaitingOnIt}, + {"TestARoundStoppedByAFailureIsSaidByTheNodesWaitingOnIt", testARoundStoppedByAFailureIsSaidByTheNodesWaitingOnIt}, + } { + t.Logf("case %s", c.name) + c.run(t) + } +} diff --git a/modules/pacman/cmd/pacman-tools/view_test.go b/modules/pacman/cmd/pacman-tools/view_test.go index 82c1f3a55..7b6dc1853 100644 --- a/modules/pacman/cmd/pacman-tools/view_test.go +++ b/modules/pacman/cmd/pacman-tools/view_test.go @@ -42,7 +42,7 @@ func viewStates(t *testing.T) (*fakeStates, *Machine) { return states, m } -func TestOnePackageOnEveryNodeWithWhoDeclaresIt(t *testing.T) { +func testOnePackageOnEveryNodeWithWhoDeclaresIt(t *testing.T) { _, m := viewStates(t) r, err := m.Packages("zsh", 500) if err != nil { @@ -99,7 +99,7 @@ func TestOnePackageOnEveryNodeWithWhoDeclaresIt(t *testing.T) { } } -func TestTheViewSaysWhatDiffersWhatIsOnSomeNodesWhatNoModuleDeclaresAndTheForeignApart(t *testing.T) { +func testTheViewSaysWhatDiffersWhatIsOnSomeNodesWhatNoModuleDeclaresAndTheForeignApart(t *testing.T) { _, m := viewStates(t) r, err := m.Packages("", 500) if err != nil { @@ -135,7 +135,7 @@ func TestTheViewSaysWhatDiffersWhatIsOnSomeNodesWhatNoModuleDeclaresAndTheForeig } } -func TestInstalledAndForeignAnswerFromTheBus(t *testing.T) { +func testInstalledAndForeignAnswerFromTheBus(t *testing.T) { _, m := viewStates(t) r, err := m.InstalledFrom("", "", "", false, 10) if err != nil || r["node"] != "node-a" || r["count"] != 4 || r["current"] != true { @@ -161,7 +161,7 @@ func TestInstalledAndForeignAnswerFromTheBus(t *testing.T) { } } -func TestUpdatesAnswerEveryNodeAndWhenItsListLastChanged(t *testing.T) { +func testUpdatesAnswerEveryNodeAndWhenItsListLastChanged(t *testing.T) { states, m := viewStates(t) up := states.store(StateUpdates) up.now = func() time.Time { return t0.Add(-2 * time.Hour) } @@ -183,7 +183,7 @@ func TestUpdatesAnswerEveryNodeAndWhenItsListLastChanged(t *testing.T) { } } -func TestANodeArgumentIsOneKeyToken(t *testing.T) { +func testANodeArgumentIsOneKeyToken(t *testing.T) { for _, bad := range []string{"node-a.not-current", "node-a.*", "a b"} { if _, err := nodeOf(map[string]any{"node": bad}); err == nil { t.Errorf("%q was taken as a node", bad) @@ -200,3 +200,21 @@ type failingReader struct{ err error } func (f failingReader) Get(string) (*stdio.StateEntry, error) { return nil, f.err } func (f failingReader) Keys() ([]string, error) { return nil, f.err } func (f failingReader) History(string) ([]stdio.StateRevision, error) { return nil, f.err } + +// TestOnePackageOnEveryNodeWithWhoDeclaresIt runs this file's cases in order as one test, each a row: the check counts every top-level test against the +// module's budget of 50 (design 47 H2 §819). A failing case is named by the line logged before it. +func TestOnePackageOnEveryNodeWithWhoDeclaresIt(t *testing.T) { + for _, c := range []struct { + name string + run func(*testing.T) + }{ + {"TestOnePackageOnEveryNodeWithWhoDeclaresIt", testOnePackageOnEveryNodeWithWhoDeclaresIt}, + {"TestTheViewSaysWhatDiffersWhatIsOnSomeNodesWhatNoModuleDeclaresAndTheForeignApart", testTheViewSaysWhatDiffersWhatIsOnSomeNodesWhatNoModuleDeclaresAndTheForeignApart}, + {"TestInstalledAndForeignAnswerFromTheBus", testInstalledAndForeignAnswerFromTheBus}, + {"TestUpdatesAnswerEveryNodeAndWhenItsListLastChanged", testUpdatesAnswerEveryNodeAndWhenItsListLastChanged}, + {"TestANodeArgumentIsOneKeyToken", testANodeArgumentIsOneKeyToken}, + } { + t.Logf("case %s", c.name) + c.run(t) + } +}