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 hostedlive
2
3package main
4
5// The Task 17 crash point. A controller built with -tags hostedlive and run
6// with EQUIPO_HOSTED_CRASH_AFTER_LAUNCH=1 exits with status 137, as if
7// killed, as soon as a provider Launch returns a VM: after the provider call
8// and before transaction 2 saves the Ref. Restarted without the variable,
9// the reaper's first pass replays the intent with the same client token and
10// claims that VM. A build without the tag holds none of this
11// (TestNoCrashPointWithoutTag).
12
13import (
14 "context"
15 "log"
16 "os"
17
18 "amadan.net/oficina/equipo/internal/isolatedjob"
19)
20
21// crashAfterLaunchEnv switches the crash point on in a hostedlive build.
22const crashAfterLaunchEnv = "EQUIPO_HOSTED_CRASH_AFTER_LAUNCH"
23
24// crashExit ends the process; tests replace it.
25var crashExit = os.Exit
26
27func init() { runnerHook = crashAfterLaunch }
28
29// crashAfterLaunch wraps r with the crash point when the variable is "1",
30// and returns r itself otherwise.
31func crashAfterLaunch(r isolatedjob.Runner) isolatedjob.Runner {
32 if os.Getenv(crashAfterLaunchEnv) != "1" {
33 return r
34 }
35 log.Printf("equipo-hosted-controller: %s=1: the process exits after the next provider launch that returns a VM", crashAfterLaunchEnv)
36 return crashRunner{r}
37}
38
39// crashRunner is a Runner whose Launch exits the process once the provider
40// has returned a VM.
41type crashRunner struct{ isolatedjob.Runner }
42
43func (c crashRunner) Launch(ctx context.Context, s isolatedjob.LaunchSpec) (isolatedjob.Ref, error) {
44 ref, err := c.Runner.Launch(ctx, s)
45 if err == nil {
46 log.Printf("equipo-hosted-controller: crash point: the provider launched %s for %s; exiting before the Ref is saved", ref, s.AttemptID)
47 crashExit(137)
48 }
49 return ref, err
50}
51