//go:build hostedlive package main // The Task 17 crash point. A controller built with -tags hostedlive and run // with EQUIPO_HOSTED_CRASH_AFTER_LAUNCH=1 exits with status 137, as if // killed, as soon as a provider Launch returns a VM: after the provider call // and before transaction 2 saves the Ref. Restarted without the variable, // the reaper's first pass replays the intent with the same client token and // claims that VM. A build without the tag holds none of this // (TestNoCrashPointWithoutTag). import ( "context" "log" "os" "amadan.net/oficina/equipo/internal/isolatedjob" ) // crashAfterLaunchEnv switches the crash point on in a hostedlive build. const crashAfterLaunchEnv = "EQUIPO_HOSTED_CRASH_AFTER_LAUNCH" // crashExit ends the process; tests replace it. var crashExit = os.Exit func init() { runnerHook = crashAfterLaunch } // crashAfterLaunch wraps r with the crash point when the variable is "1", // and returns r itself otherwise. func crashAfterLaunch(r isolatedjob.Runner) isolatedjob.Runner { if os.Getenv(crashAfterLaunchEnv) != "1" { return r } log.Printf("equipo-hosted-controller: %s=1: the process exits after the next provider launch that returns a VM", crashAfterLaunchEnv) return crashRunner{r} } // crashRunner is a Runner whose Launch exits the process once the provider // has returned a VM. type crashRunner struct{ isolatedjob.Runner } func (c crashRunner) Launch(ctx context.Context, s isolatedjob.LaunchSpec) (isolatedjob.Ref, error) { ref, err := c.Runner.Launch(ctx, s) if err == nil { log.Printf("equipo-hosted-controller: crash point: the provider launched %s for %s; exiting before the Ref is saved", ref, s.AttemptID) crashExit(137) } return ref, err }