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.

Test the deadline and the site guard, not the machine

e48543eec150817b20c17a8b3d4f663be1c11609 · Keenan Nemetz · 23d ago · parent c284cb2c

Test the deadline and the site guard, not the machine

verify failed twice on cli-help-table while the runner host was at 50-60% CPU
steal. Neither failing test was about the code under test.

TestWorkflowRefusesAStaleSiteDeploy started its held runner with
exec.Command(binPath, "runner", ...) instead of f.runnerCmd, so it kept the 2G
disk reserve that c284cb2 turned off for every other test-spawned runner. Inside
a CI job /tmp is the runtime's 1G tmpfs, so the nested runner stopped the build
at its first one-second disk check: the stale run failed, but for the disk rather
than for staleness, and the log never said "the site was not deployed".
TestTestRunnersComeFromRunnerCmd now fails when a test starts a runner directly,
because the mistake is invisible on a workstation where /tmp is large.

TestHandshakeDeadlineIsClearedForTheSession gave the handshake a 100 ms deadline
and then slept past it. On a loaded machine the server cut the test's own
handshake, so dial failed with EOF and the test reported a product problem it had
created. It now reads the deadlines the server set on the connection: a non-zero
bound for the handshake, then a zero one after it. That is the property, it takes
no wall-clock assumption, and deleting the clearing in serveConn fails it
immediately instead of a third of a second later.

Closes: 01M7389DZ8JY77W3AF1P10ZDRT

server/ssh/sshserver_test.go +65−1

@@ -13,6 +13,7 @@ import (
13 13 "path/filepath"
14 14 "runtime/debug"
15 15 "strings"
16 "sync"
16 17 "testing"
17 18 "time"
18 19
@@ -89,6 +90,16 @@ func newHarness(t *testing.T) *harness { return newHarnessWith(t, nil) }
89 90 // which is how the handshake, connection and process caps get exercised at a
90 91 // size a test can reach.
91 92 func newHarnessWith(t *testing.T, tweak func(*Config)) *harness {
93 t.Helper()
94 h, _ := newRecordingHarness(t, tweak)
95 return h
96 }
97
98 // newRecordingHarness is newHarnessWith, plus the listener the server accepted
99 // from, so a test can see what the server did to the connection — the handshake
100 // deadline it set, and whether it cleared it — instead of inferring it from a
101 // clock that a loaded machine does not keep.
102 func newRecordingHarness(t *testing.T, tweak func(*Config)) (*harness, *recordingListener) {
92 103 t.Helper()
93 104 dir := t.TempDir()
94 105 usersDB := filepath.Join(dir, "users.db")
@@ -173,14 +184,67 @@ func newHarnessWith(t *testing.T, tweak func(*Config)) *harness {
173 184 if err != nil {
174 185 t.Fatal(err)
175 186 }
176 go srv.Serve(ln)
187 rec := &recordingListener{Listener: ln}
188 go srv.Serve(rec)
177 189 t.Cleanup(func() { srv.Close() })
178 190
179 191 return &harness{
180 192 t: t, dir: dir, addr: ln.Addr().String(), ident: ident, repos: rs,
181 193 srv: srv, keyPath: writer, roKey: reader, repoName: "demo",
182 194 runs: queue, logs: logStore, objects: objects, writerID: writerID,
195 }, rec
196 }
197
198 // recordingListener wraps the accepted connections in a recordingConn, so a test
199 // can read back the deadlines the server set on them.
200 type recordingListener struct {
201 net.Listener
202 mu sync.Mutex
203 conns []*recordingConn
204 }
205
206 func (l *recordingListener) Accept() (net.Conn, error) {
207 c, err := l.Listener.Accept()
208 if err != nil {
209 return nil, err
210 }
211 rec := &recordingConn{Conn: c}
212 l.mu.Lock()
213 l.conns = append(l.conns, rec)
214 l.mu.Unlock()
215 return rec, nil
216 }
217
218 // first returns the connection the test's client dialled.
219 func (l *recordingListener) first(t *testing.T) *recordingConn {
220 t.Helper()
221 l.mu.Lock()
222 defer l.mu.Unlock()
223 if len(l.conns) == 0 {
224 t.Fatal("the server accepted no connection")
183 225 }
226 return l.conns[0]
227 }
228
229 // recordingConn records the deadlines the server set on one connection.
230 type recordingConn struct {
231 net.Conn
232 mu sync.Mutex
233 deadlines []time.Time
234 }
235
236 func (c *recordingConn) SetDeadline(t time.Time) error {
237 c.mu.Lock()
238 c.deadlines = append(c.deadlines, t)
239 c.mu.Unlock()
240 return c.Conn.SetDeadline(t)
241 }
242
243 // deadlinesSeen returns what the server set, in order.
244 func (c *recordingConn) deadlinesSeen() []time.Time {
245 c.mu.Lock()
246 defer c.mu.Unlock()
247 return append([]time.Time(nil), c.deadlines...)
184 248 }
185 249
186 250 // keypair writes an OpenSSH private key and returns its path plus the public