report the running version on every poll (#35)
- commit
- 65c7d3d730202ff2b67b0393de6e8046b67ba6da
- author
- brice · · 2026-10-16 09:04 UTC
- committer
- bnema · · 2026-10-16 09:04 UTC
- parent
- 9517f29
- signature
- SSH Unverified
SHA256:VOCA5lYARHcbKDZ7GhTV45VmcjWnJ6ZQIBazj17LivAThe key is unknown
2 files · +25 -1
M internal/host/runner.go +1 -1
| @@ -142,7 +142,7 @@ func (r *Runner) Run(ctx context.Context) error { | |||
| 142 | 142 | pollID = newPollID() | |
| 143 | 143 | } | |
| 144 | 144 | pctx, cancel := context.WithTimeout(ctx, t.PollTimeout) | |
| 145 | - | resp, err := r.Poll.FetchJob(pctx, connect.NewRequest(&ermite.FetchJobRequest{PollId: pollID})) | |
| 145 | + | resp, err := r.Poll.FetchJob(pctx, connect.NewRequest(&ermite.FetchJobRequest{PollId: pollID, Version: r.Cfg.Version})) | |
| 146 | 146 | cancel() | |
| 147 | 147 | if err != nil { | |
| 148 | 148 | <-slots | |
| @@ -142,7 +142,7 @@ func (r *Runner) Run(ctx context.Context) error { | |||||
| 142 | pollID = newPollID() | 142 | pollID = newPollID() | ||
| 143 | } | 143 | } | ||
| 144 | pctx, cancel := context.WithTimeout(ctx, t.PollTimeout) | 144 | pctx, cancel := context.WithTimeout(ctx, t.PollTimeout) | ||
| 145 | - | resp, err := r.Poll.FetchJob(pctx, connect.NewRequest(&ermite.FetchJobRequest{PollId: pollID})) | 145 | + | resp, err := r.Poll.FetchJob(pctx, connect.NewRequest(&ermite.FetchJobRequest{PollId: pollID, Version: r.Cfg.Version})) |
| 146 | cancel() | 146 | cancel() | ||
| 147 | if err != nil { | 147 | if err != nil { | ||
| 148 | <-slots | 148 | <-slots | ||
M internal/host/runner_test.go +24 -0
| @@ -13,6 +13,7 @@ import ( | |||
| 13 | 13 | "regexp" | |
| 14 | 14 | "strconv" | |
| 15 | 15 | "strings" | |
| 16 | + | "sync" | |
| 16 | 17 | "testing" | |
| 17 | 18 | "time" | |
| 18 | 19 | "unicode/utf8" | |
| @@ -1326,3 +1327,26 @@ func TestUnitMountNamespaceCheckSeesOptions(t *testing.T) { | |||
| 1326 | 1327 | t.Fatalf("%q", got) | |
| 1327 | 1328 | } | |
| 1328 | 1329 | } | |
| 1330 | + | ||
| 1331 | + | // Every poll carries the version of the running binary, so that the server's | |
| 1332 | + | // runner list shows what runs now and not what registered. | |
| 1333 | + | func TestPollReportsTheRunningVersion(t *testing.T) { | |
| 1334 | + | h := newHarness(t, simpleScript("x")) | |
| 1335 | + | var mu sync.Mutex | |
| 1336 | + | var seen []string | |
| 1337 | + | h.srv.pollHook = func(_ int, req *ermite.FetchJobRequest) (*ermite.FetchJobResponse, error) { | |
| 1338 | + | mu.Lock() | |
| 1339 | + | seen = append(seen, req.GetVersion()) | |
| 1340 | + | mu.Unlock() | |
| 1341 | + | return nil, nil | |
| 1342 | + | } | |
| 1343 | + | h.run(t) | |
| 1344 | + | eventually(t, "two polls", func() bool { mu.Lock(); defer mu.Unlock(); return len(seen) >= 2 }) | |
| 1345 | + | mu.Lock() | |
| 1346 | + | defer mu.Unlock() | |
| 1347 | + | for _, v := range seen { | |
| 1348 | + | if v != "test" { | |
| 1349 | + | t.Fatalf("poll versions %v, want the runner's own", seen) | |
| 1350 | + | } | |
| 1351 | + | } | |
| 1352 | + | } | |
| @@ -13,6 +13,7 @@ import ( | |||||
| 13 | "regexp" | 13 | "regexp" | ||
| 14 | "strconv" | 14 | "strconv" | ||
| 15 | "strings" | 15 | "strings" | ||
| 16 | + | "sync" | |||
| 16 | "testing" | 17 | "testing" | ||
| 17 | "time" | 18 | "time" | ||
| 18 | "unicode/utf8" | 19 | "unicode/utf8" | ||
| @@ -1326,3 +1327,26 @@ func TestUnitMountNamespaceCheckSeesOptions(t *testing.T) { | |||||
| 1326 | t.Fatalf("%q", got) | 1327 | t.Fatalf("%q", got) | ||
| 1327 | } | 1328 | } | ||
| 1328 | } | 1329 | } | ||
| 1330 | + | ||||
| 1331 | + | // Every poll carries the version of the running binary, so that the server's | |||
| 1332 | + | // runner list shows what runs now and not what registered. | |||
| 1333 | + | func TestPollReportsTheRunningVersion(t *testing.T) { | |||
| 1334 | + | h := newHarness(t, simpleScript("x")) | |||
| 1335 | + | var mu sync.Mutex | |||
| 1336 | + | var seen []string | |||
| 1337 | + | h.srv.pollHook = func(_ int, req *ermite.FetchJobRequest) (*ermite.FetchJobResponse, error) { | |||
| 1338 | + | mu.Lock() | |||
| 1339 | + | seen = append(seen, req.GetVersion()) | |||
| 1340 | + | mu.Unlock() | |||
| 1341 | + | return nil, nil | |||
| 1342 | + | } | |||
| 1343 | + | h.run(t) | |||
| 1344 | + | eventually(t, "two polls", func() bool { mu.Lock(); defer mu.Unlock(); return len(seen) >= 2 }) | |||
| 1345 | + | mu.Lock() | |||
| 1346 | + | defer mu.Unlock() | |||
| 1347 | + | for _, v := range seen { | |||
| 1348 | + | if v != "test" { | |||
| 1349 | + | t.Fatalf("poll versions %v, want the runner's own", seen) | |||
| 1350 | + | } | |||
| 1351 | + | } | |||
| 1352 | + | } | |||