package isolatedjob_test import ( "context" "errors" "fmt" "net/netip" "slices" "strings" "sync" "testing" "time" "amadan.net/oficina/equipo/internal/isolatedjob" "amadan.net/oficina/equipo/internal/isolatedjob/isolatedjobtest" ) const fakeDigest = isolatedjob.ImageDigest("sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef") var fakeStart = time.Date(2026, 11, 22, 9, 0, 0, 0, time.UTC) func newFake(t *testing.T) (*isolatedjob.Fake, *isolatedjobtest.FakeClock) { t.Helper() c := isolatedjobtest.NewFakeClock(fakeStart) return isolatedjob.NewFake(c, isolatedjob.SpikeLimits()), c } func fakeSpec(attempt string) isolatedjob.LaunchSpec { return isolatedjob.LaunchSpec{ AttemptID: attempt, Image: fakeDigest, Size: isolatedjob.SizeSmall, MaxLifetime: time.Hour, Bootstrap: []byte("one-time-code"), } } // settleFake ticks the fake until want holds, reading the VM before each tick. func settleFake(f *isolatedjob.Fake) func(context.Context, isolatedjob.Ref, func(isolatedjob.State) bool) (isolatedjob.Job, error) { return func(ctx context.Context, ref isolatedjob.Ref, want func(isolatedjob.State) bool) (isolatedjob.Job, error) { const maxTicks = 10 var job isolatedjob.Job for range maxTicks + 1 { var err error job, err = f.Get(ctx, ref) if err != nil { return job, err } if want(job.State) { return job, nil } f.Tick() } return job, fmt.Errorf("fake VM %s still %s after %d ticks", ref, job.State, maxTicks) } } func TestFakeContract(t *testing.T) { f, _ := newFake(t) isolatedjobtest.Contract(t, isolatedjobtest.Harness{Runner: f, Image: fakeDigest, Settle: settleFake(f)}) } // lateVisible is the Fake with reads that trail launches: Get answers // ErrNotFound once for each VM Launch returns, as AWS GetMicrovm can just // after the VM is created, its reads being eventually consistent. It also // counts Get and List calls whose context has no deadline. type lateVisible struct { *isolatedjob.Fake mu sync.Mutex seen map[isolatedjob.Ref]bool hidden map[isolatedjob.Ref]bool misses int unbounded int boundedOps int } func (l *lateVisible) note(ctx context.Context) { _, ok := ctx.Deadline() l.mu.Lock() defer l.mu.Unlock() if ok { l.boundedOps++ } else { l.unbounded++ } } func (l *lateVisible) List(ctx context.Context) ([]isolatedjob.Job, error) { l.note(ctx) return l.Fake.List(ctx) } func (l *lateVisible) Launch(ctx context.Context, s isolatedjob.LaunchSpec) (isolatedjob.Ref, error) { ref, err := l.Fake.Launch(ctx, s) if err == nil { l.mu.Lock() if !l.seen[ref] { l.seen[ref], l.hidden[ref] = true, true } l.mu.Unlock() } return ref, err } func (l *lateVisible) Get(ctx context.Context, ref isolatedjob.Ref) (isolatedjob.Job, error) { l.note(ctx) l.mu.Lock() hide := l.hidden[ref] if hide { delete(l.hidden, ref) l.misses++ } l.mu.Unlock() if hide { return isolatedjob.Job{}, fmt.Errorf("%w: %s is not visible yet", isolatedjob.ErrNotFound, ref) } return l.Fake.Get(ctx, ref) } // TestFakeContractLateVisibility runs the contract against a runner whose // Get misses every new VM once (Task 17, final review A3): the contract // waits for the VM to appear, within Harness.Visibility, before it reads it. // Every Get and List the contract makes carries a deadline, so a stalled // provider read fails a live run rather than hanging it. func TestFakeContractLateVisibility(t *testing.T) { f, _ := newFake(t) lv := &lateVisible{Fake: f, seen: map[isolatedjob.Ref]bool{}, hidden: map[isolatedjob.Ref]bool{}} var logMu sync.Mutex var logged []string isolatedjobtest.Contract(t, isolatedjobtest.Harness{Runner: lv, Image: fakeDigest, Settle: settleFake(f), Visibility: 200 * time.Millisecond, Logf: func(format string, args ...any) { logMu.Lock() defer logMu.Unlock() logged = append(logged, fmt.Sprintf(format, args...)) }}) // The live run reads these delays from the log (Task 17 review, round 1). var visible, listed int for _, l := range logged { switch { case strings.HasPrefix(l, "visibility: Get showed new VM ") && strings.HasSuffix(l, "(2 reads)"): visible++ case strings.HasPrefix(l, "list lag: List showed running VM "): listed++ } } if visible == 0 || listed == 0 { t.Errorf("measured delays logged: %d visibility after a miss, %d list lag; want both; log %q", visible, listed, logged) } lv.mu.Lock() defer lv.mu.Unlock() if lv.misses == 0 { t.Fatal("no Get answered ErrNotFound for a new VM; the test checked nothing") } if lv.unbounded != 0 || lv.boundedOps == 0 { t.Fatalf("contract made %d Get or List calls without a deadline (%d with one), want none without", lv.unbounded, lv.boundedOps) } } func mustLaunch(t *testing.T, f *isolatedjob.Fake, s isolatedjob.LaunchSpec) isolatedjob.Ref { t.Helper() ref, err := f.Launch(context.Background(), s) if err != nil { t.Fatalf("Launch(%s) = %v", s.AttemptID, err) } return ref } func mustGet(t *testing.T, f *isolatedjob.Fake, ref isolatedjob.Ref) isolatedjob.Job { t.Helper() job, err := f.Get(context.Background(), ref) if err != nil { t.Fatalf("Get(%s) = %v", ref, err) } return job } func wantState(t *testing.T, f *isolatedjob.Fake, ref isolatedjob.Ref, want isolatedjob.State) { t.Helper() if got := mustGet(t, f, ref).State; got != want { t.Fatalf("Get(%s).State = %s, want %s", ref, got, want) } } // running launches a VM and ticks it to running. func running(t *testing.T, f *isolatedjob.Fake, s isolatedjob.LaunchSpec) isolatedjob.Ref { t.Helper() ref := mustLaunch(t, f, s) f.Tick() wantState(t, f, ref, isolatedjob.StateRunning) return ref } func isSentinel(err error) bool { for _, s := range []error{isolatedjob.ErrNotFound, isolatedjob.ErrInvalid, isolatedjob.ErrConflict, isolatedjob.ErrThrottled, isolatedjob.ErrIncomplete, isolatedjob.ErrBootstrapTooLarge} { if errors.Is(err, s) { return true } } return false } // TestFakeFaults has one row per fault. Every row also checks that the fault // was used up by the one call it hit. func TestFakeFaults(t *testing.T) { ctx := context.Background() t.Run("throttle does nothing", func(t *testing.T) { f, _ := newFake(t) f.Inject(isolatedjob.OpLaunch, isolatedjob.FaultThrottle) ref, err := f.Launch(ctx, fakeSpec("a1")) if !errors.Is(err, isolatedjob.ErrThrottled) || ref != "" { t.Fatalf("throttled Launch = (%q, %v), want (\"\", ErrThrottled)", ref, err) } if live := f.LiveByAttempt(); len(live) != 0 { t.Fatalf("LiveByAttempt after a throttled launch = %v, want none", live) } mustLaunch(t, f, fakeSpec("a1")) if live := f.LiveByAttempt(); live["a1"] != 1 { t.Fatalf("LiveByAttempt after the next launch = %v, want a1:1", live) } }) t.Run("lost reply applies then errs", func(t *testing.T) { f, _ := newFake(t) f.Inject(isolatedjob.OpLaunch, isolatedjob.FaultLostReply) ref, err := f.Launch(ctx, fakeSpec("a1")) if !errors.Is(err, isolatedjob.ErrLostReply) || isSentinel(err) || ref != "" { t.Fatalf("lost-reply Launch = (%q, %v), want (\"\", ErrLostReply) and no sentinel", ref, err) } if live := f.LiveByAttempt(); live["a1"] != 1 { t.Fatalf("LiveByAttempt after a lost reply = %v, want a1:1 (the launch happened)", live) } again := mustLaunch(t, f, fakeSpec("a1")) if live := f.LiveByAttempt(); live["a1"] != 1 { t.Fatalf("LiveByAttempt after the retry = %v, want a1:1", live) } f.Inject(isolatedjob.OpStop, isolatedjob.FaultLostReply) if err := f.Stop(ctx, again, "test"); !errors.Is(err, isolatedjob.ErrLostReply) { t.Fatalf("lost-reply Stop = %v, want ErrLostReply", err) } wantState(t, f, again, isolatedjob.StateStopping) if err := f.Stop(ctx, again, "test"); err != nil { t.Fatalf("the next Stop = %v, want nil", err) } }) t.Run("lost reply on resume", func(t *testing.T) { f, _ := newFake(t) suspendedVM := func(attempt string) isolatedjob.Ref { ref := running(t, f, fakeSpec(attempt)) if err := f.Suspend(ctx, ref); err != nil { t.Fatal(err) } f.Tick() wantState(t, f, ref, isolatedjob.StateSuspended) return ref } lost := func(ref isolatedjob.Ref) { t.Helper() f.Inject(isolatedjob.OpResume, isolatedjob.FaultLostReply) err := f.Resume(ctx, ref) if !errors.Is(err, isolatedjob.ErrLostReply) || isSentinel(err) { t.Fatalf("lost-reply Resume(%s) = %v, want ErrLostReply and no sentinel", ref, err) } wantState(t, f, ref, isolatedjob.StateSuspended) } // The resume took effect: one Tick runs the VM with no second Resume. a := suspendedVM("a1") lost(a) f.Tick() wantState(t, f, a, isolatedjob.StateRunning) // A retry finds no fault left and changes nothing while the resume is pending. b := suspendedVM("a2") lost(b) if err := f.Resume(ctx, b); err != nil { t.Fatalf("retried Resume(%s) = %v, want nil", b, err) } wantState(t, f, b, isolatedjob.StateSuspended) f.Tick() wantState(t, f, b, isolatedjob.StateRunning) if err := f.Resume(ctx, b); err != nil { t.Fatalf("Resume(%s) once running = %v, want nil", b, err) } }) t.Run("incomplete list", func(t *testing.T) { f, _ := newFake(t) ref := mustLaunch(t, f, fakeSpec("a1")) f.Inject(isolatedjob.OpList, isolatedjob.FaultIncompleteList) jobs, err := f.List(ctx) if !errors.Is(err, isolatedjob.ErrIncomplete) || jobs != nil { t.Fatalf("faulted List = (%v, %v), want (nil, ErrIncomplete)", jobs, err) } jobs, err = f.List(ctx) if err != nil || len(jobs) != 1 || jobs[0].Ref != ref { t.Fatalf("the next List = (%v, %v), want just %s", jobs, err, ref) } }) t.Run("unknown state on get", func(t *testing.T) { f, _ := newFake(t) ref := running(t, f, fakeSpec("a1")) f.Inject(isolatedjob.OpGet, isolatedjob.FaultUnknownState) wantState(t, f, ref, isolatedjob.StateUnknown) wantState(t, f, ref, isolatedjob.StateRunning) }) t.Run("age unknown on get", func(t *testing.T) { f, c := newFake(t) ref := running(t, f, fakeSpec("a1")) c.AdvanceMono(5 * time.Minute) f.Inject(isolatedjob.OpGet, isolatedjob.FaultAgeUnknown) if job := mustGet(t, f, ref); job.AgeKnown || job.State != isolatedjob.StateRunning { t.Fatalf("faulted Get = %+v, want AgeKnown false and still running", job) } if job := mustGet(t, f, ref); !job.AgeKnown || job.ProviderAge != 5*time.Minute { t.Fatalf("the next Get = %+v, want AgeKnown and ProviderAge 5m", job) } }) t.Run("faults queue in order", func(t *testing.T) { f, _ := newFake(t) ref := running(t, f, fakeSpec("a1")) f.Inject(isolatedjob.OpSuspend, isolatedjob.FaultThrottle) f.Inject(isolatedjob.OpSuspend, isolatedjob.FaultLostReply) if err := f.Suspend(ctx, ref); !errors.Is(err, isolatedjob.ErrThrottled) { t.Fatalf("first Suspend = %v, want ErrThrottled", err) } wantState(t, f, ref, isolatedjob.StateRunning) if err := f.Suspend(ctx, ref); !errors.Is(err, isolatedjob.ErrLostReply) { t.Fatalf("second Suspend = %v, want ErrLostReply", err) } wantState(t, f, ref, isolatedjob.StateSuspending) f.Tick() if err := f.Resume(ctx, ref); err != nil { t.Fatalf("Resume with no fault queued = %v", err) } }) t.Run("tick counts suspended time", func(t *testing.T) { f, c := newFake(t) ref := running(t, f, fakeSpec("a1")) // one-hour lifetime c.AdvanceMono(10 * time.Minute) if err := f.Suspend(ctx, ref); err != nil { t.Fatal(err) } f.Tick() c.AdvanceMono(49 * time.Minute) f.Tick() wantState(t, f, ref, isolatedjob.StateSuspended) c.AdvanceMono(time.Minute) f.Tick() wantState(t, f, ref, isolatedjob.StateStopping) f.Tick() job := mustGet(t, f, ref) if job.State != isolatedjob.StateStopped || !strings.Contains(job.Reason, "lifetime") { t.Fatalf("Get after the backstop = %+v, want stopped with a lifetime reason", job) } if live := f.LiveByAttempt(); len(live) != 0 { t.Fatalf("LiveByAttempt = %v, want none", live) } }) t.Run("suspended time excluded when the provider says so", func(t *testing.T) { c := isolatedjobtest.NewFakeClock(fakeStart) l := isolatedjob.SpikeLimits() l.SuspendUsesLifetime = false f := isolatedjob.NewFake(c, l) ref := running(t, f, fakeSpec("a1")) c.AdvanceMono(10 * time.Minute) if err := f.Suspend(ctx, ref); err != nil { t.Fatal(err) } f.Tick() c.AdvanceMono(2 * time.Hour) f.Tick() wantState(t, f, ref, isolatedjob.StateSuspended) if err := f.Resume(ctx, ref); err != nil { t.Fatal(err) } c.AdvanceMono(49 * time.Minute) f.Tick() wantState(t, f, ref, isolatedjob.StateRunning) c.AdvanceMono(time.Minute) f.Tick() wantState(t, f, ref, isolatedjob.StateStopping) }) } func TestFakeLifecycle(t *testing.T) { ctx := context.Background() t.Run("states step on tick", func(t *testing.T) { f, _ := newFake(t) ref := mustLaunch(t, f, fakeSpec("a1")) wantState(t, f, ref, isolatedjob.StateStarting) if err := f.Suspend(ctx, ref); !errors.Is(err, isolatedjob.ErrConflict) { t.Fatalf("Suspend while starting = %v, want ErrConflict", err) } if err := f.Resume(ctx, ref); !errors.Is(err, isolatedjob.ErrConflict) { t.Fatalf("Resume while starting = %v, want ErrConflict", err) } f.Tick() wantState(t, f, ref, isolatedjob.StateRunning) if err := f.Suspend(ctx, ref); err != nil { t.Fatal(err) } wantState(t, f, ref, isolatedjob.StateSuspending) if err := f.Suspend(ctx, ref); !errors.Is(err, isolatedjob.ErrConflict) { t.Fatalf("Suspend while suspending = %v, want ErrConflict", err) } f.Tick() wantState(t, f, ref, isolatedjob.StateSuspended) if err := f.Resume(ctx, ref); err != nil { t.Fatal(err) } f.Tick() wantState(t, f, ref, isolatedjob.StateRunning) if err := f.Stop(ctx, ref, "done"); err != nil { t.Fatal(err) } wantState(t, f, ref, isolatedjob.StateStopping) if err := f.Resume(ctx, ref); !errors.Is(err, isolatedjob.ErrConflict) { t.Fatalf("Resume while stopping = %v, want ErrConflict", err) } f.Tick() if job := mustGet(t, f, ref); job.State != isolatedjob.StateStopped || job.Reason != "done" { t.Fatalf("Get after stop = %+v, want stopped with reason done", job) } for _, call := range []func(context.Context, isolatedjob.Ref) error{f.Suspend, f.Resume} { if err := call(ctx, "vm-missing"); !errors.Is(err, isolatedjob.ErrNotFound) { t.Fatalf("Suspend or Resume of an unknown ref = %v, want ErrNotFound", err) } } if _, err := f.Get(ctx, "vm-missing"); !errors.Is(err, isolatedjob.ErrNotFound) { t.Fatalf("Get of an unknown ref = %v, want ErrNotFound", err) } }) t.Run("resume reports suspended until the next tick", func(t *testing.T) { f, _ := newFake(t) suspended := func(attempt string) isolatedjob.Ref { ref := running(t, f, fakeSpec(attempt)) if err := f.Suspend(ctx, ref); err != nil { t.Fatal(err) } f.Tick() wantState(t, f, ref, isolatedjob.StateSuspended) return ref } ref := suspended("a1") for i := 1; i <= 2; i++ { if err := f.Resume(ctx, ref); err != nil { t.Fatalf("Resume %d while the resume is pending = %v, want nil", i, err) } wantState(t, f, ref, isolatedjob.StateSuspended) } f.Tick() wantState(t, f, ref, isolatedjob.StateRunning) f.Tick() wantState(t, f, ref, isolatedjob.StateRunning) // Stop while the resume is pending stops the VM; the resume is dropped. other := suspended("a2") if err := f.Resume(ctx, other); err != nil { t.Fatal(err) } if err := f.Stop(ctx, other, "stop mid-resume"); err != nil { t.Fatal(err) } wantState(t, f, other, isolatedjob.StateStopping) f.Tick() wantState(t, f, other, isolatedjob.StateStopped) }) t.Run("launch replays after stop and refuses bad specs", func(t *testing.T) { f, _ := newFake(t) ref := mustLaunch(t, f, fakeSpec("a1")) if err := f.Stop(ctx, ref, "x"); err != nil { t.Fatal(err) } f.Tick() if again := mustLaunch(t, f, fakeSpec("a1")); again != ref { t.Fatalf("Launch after stop = %s, want the stopped VM %s (client token replay)", again, ref) } calls := f.Calls(isolatedjob.OpLaunch) f.Inject(isolatedjob.OpLaunch, isolatedjob.FaultThrottle) bad := fakeSpec("a2") bad.Size = "medium" if _, err := f.Launch(ctx, bad); !errors.Is(err, isolatedjob.ErrInvalid) { t.Fatalf("Launch with a bad size = %v, want ErrInvalid", err) } big := fakeSpec("a3") big.Bootstrap = make([]byte, f.Limits().MaxBootstrapBytes+1) if _, err := f.Launch(ctx, big); !errors.Is(err, isolatedjob.ErrBootstrapTooLarge) { t.Fatalf("Launch with an oversized bootstrap = %v, want ErrBootstrapTooLarge", err) } if got := f.Calls(isolatedjob.OpLaunch); got != calls { t.Fatalf("Calls(OpLaunch) = %d after two refused specs, want %d: a bad spec must not reach the provider", got, calls) } if _, err := f.Launch(ctx, fakeSpec("a4")); !errors.Is(err, isolatedjob.ErrThrottled) { t.Fatalf("next good Launch = %v, want the queued ErrThrottled (a refused spec takes no fault)", err) } if got := f.Calls(isolatedjob.OpLaunch); got != calls+1 { t.Fatalf("Calls(OpLaunch) = %d after a throttled launch, want %d", got, calls+1) } if jobs, _ := f.List(ctx); len(jobs) != 1 { t.Fatalf("List = %v, want only the first VM", jobs) } }) t.Run("vanish hides the VM but keeps its client token", func(t *testing.T) { f, _ := newFake(t) gone := running(t, f, fakeSpec("a1")) kept := running(t, f, fakeSpec("a2")) f.Vanish(gone) f.Vanish("vm-missing") // a ref the fake never held changes nothing if _, err := f.Get(ctx, gone); !errors.Is(err, isolatedjob.ErrNotFound) { t.Fatalf("Get of a vanished VM = %v, want ErrNotFound", err) } jobs, err := f.List(ctx) if err != nil || len(jobs) != 1 || jobs[0].Ref != kept { t.Fatalf("List after vanish = (%v, %v), want just %s", jobs, err, kept) } if live := f.LiveByAttempt(); len(live) != 1 || live["a2"] != 1 { t.Fatalf("LiveByAttempt after vanish = %v, want a2:1", live) } if stops := f.StopsIssued(); len(stops) != 0 { t.Fatalf("StopsIssued after vanish = %v, want none: the controller stopped nothing", stops) } for name, call := range map[string]func(context.Context, isolatedjob.Ref) error{"Suspend": f.Suspend, "Resume": f.Resume} { if err := call(ctx, gone); !errors.Is(err, isolatedjob.ErrNotFound) { t.Fatalf("%s of a vanished VM = %v, want ErrNotFound", name, err) } } if err := f.Stop(ctx, gone, "late"); err != nil { t.Fatalf("Stop of a vanished VM = %v, want nil", err) } f.Tick() if _, err := f.Get(ctx, gone); !errors.Is(err, isolatedjob.ErrNotFound) { t.Fatalf("Get of a vanished VM after Stop and Tick = %v, want ErrNotFound", err) } if again := mustLaunch(t, f, fakeSpec("a1")); again != gone { t.Fatalf("Launch replay after vanish = %s, want %s (the client token outlives the VM)", again, gone) } changed := fakeSpec("a1") changed.Bootstrap = []byte("another-code") if _, err := f.Launch(ctx, changed); !errors.Is(err, isolatedjob.ErrConflict) { t.Fatalf("Launch of a changed spec after vanish = %v, want ErrConflict", err) } if live := f.LiveByAttempt(); len(live) != 1 || live["a2"] != 1 { t.Fatalf("LiveByAttempt after the replay = %v, want a2:1", live) } }) t.Run("times come from the clock", func(t *testing.T) { f, c := newFake(t) ref := mustLaunch(t, f, fakeSpec("a1")) c.SetWall(fakeStart.Add(-24 * time.Hour)) c.AdvanceMono(90 * time.Second) job := mustGet(t, f, ref) if !job.StartedAt.Equal(fakeStart) || job.ProviderAge != 90*time.Second || !job.AgeKnown { t.Fatalf("Get = %+v, want StartedAt %v, ProviderAge 90s, AgeKnown", job, fakeStart) } }) t.Run("backstop off keeps the VM", func(t *testing.T) { f, c := newFake(t) f.SetBackstop(false) ref := running(t, f, fakeSpec("a1")) c.AdvanceMono(2 * time.Hour) f.Tick() wantState(t, f, ref, isolatedjob.StateRunning) f.SetBackstop(true) f.Tick() wantState(t, f, ref, isolatedjob.StateStopping) }) t.Run("plant, live count and stops issued", func(t *testing.T) { f, _ := newFake(t) orphan := f.Plant(fakeSpec("a1")) wantState(t, f, orphan, isolatedjob.StateRunning) other := mustLaunch(t, f, fakeSpec("a2")) if live := f.LiveByAttempt(); len(live) != 2 || live["a1"] != 1 || live["a2"] != 1 { t.Fatalf("LiveByAttempt = %v, want a1:1 a2:1", live) } for _, r := range []isolatedjob.Ref{orphan, "vm-missing", orphan} { if err := f.Stop(ctx, r, "reap"); err != nil { t.Fatalf("Stop(%s) = %v", r, err) } } want := []isolatedjob.Ref{orphan, "vm-missing", orphan} if got := f.StopsIssued(); !slices.Equal(got, want) { t.Fatalf("StopsIssued = %v, want %v", got, want) } f.Tick() if live := f.LiveByAttempt(); len(live) != 1 || live["a2"] != 1 { t.Fatalf("LiveByAttempt after the reap = %v, want a2:1 (%s)", live, other) } }) t.Run("network audit", func(t *testing.T) { f, _ := newFake(t) a, err := f.AuditNetwork(ctx) if err != nil || a.OK(nil) != nil { t.Fatalf("default AuditNetwork = (%+v, %v), want a passing audit", a, err) } set := isolatedjob.NetworkAudit{EgressOnly: []netip.AddrPort{netip.MustParseAddrPort("10.0.0.1:3128")}} boom := errors.New("describe failed") f.SetAudit(set, boom) a, err = f.AuditNetwork(ctx) if !errors.Is(err, boom) || len(a.EgressOnly) != 1 { t.Fatalf("AuditNetwork after SetAudit = (%+v, %v)", a, err) } }) t.Run("concurrent launches of one attempt", func(t *testing.T) { f, _ := newFake(t) refs := make([]isolatedjob.Ref, 20) var wg sync.WaitGroup for i := range refs { wg.Go(func() { ref, err := f.Launch(ctx, fakeSpec("a1")) if err != nil { t.Errorf("Launch = %v", err) } refs[i] = ref }) } wg.Wait() if live := f.LiveByAttempt(); live["a1"] != 1 { t.Fatalf("LiveByAttempt = %v, want a1:1", live) } for _, r := range refs { if r != refs[0] { t.Fatalf("refs = %v, want all the same", refs) } } }) t.Run("inject refuses a fault the op cannot have", func(t *testing.T) { f, _ := newFake(t) defer func() { if recover() == nil { t.Fatal("Inject(OpGet, FaultIncompleteList) did not panic") } }() f.Inject(isolatedjob.OpGet, isolatedjob.FaultIncompleteList) }) t.Run("limits as the spike found", func(t *testing.T) { want := isolatedjob.Limits{MaxLifetime: 28800 * time.Second, MaxBootstrapBytes: 4096, SuspendUsesLifetime: true} if got := isolatedjob.SpikeLimits(); got != want { t.Fatalf("SpikeLimits = %+v, want %+v", got, want) } f, _ := newFake(t) if f.Limits() != want { t.Fatalf("Limits = %+v, want %+v", f.Limits(), want) } }) }