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/ssh/server.go +11
| @@ -118,6 +118,10 @@ type Config struct { | |||
| 118 | 118 | // because the dispatcher lives on the instance and the SSH server is one of its | |
| 119 | 119 | // callers, not the other way round. | |
| 120 | 120 | DispatchWorkflow func(repo, workflow, ref string, inputs map[string]string, actor string) (int, error) | |
| 121 | // RunFinished is called after a run's result is stored, so work that waits on | ||
| 122 | // that result (an armed landing) can look now instead of on its next sweep. Nil | ||
| 123 | // means nothing waits on results. | ||
| 124 | RunFinished func() | ||
| 121 | 125 | // HandshakeTimeout bounds how long a connection may take to complete the SSH | |
| 122 | 126 | // handshake. Zero uses the default. | |
| 123 | 127 | HandshakeTimeout time.Duration | |
| @@ -175,6 +179,13 @@ func (s *Server) SetDispatchWorkflow(fn func(repo, workflow, ref string, inputs | |||
| 175 | 179 | s.cfg.DispatchWorkflow = fn | |
| 176 | 180 | } | |
| 177 | 181 | ||
| 182 | // SetRunFinished wires the notification for a stored run result. It is a setter for | ||
| 183 | // the same reason as SetDispatchWorkflow, and it must not block: it runs on the SSH | ||
| 184 | // session that reported the result. | ||
| 185 | func (s *Server) SetRunFinished(fn func()) { | ||
| 186 | s.cfg.RunFinished = fn | ||
| 187 | } | ||
| 188 | |||
| 178 | 189 | // maxConnections is the configured listener cap, or the default when unset. | |
| 179 | 190 | func (c Config) maxConnections() int { | |
| 180 | 191 | if c.MaxConnections > 0 { | |