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.

Code

527 commit(s) on main

Put job execution behind an interface Keenan Nemetz · 2h ago de3eec16
history blame raw 2.0 KiB
1package agent
2
3import (
4 "context"
5 "errors"
6 "io"
7 "testing"
8 "time"
9
10 "rodent.software/vole/ci/execute"
11)
12
13// stubExecutor is an executor whose only interesting behaviour is its prune, which
14// is what the runner's image trimmer drives. The trimming policy belongs to the
15// backend (ci/container tests it there); what is left here is the beat and the
16// once-only complaint.
17type stubExecutor struct {
18 calls int
19 err error
20 present bool
21}
22
23func (s *stubExecutor) Capabilities() execute.Capabilities {
24 return execute.Capabilities{Backend: "stub"}
25}
26func (s *stubExecutor) Probe(context.Context) error { return nil }
27func (s *stubExecutor) Prepare(context.Context, execute.Image, io.Writer, execute.Runner) (string, func(), error) {
28 return "", nil, errors.New("not used")
29}
30func (s *stubExecutor) Start(context.Context, execute.Spec) (execute.Sandbox, error) {
31 return execute.Nothing(), nil
32}
33func (s *stubExecutor) Reconcile(context.Context) error { return nil }
34func (s *stubExecutor) Prune(_ context.Context, age time.Duration) (int64, error) {
35 s.calls++
36 if age <= 0 {
37 return 0, nil
38 }
39 return 0, s.err
40}
41
42// A backend that cannot prune is a line, not a retry every five minutes and not a
43// runner that refuses to serve.
44func TestImageTrimmerStopsAfterTheExecutorRefuses(t *testing.T) {
45 exec := &stubExecutor{err: errors.New("the image store is not available")}
46 trimmer := newImageTrimmer(exec, time.Hour)
47 trimmer.trim(context.Background())
48 trimmer.trim(context.Background())
49 if exec.calls != 1 {
50 t.Fatalf("a refusing executor was asked %d times, want once", exec.calls)
51 }
52 if !trimmer.stopped {
53 t.Fatal("the trimmer kept trying after the executor refused")
54 }
55}
56
57// Zero is a policy ("keep every image"), not a very short age: the pass is never
58// scheduled at all.
59func TestImageTrimmerIsOffAtAgeZero(t *testing.T) {
60 exec := &stubExecutor{}
61 trimmer := newImageTrimmer(exec, 0)
62 if trimmer.enabled() {
63 t.Fatal("age 0 enabled the image trimmer")
64 }
65 if trimmer.age != 0 {
66 t.Fatalf("age = %s", trimmer.age)
67 }
68}
69