Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

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/candidates.go +16−1

@@ -287,6 +287,10 @@ func (s *Server) pruneCandidates(m *repo.Meta, req *metadata.Request, keep strin
287 287 // watchAutoMerges lands requests whose merger asked for "merge when ready" and
288 288 // whose combined result is green. Every pass re-runs the full gate: an armed row is
289 289 // a reason to look, never an authorisation to land.
290 //
291 // A pass also runs as soon as a run finishes, because the run that ended is often
292 // the combined result an armed request was waiting for: the ticker is the safety
293 // net, not the latency.
290 294 func (s *Server) watchAutoMerges(ctx context.Context) {
291 295 s.landArmed()
292 296 t := time.NewTicker(5 * time.Second)
@@ -296,8 +300,19 @@ func (s *Server) watchAutoMerges(ctx context.Context) {
296 300 case <-ctx.Done():
297 301 return
298 302 case <-t.C:
299 s.landArmed()
303 case <-s.autoMergeWake:
300 304 }
305 s.landArmed()
306 }
307 }
308
309 // wakeAutoMerge asks the landing loop to look now. It is called from the SSH
310 // session that stores a run's result, so it must never block: a pending wake is
311 // enough.
312 func (s *Server) wakeAutoMerge() {
313 select {
314 case s.autoMergeWake <- struct{}{}:
315 default:
301 316 }
302 317 }
303 318