carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1//go:build linux
2
3package host
4
5import (
6 "context"
7 "github.com/carlosframework/platform/internal/hostbox"
8 "github.com/carlosframework/platform/internal/instancectl"
9 "testing"
10)
11
12type rev3SetupUnits struct {
13 *launchUnits
14 setup func()
15 tenant int
16}
17
18// Rev 2 calls this path: asynchronous setup happens after its only check.
19func (u *rev3SetupUnits) StartChecked(ctx context.Context, in instancectl.ClaimUnit, l instancectl.Launch, check func() error) (instancectl.ClaimUnitStarted, error) {
20 s, err := u.launchUnits.StartChecked(ctx, in, l, check)
21 if err != nil {
22 return s, err
23 }
24 u.setup()
25 u.tenant++
26 return s, nil
27}
28func TestRev3ExpiryDuringUnitSetup(t *testing.T) {
29 f := newLaunchFixture(t, rev2Operation())
30 u := &rev3SetupUnits{launchUnits: f.units, setup: func() { f.root.Clock.(*rev2Clock).boot = 1000 }}
31 f.root.Units = u
32 _, err := f.root.Serve(t.Context(), f.peer, f.req)
33 if err == nil || u.tenant != 0 {
34 t.Fatalf("expired during namespace setup: grant error=%v tenant executions=%d", err, u.tenant)
35 }
36 r, e := f.journal.UnitReservation(t.Context(), f.target, f.req.Reservation.ID)
37 if e != nil || r.State != hostbox.UnitSettled {
38 t.Fatalf("failed launch not settled: %+v %v", r, e)
39 }
40}
41
42func (u *rev3SetupUnits) StartReserved(ctx context.Context, in instancectl.ClaimUnit, l instancectl.Launch, p instancectl.ClaimExecPermit, check func() error) (instancectl.ClaimUnitStarted, error) {
43 s, err := u.launchUnits.StartChecked(ctx, in, l, check)
44 if err != nil {
45 return s, err
46 }
47 u.setup()
48 if err = check(); err != nil {
49 _ = u.Stop(ctx, in.Host)
50 return instancectl.ClaimUnitStarted{}, err
51 }
52 u.tenant++
53 return s, nil
54}
55