oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1//go:build testbuild
2
3package thin
4
5import (
6 "context"
7 "os"
8 "path/filepath"
9 "sync/atomic"
10 "testing"
11 "time"
12
13 "amadan.net/oficina/equipo/internal/runner/mac"
14 "amadan.net/oficina/equipo/internal/wire"
15)
16
17// Whole-branch fix 3, #1: a launch keeps the Mac's turn, and its
18// recovery evidence, until the executor's Wait (stop, proof, cleanup)
19// has returned, even when that runs past the launcher's wait. Here the
20// simulator shutdown ignores its deadline and outlasts every bound: the
21// turn is never free while it runs, and the attempt ends unterminated
22// only once it has returned.
23func TestWorkerLaunchHoldsTheTurnThroughCleanup(t *testing.T) {
24 x := newEngRig(t)
25 x.note("edit:Swipe.swift|false|true")
26 temp := filepath.Join(t.TempDir(), "T")
27 if err := os.Mkdir(temp, 0o700); err != nil {
28 t.Fatal(err)
29 }
30 var stole, ended atomic.Bool
31 x.w.Eng.XcodeExec = &mac.Executor{Turns: x.m.turns, UserTemp: temp, Settle: time.Second, CleanLimit: 300 * time.Millisecond,
32 QuietSimulators: func(context.Context) {
33 for deadline := time.Now().Add(2500 * time.Millisecond); time.Now().Before(deadline); time.Sleep(100 * time.Millisecond) {
34 if u, ok := x.m.turns.TryTake(mac.OpCheck); ok {
35 stole.Store(true)
36 u.Give()
37 }
38 }
39 ended.Store(true)
40 }}
41 x.w.Eng.Xcode = func() bool { return true }
42 // The policy names the Mac's T by its real prefix; the executor
43 // cleans the test's own.
44 x.m.paths.UserTemp = mac.UserTempPrefix + "/wb/T"
45 x.r.XcodeAccess = wire.XcodeAccessSandboxed
46 // The launcher's wait (a 200 ms grace, then the budgets plus no
47 // margin, 1.3 s) passes long
48 // before the cleanup returns.
49 was, grace := macStopMargin, macStopGrace
50 macStopMargin, macStopGrace = 0, 200*time.Millisecond
51 t.Cleanup(func() { macStopMargin, macStopGrace = was, grace })
52 rep := x.run(t)
53 if !ended.Load() || stole.Load() {
54 t.Fatalf("the cleanup was still running (%v) or the turn was taken during it (%v)", !ended.Load(), stole.Load())
55 }
56 if rep.Termination || rep.State == wire.StepDone {
57 t.Fatalf("report %+v", rep)
58 }
59 if u, ok := x.m.turns.TryTake(mac.OpCheck); !ok {
60 t.Fatal("the turn was not given back")
61 } else {
62 u.Give()
63 }
64}
65