vole
Site
Clone
Read only, no credentials:
https://rodent.software/vole.git
Write over SSH with a registered key:
git clone ssh://git@rodent.software/vole.git
Self-hosted forge that lives in your Git repo.
Copy a prepared instance per test, and act on a push or a finish at once
484548cd70c4ac42e4210132bcadaf8b1a8af3bc · Keenan Nemetz · 9d ago · parent 4489805d
Copy a prepared instance per test, and act on a push or a finish at once
Every test in the server package built an instance from empty files, and
creating those schemas costs about 400 ms: index.Open on a new file is 226 ms
and runs.Open 152 ms, nearly all of it DDL through the pure-Go SQLite driver,
while opening the same files again is 3 ms and 17 ms. With 253 fixtures that
was most of the package's runtime. TestMain now builds one data directory with
every schema and no rows, and a fixture copies it — a handful of small files —
so the per-test cost is the copy, not the schema.
The queue also waited on timers rather than on events, which is latency a
person feels, not just tests:
- the push spool was read once a second, so a push's first job appeared up
to a second later. It is read every quarter second now, and once at
startup, so a restart also picks up what landed while the instance was
down.
- the lease janitor swept every five seconds whatever the lease was, so a
two-second lease still looked dead for five. The sweep is a quarter of the
lease, capped at five seconds, which leaves a default minute-long lease
exactly as it was.
- a merge-when-ready request waited for the landing sweep after its combined
result turned green, and for the same sweep after being armed. Arming now
notifies the landing worker through the run store, and a stored result
notifies it from the SSH session that reports it; both still run the full
gate, and the sweep remains the safety net.
The waits that only tests can shorten are shorter too: three spool ticks
instead of one long sleep where a test proves nothing was queued, 25 ms polls
instead of 100 ms for state the server has already changed, and the two
workflow steps that sleep only to stay running are half as long.
Measured over `go test -json`, summing per-test elapsed so parallelism cannot
hide it: the server package goes from 650 s of accumulated test time to about
275 s across the same 332 tests. In the verify container the server package's
-race run goes from 47.7 s to about 35 s, and the whole job is roughly 75 s with
the image cached.
The spool contract is unchanged: one file per ref update, consumed idempotently,
cleared when queued. leaseSweep and the run store's arming notification have
unit tests; the rest is covered by the integration tests that depended on those
timers.
Verified with `go test ./... -count=1`, `go test ./server -shuffle=on`, and
`vole workflow run verify` (which includes the race suite).
Closes: 01M87KDS5D5GCB5XGG4MW1NDQC
server/integration_test.go +86−10
| @@ -9,6 +9,7 @@ import ( | |||
| 9 | 9 | "errors" | |
| 10 | 10 | "fmt" | |
| 11 | 11 | "io" | |
| 12 | "io/fs" | ||
| 12 | 13 | "log/slog" | |
| 13 | 14 | "net" | |
| 14 | 15 | "net/http" | |
| @@ -28,6 +29,7 @@ import ( | |||
| 28 | 29 | "rodent.software/vole/ci" | |
| 29 | 30 | "rodent.software/vole/ci/runs" | |
| 30 | 31 | "rodent.software/vole/core/git" | |
| 32 | "rodent.software/vole/forge" | ||
| 31 | 33 | "rodent.software/vole/forge/access" | |
| 32 | 34 | "rodent.software/vole/forge/config" | |
| 33 | 35 | "rodent.software/vole/forge/identity" | |
| @@ -154,8 +156,8 @@ func binaryBuildArgs() []string { | |||
| 154 | 156 | ||
| 155 | 157 | // Every test here calls t.Parallel(). These are integration tests: each one starts a | |
| 156 | 158 | // server, pushes over SSH and runs `git` subprocesses, so it spends almost all of its | |
| 157 | // time waiting on child processes and almost none of it on CPU. Serially that is ~150 | ||
| 158 | // seconds; sixteen at a time it is ~16. Anything added here must keep that possible: | ||
| 159 | // time waiting on child processes and almost none of it on CPU. Serially that is ~280 | ||
| 160 | // seconds; sixteen at a time it is ~20. Anything added here must keep that possible: | ||
| 159 | 161 | // | |
| 160 | 162 | // - no t.Setenv — it panics in a parallel test, and it is the wrong tool anyway. | |
| 161 | 163 | // Pass environment through cmd.Env (see ciEnv) so tests cannot see each other. | |
| @@ -166,6 +168,13 @@ func binaryBuildArgs() []string { | |||
| 166 | 168 | // A genuinely slow *wait* is the one thing parallelism cannot hide, because it sets the | |
| 167 | 169 | // floor for the whole package: prefer the shortest sleep a fixture can get away with, | |
| 168 | 170 | // and say in a comment what it is waiting for. | |
| 171 | // | ||
| 172 | // Creating an instance's schemas from empty files costs about 400 ms, almost all of | ||
| 173 | // it in the index and run-queue DDL, and every fixture used to pay it again. The | ||
| 174 | // template below is that work done once; a fixture copies the resulting directory, | ||
| 175 | // which is a handful of small files. | ||
| 176 | var fixtureTemplate string | ||
| 177 | |||
| 169 | 178 | func TestMain(m *testing.M) { | |
| 170 | 179 | dir, err := os.MkdirTemp("", "vole-int-bin-") | |
| 171 | 180 | if err != nil { | |
| @@ -200,11 +209,74 @@ func TestMain(m *testing.M) { | |||
| 200 | 209 | // control channel is a security boundary — so the test package uses the explicit | |
| 201 | 210 | // override rather than teaching the tests to trust everything implicitly. | |
| 202 | 211 | os.Setenv("VOLE_INSECURE_HOST_KEY", "1") | |
| 212 | fixtureTemplate, err = buildFixtureTemplate() | ||
| 213 | if err != nil { | ||
| 214 | fmt.Fprintln(os.Stderr, "fixture template:", err) | ||
| 215 | os.Exit(1) | ||
| 216 | } | ||
| 203 | 217 | code := m.Run() | |
| 204 | 218 | os.RemoveAll(dir) | |
| 219 | os.RemoveAll(fixtureTemplate) | ||
| 205 | 220 | os.Exit(code) | |
| 206 | 221 | } | |
| 207 | 222 | ||
| 223 | // buildFixtureTemplate returns a data directory whose stores all exist and hold | ||
| 224 | // nothing: the instance database with its schemas, and the index, run queue, | ||
| 225 | // session, access, lock, page-view, secret and channel stores beside it. | ||
| 226 | func buildFixtureTemplate() (string, error) { | ||
| 227 | dir, err := os.MkdirTemp("", "vole-int-fixture-") | ||
| 228 | if err != nil { | ||
| 229 | return "", err | ||
| 230 | } | ||
| 231 | cfg, err := config.Load("") | ||
| 232 | if err != nil { | ||
| 233 | return "", err | ||
| 234 | } | ||
| 235 | cfg.DataDir = dir | ||
| 236 | if err := identity.Init(cfg.InstanceDB()); err != nil { | ||
| 237 | return "", err | ||
| 238 | } | ||
| 239 | inst, err := forge.Open(cfg, binPath) | ||
| 240 | if err != nil { | ||
| 241 | return "", err | ||
| 242 | } | ||
| 243 | if err := inst.Close(); err != nil { | ||
| 244 | return "", err | ||
| 245 | } | ||
| 246 | return dir, nil | ||
| 247 | } | ||
| 248 | |||
| 249 | // copyTree copies the template's files and modes. A fixture gets its own copy | ||
| 250 | // because SQLite would otherwise carry one test's writes into the next. | ||
| 251 | func copyTree(t *testing.T, src, dst string) { | ||
| 252 | t.Helper() | ||
| 253 | err := filepath.WalkDir(src, func(path string, entry fs.DirEntry, err error) error { | ||
| 254 | if err != nil { | ||
| 255 | return err | ||
| 256 | } | ||
| 257 | rel, err := filepath.Rel(src, path) | ||
| 258 | if err != nil { | ||
| 259 | return err | ||
| 260 | } | ||
| 261 | target := filepath.Join(dst, rel) | ||
| 262 | info, err := entry.Info() | ||
| 263 | if err != nil { | ||
| 264 | return err | ||
| 265 | } | ||
| 266 | if entry.IsDir() { | ||
| 267 | return os.MkdirAll(target, info.Mode().Perm()) | ||
| 268 | } | ||
| 269 | data, err := os.ReadFile(path) | ||
| 270 | if err != nil { | ||
| 271 | return err | ||
| 272 | } | ||
| 273 | return os.WriteFile(target, data, info.Mode().Perm()) | ||
| 274 | }) | ||
| 275 | if err != nil { | ||
| 276 | t.Fatalf("copy fixture template: %v", err) | ||
| 277 | } | ||
| 278 | } | ||
| 279 | |||
| 208 | 280 | type fixture struct { | |
| 209 | 281 | t *testing.T | |
| 210 | 282 | cfg *config.Config | |
| @@ -232,10 +304,12 @@ func newFixtureWith(t *testing.T, tweak func(*config.Config)) *fixture { | |||
| 232 | 304 | if tweak != nil { | |
| 233 | 305 | tweak(cfg) | |
| 234 | 306 | } | |
| 235 | if err := os.MkdirAll(cfg.ReposDir(), 0o755); err != nil { | ||
| 236 | t.Fatal(err) | ||
| 307 | // The template already carries every schema; only the copy is paid per test. | ||
| 308 | if fixtureTemplate == "" { | ||
| 309 | t.Fatal("the fixture template was not built by TestMain") | ||
| 237 | 310 | } | |
| 238 | if err := identity.Init(cfg.InstanceDB()); err != nil { | ||
| 311 | copyTree(t, fixtureTemplate, cfg.DataDir) | ||
| 312 | if err := os.MkdirAll(cfg.ReposDir(), 0o755); err != nil { | ||
| 239 | 313 | t.Fatal(err) | |
| 240 | 314 | } | |
| 241 | 315 | pub, priv := keypair(t, filepath.Join(cfg.DataDir, "id_test")) | |
| @@ -3003,7 +3077,9 @@ func (f *fixture) ciEnvFor(keyPath string) []string { | |||
| 3003 | 3077 | ||
| 3004 | 3078 | func (f *fixture) sshBase() string { return "ssh://git@" + f.sshAddr } | |
| 3005 | 3079 | ||
| 3006 | // waitForRun polls the queue until a run matches, because ingestion is a ticker. | ||
| 3080 | // waitForRun polls the queue until a run matches. Ingestion runs on a short | ||
| 3081 | // ticker, so this polls a good deal faster than that: the wait should be the | ||
| 3082 | // producer's latency, not the poller's. | ||
| 3007 | 3083 | func (f *fixture) waitForRun(t *testing.T, within time.Duration, match func(*runs.Run) bool) *runs.Run { | |
| 3008 | 3084 | t.Helper() | |
| 3009 | 3085 | deadline := time.Now().Add(within) | |
| @@ -3018,7 +3094,7 @@ func (f *fixture) waitForRun(t *testing.T, within time.Duration, match func(*run | |||
| 3018 | 3094 | } | |
| 3019 | 3095 | } | |
| 3020 | 3096 | } | |
| 3021 | time.Sleep(100 * time.Millisecond) | ||
| 3097 | time.Sleep(20 * time.Millisecond) | ||
| 3022 | 3098 | } | |
| 3023 | 3099 | t.Fatalf("no matching run after %s; saw %d run(s): %+v", within, len(last), last) | |
| 3024 | 3100 | return nil | |
| @@ -3175,7 +3251,7 @@ jobs: | |||
| 3175 | 3251 | image: alpine:3.22 | |
| 3176 | 3252 | steps: | |
| 3177 | 3253 | - name: slow | |
| 3178 | run: echo "first line"; sleep 4; echo "second line" | ||
| 3254 | run: echo "first line"; sleep 2; echo "second line" | ||
| 3179 | 3255 | `)) | |
| 3180 | 3256 | if _, errs, err := f.git(work, "push", f.sshURL(f.repo), "main:refs/heads/main"); err != nil { | |
| 3181 | 3257 | t.Fatalf("push: %s", errs) | |
| @@ -3202,7 +3278,7 @@ jobs: | |||
| 3202 | 3278 | if time.Now().After(deadline) { | |
| 3203 | 3279 | t.Fatalf("the running log never showed the first line: %d %q", code, body) | |
| 3204 | 3280 | } | |
| 3205 | time.Sleep(100 * time.Millisecond) | ||
| 3281 | time.Sleep(25 * time.Millisecond) | ||
| 3206 | 3282 | } | |
| 3207 | 3283 | // The running step is the live view: its own accordion entry tails the step's | |
| 3208 | 3284 | // byte range, and there is no separate job-output pane duplicating it. | |
| @@ -3420,7 +3496,7 @@ jobs: | |||
| 3420 | 3496 | # (the kill happens as soon as the lease is visible, so the margin is the whole | |
| 3421 | 3497 | # step), and no longer: this same step also runs on the retry, so every second | |
| 3422 | 3498 | # here is a second added to the test. | |
| 3423 | run: sleep 3 | ||
| 3499 | run: sleep 1 | ||
| 3424 | 3500 | `)) | |
| 3425 | 3501 | if _, errs, err := f.git(work, "push", f.sshURL(f.repo), "main:refs/heads/main"); err != nil { | |
| 3426 | 3502 | t.Fatalf("push: %s", errs) | |