The node-engine held 1,707 top-level unit tests against the budget of 500 a module. Each unit test file with two or more tests now runs them as subtests of one test named for the file, each named as its function was, in the same order: every check is kept, and the check counts 383. Files with a TestMain, a re-run of a test by its name, or the integration tag are left. Four files of this branch's earlier commits are formatted. Builds: design 47 H2 §819; H-A-349 DQ-14
47 lines
1.7 KiB
Go
47 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// An apply runs in a context the bus's loss cannot end: the link's context ends when the bus goes, and the bus may go
|
|
// because of the apply itself (it replaces the bus's own container), which then must finish (issue 1945, live on
|
|
// 2026-10-25 at 11:23: novox's node-engine removed the bus container, its link's context ended, and the docker run that
|
|
// would have made the new one was never made).
|
|
func testAnApplyOutlivesTheLinksContext(t *testing.T) {
|
|
type key struct{}
|
|
link, cancel := context.WithCancel(context.WithValue(context.Background(), key{}, "v"))
|
|
ctx, done := applyContext(link)
|
|
defer done()
|
|
cancel()
|
|
if ctx.Err() != nil {
|
|
t.Fatalf("the apply's context ended with the link's: %v", ctx.Err())
|
|
}
|
|
if ctx.Value(key{}) != "v" {
|
|
t.Fatal("the apply's context lost the link's values")
|
|
}
|
|
}
|
|
|
|
// An apply is bounded all the same: a step that hangs (a docker call that never returns) cannot hold the node agent for
|
|
// ever (the review of issue 1945).
|
|
func testAnApplyIsBounded(t *testing.T) {
|
|
t.Run("the marks of the haves never hold the pass", marksOfTheHavesNeverHoldThePass)
|
|
ctx, done := applyContext(context.Background())
|
|
defer done()
|
|
at, ok := ctx.Deadline()
|
|
if !ok {
|
|
t.Fatal("an apply has no bound")
|
|
}
|
|
if left := time.Until(at); left > applyBound || left < applyBound-time.Minute {
|
|
t.Fatalf("the bound is %s away, want about %s", left, applyBound)
|
|
}
|
|
}
|
|
|
|
// TestApplyContext runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
|
func TestApplyContext(t *testing.T) {
|
|
t.Run("AnApplyOutlivesTheLinksContext", testAnApplyOutlivesTheLinksContext)
|
|
t.Run("AnApplyIsBounded", testAnApplyIsBounded)
|
|
}
|