//go:build linux package host import ( "context" "github.com/carlosframework/platform/internal/hostbox" "github.com/carlosframework/platform/internal/instancectl" "testing" ) type rev3SetupUnits struct { *launchUnits setup func() tenant int } // Rev 2 calls this path: asynchronous setup happens after its only check. func (u *rev3SetupUnits) StartChecked(ctx context.Context, in instancectl.ClaimUnit, l instancectl.Launch, check func() error) (instancectl.ClaimUnitStarted, error) { s, err := u.launchUnits.StartChecked(ctx, in, l, check) if err != nil { return s, err } u.setup() u.tenant++ return s, nil } func TestRev3ExpiryDuringUnitSetup(t *testing.T) { f := newLaunchFixture(t, rev2Operation()) u := &rev3SetupUnits{launchUnits: f.units, setup: func() { f.root.Clock.(*rev2Clock).boot = 1000 }} f.root.Units = u _, err := f.root.Serve(t.Context(), f.peer, f.req) if err == nil || u.tenant != 0 { t.Fatalf("expired during namespace setup: grant error=%v tenant executions=%d", err, u.tenant) } r, e := f.journal.UnitReservation(t.Context(), f.target, f.req.Reservation.ID) if e != nil || r.State != hostbox.UnitSettled { t.Fatalf("failed launch not settled: %+v %v", r, e) } } func (u *rev3SetupUnits) StartReserved(ctx context.Context, in instancectl.ClaimUnit, l instancectl.Launch, p instancectl.ClaimExecPermit, check func() error) (instancectl.ClaimUnitStarted, error) { s, err := u.launchUnits.StartChecked(ctx, in, l, check) if err != nil { return s, err } u.setup() if err = check(); err != nil { _ = u.Stop(ctx, in.Host) return instancectl.ClaimUnitStarted{}, err } u.tenant++ return s, nil }