78 lines
2.6 KiB
Go
78 lines
2.6 KiB
Go
package main
|
|
|
|
// The integration level (novox/hq ADR 0445 §2 §3, ADR 0470; issue 1486): `go test -tags integration` over the
|
|
// workspace, against a throwaway postgres and a throwaway bus started for this run alone, handed to the tests as
|
|
// MESH_TEST_POSTGRES and MESH_TEST_NATS. Its setup (compiling, the store, the bus) and its running time are measured and
|
|
// judged apart, 30 s and 60 s; both servers are stopped and the run's directory removed whatever the tests did.
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"strconv"
|
|
"time"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/buildstep"
|
|
)
|
|
|
|
// The integration level's bounds (ADR 0445 §3).
|
|
const (
|
|
IntegrationSetup = 30 * time.Second
|
|
IntegrationRun = 60 * time.Second
|
|
)
|
|
|
|
func (m *Module) integrationBounds() Bounds {
|
|
b := m.IntegrationBounds
|
|
if b.Setup <= 0 {
|
|
b.Setup = IntegrationSetup
|
|
}
|
|
if b.Run <= 0 {
|
|
b.Run = IntegrationRun
|
|
}
|
|
return b
|
|
}
|
|
|
|
func (m *Module) integration(ctx context.Context, workspace, tree string, packages []string) (res *TestResult, err error) {
|
|
major, err := m.checkPostgres(ctx)
|
|
if err != nil {
|
|
return nil, err // a *buildstep.Refusal: this level only
|
|
}
|
|
run := filepath.Join(m.Work, workspace, "run-"+buildstep.NewID())
|
|
if err := os.MkdirAll(run, 0o700); err != nil {
|
|
return nil, err
|
|
}
|
|
// The run's directory goes, and the servers stop, however the level ends: passed, failed, a panic.
|
|
defer os.RemoveAll(run)
|
|
|
|
began := m.clock()
|
|
dirs, err := m.goModDirs(ctx, tree)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
postgres, stopStore, err := m.startStore(ctx, run)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("the integration level's store: %w", err)
|
|
}
|
|
defer stopStore()
|
|
nats, stopBus, err := m.startBus(ctx, filepath.Join(run, "nats"))
|
|
if err != nil {
|
|
return nil, fmt.Errorf("the integration level's bus: %w", err)
|
|
}
|
|
defer stopBus()
|
|
env := []string{"MESH_TEST_POSTGRES=" + postgres, "MESH_TEST_NATS=" + nats}
|
|
// Compiling counts as setup: the tests are built once, here, with the addresses a TestMain may read, and the run
|
|
// below finds them built. Whether they compile is for the run to say; its failure is not read here.
|
|
for _, d := range dirs {
|
|
m.Run(ctx, append(m.goEnvFor(filepath.Join(tree, d)), env...), "go", "-C", filepath.Join(tree, d), "test", "-tags", "integration", "-run", "^$", "-count=1", "./...")
|
|
}
|
|
setup := m.clock().Sub(began)
|
|
|
|
return m.runLevel(ctx, tree, levelOpts{
|
|
level: LevelIntegration, tags: []string{"integration"}, packages: packages, bounds: m.integrationBounds(),
|
|
env: env,
|
|
setup: setup, wall: true,
|
|
store: "postgres " + strconv.Itoa(major), bus: "nats-server " + m.Recipe.NatsServer,
|
|
})
|
|
}
|