| index 8ae3aee72..76b97cce4 100644 |
| --- a/internal/console/rootfs_test.go |
| +++ b/internal/console/rootfs_test.go |
| @@ -2,14 +2,18 @@ package console |
| |
| import ( |
| "context" |
| + "encoding/json" |
| "errors" |
| "fmt" |
| "net/http" |
| "strings" |
| + "sync" |
| + "sync/atomic" |
| "testing" |
| "time" |
| |
| "github.com/carlosframework/platform/internal/geo" |
| + "github.com/carlosframework/platform/internal/provision" |
| "github.com/carlosframework/platform/internal/registry" |
| "github.com/carlosframework/platform/internal/release" |
| "github.com/carlosframework/platform/internal/status" |
| @@ -71,6 +75,13 @@ func refStatus(ref *doorRefusal) int { |
| // registry, the owned fleets home and away (through the real door), and a |
| // fleet theirs that belongs to another account. |
| func rootfsDoorWorld(t *testing.T, code string) (*consoleFixture, *registry.Registry) { |
| + t.Helper() |
| + fx, _, reg := rootfsDoorWorldToken(t, code) |
| + return fx, reg |
| +} |
| + |
| +// rootfsDoorWorldToken is rootfsDoorWorld with the owner's CLI token. |
| +func rootfsDoorWorldToken(t *testing.T, code string) (*consoleFixture, string, *registry.Registry) { |
| t.Helper() |
| fx, token := fleetFixture(t, code) |
| if _, err := fx.st.CreateAppIn(OpsAccountID, "shop", "paul@keymail.dev", time.Now()); err != nil { |
| @@ -87,7 +98,7 @@ func rootfsDoorWorld(t *testing.T, code string) (*consoleFixture, *registry.Regi |
| if _, err := reg.CreateFleet(registry.Fleet{Name: "theirs", Account: "zzz", Bucket: "theirs-data"}); err != nil { |
| t.Fatal(err) |
| } |
| - return fx, reg |
| + return fx, token, reg |
| } |
| |
| // fleetFailReg is the registry with GetFleet and ListFleetBoxes failing. |
| @@ -299,3 +310,423 @@ func TestRootfsReadyRefusesWhenItCannotLook(t *testing.T) { |
| } |
| } |
| } |
| + |
| +// ---- Plan 4 Task 3: instance create mints rootfs records ---- |
| + |
| +const rootfsShopHost = "shop.example.com" |
| + |
| +// rootfsShopManifest is shop's instances manifest (row 2.9): no pool, no |
| +// seed, hosts under example.com, following channel edge. |
| +func rootfsShopManifest() provision.Manifest { |
| + return provision.Manifest{Schema: 1, App: "shop", Domain: "example.com", Channel: "edge"} |
| +} |
| + |
| +// rootfsCreateWorld is rootfsDoorWorld with shop's instances enabled from |
| +// m, and the owner's token. |
| +func rootfsCreateWorld(t *testing.T, code string, m provision.Manifest) (*consoleFixture, string, *registry.Registry) { |
| + t.Helper() |
| + fx, token, reg := rootfsDoorWorldToken(t, code) |
| + enableInstances(t, fx, "shop", m) |
| + return fx, token, reg |
| +} |
| + |
| +// placeShop places shop on fleet through the place door. A rootfs app is |
| +// placed before its first ship: the door refuses a rootfs-kind app (C24). |
| +func placeShop(t *testing.T, fx *consoleFixture, token, fleet string) { |
| + t.Helper() |
| + if code, _, raw := rawReq(t, http.MethodPost, placeURL(fx, "shop"), token, `{"target":"fleet/`+fleet+`"}`); code != http.StatusOK { |
| + t.Fatalf("place shop on %s = %d %s", fleet, code, raw) |
| + } |
| +} |
| + |
| +// fleetBoxNow registers label on fleet, active, with a fresh heartbeat. |
| +func fleetBoxNow(t *testing.T, fx *consoleFixture, reg *registry.Registry, fleet, label string, ready bool) { |
| + t.Helper() |
| + registerFleetBox(t, reg, fleet, label) |
| + writeFleetBox(t, fx, fleet, label, "", ready, time.Now()) |
| +} |
| + |
| +// shipShop ships rootfs release r1 of shop and points channel edge at it. |
| +func shipShop(t *testing.T, fx *consoleFixture, hibernate bool) { |
| + t.Helper() |
| + shipRootfsRelease(t, fx, "shop", "r1", hibernate) |
| + seedChannel(t, fx, "shop", "edge", "r1") |
| +} |
| + |
| +// placedRootfsApp is shop placed on fleet home with one box (ready or not), |
| +// manifest m, and rootfs r1 on edge. |
| +func placedRootfsApp(t *testing.T, code string, m provision.Manifest, ready, hibernate bool) (*consoleFixture, string) { |
| + t.Helper() |
| + fx, token, reg := rootfsCreateWorld(t, code, m) |
| + placeShop(t, fx, token, "home") |
| + fleetBoxNow(t, fx, reg, "home", "pi-1", ready) |
| + shipShop(t, fx, hibernate) |
| + return fx, token |
| +} |
| + |
| +// rootfsReadyFleetApp is shop on fleet home with a ready box and rootfs r1 |
| +// on edge. |
| +func rootfsReadyFleetApp(t *testing.T, code string, hibernate bool) (*consoleFixture, string) { |
| + t.Helper() |
| + return placedRootfsApp(t, code, rootfsShopManifest(), true, hibernate) |
| +} |
| + |
| +func readyApp(t *testing.T) (*consoleFixture, string) { |
| + return rootfsReadyFleetApp(t, "code-rfs-ready-app", false) |
| +} |
| + |
| +func notReadyFleetApp(t *testing.T) (*consoleFixture, string) { |
| + return placedRootfsApp(t, "code-rfs-not-ready", rootfsShopManifest(), false, false) |
| +} |
| + |
| +func pooledRootfsApp(t *testing.T) (*consoleFixture, string) { |
| + m := rootfsShopManifest() |
| + m.Pool = "gold" |
| + return placedRootfsApp(t, "code-rfs-pooled", m, true, false) |
| +} |
| + |
| +// unplacedRootfsApp is shop with no placement and rootfs r1 on edge. |
| +func unplacedRootfsApp(t *testing.T) (*consoleFixture, string) { |
| + t.Helper() |
| + fx, token, _ := rootfsCreateWorld(t, "code-rfs-unplaced", rootfsShopManifest()) |
| + shipShop(t, fx, false) |
| + return fx, token |
| +} |
| + |
| +func createShop(t *testing.T, fx *consoleFixture, token, body string) (int, string) { |
| + t.Helper() |
| + code, _, raw := rawReq(t, http.MethodPost, instancesURL(fx, fx.sqid, "shop"), token, body) |
| + return code, raw |
| +} |
| + |
| +// storedShop reads shop's record of host, and its stored JSON's keys. |
| +func storedShop(t *testing.T, fx *consoleFixture, host string) (*provision.Record, map[string]json.RawMessage) { |
| + t.Helper() |
| + rec, err := provision.GetRecord(context.Background(), fx.rel, fx.sqid, "shop", host) |
| + if err != nil { |
| + t.Fatalf("read %s: %v", host, err) |
| + } |
| + raw, _, err := fx.rel.Get(context.Background(), provision.RecordKey(fx.sqid, "shop", host)) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + var keys map[string]json.RawMessage |
| + if err := json.Unmarshal(raw, &keys); err != nil { |
| + t.Fatal(err) |
| + } |
| + return rec, keys |
| +} |
| + |
| +func noShopRecord(t *testing.T, fx *consoleFixture, host string) { |
| + t.Helper() |
| + if _, err := provision.GetRecord(context.Background(), fx.rel, fx.sqid, "shop", host); err == nil { |
| + t.Fatalf("a refused create wrote %s", host) |
| + } |
| +} |
| + |
| +func TestRootfsCreateMintsRuntimeAndAlwaysOn(t *testing.T) { |
| + fx, token := rootfsReadyFleetApp(t, "code-rfs-create", false) |
| + if code, out := createShop(t, fx, token, `{"host":"shop.example.com","channel":"edge"}`); code != http.StatusCreated { |
| + t.Fatalf("create = %d %s", code, out) |
| + } |
| + rec, _ := storedShop(t, fx, rootfsShopHost) |
| + if rec.Runtime != provision.RuntimeRootfsV1 || rec.Hibernate == nil || *rec.Hibernate { |
| + t.Fatalf("stored record %+v; want rootfs-v1 with an explicit hibernate false", rec) |
| + } |
| + if rec.Region != "fleet/home" || rec.HA { |
| + t.Fatalf("region %q, HA %v", rec.Region, rec.HA) |
| + } |
| +} |
| + |
| +func TestRootfsCreateTakesHibernateFromTheRelease(t *testing.T) { |
| + fx, token := rootfsReadyFleetApp(t, "code-rfs-create-hib", true) |
| + if code, out := createShop(t, fx, token, `{"host":"shop.example.com"}`); code != http.StatusCreated { |
| + t.Fatalf("create = %d %s", code, out) |
| + } |
| + if rec, _ := storedShop(t, fx, rootfsShopHost); rec.Runtime != provision.RuntimeRootfsV1 || rec.Hibernate == nil || !*rec.Hibernate { |
| + t.Fatalf("stored record %+v; want rootfs-v1 with hibernate true", rec) |
| + } |
| +} |
| + |
| +func TestRootfsCreateRefusals(t *testing.T) { |
| + for _, tc := range []struct { |
| + name string |
| + setup func(t *testing.T) (*consoleFixture, string) |
| + body string |
| + status int |
| + want string |
| + }{ |
| + {"unplaced on a shared deployment", unplacedRootfsApp, `{"host":"shop.example.com"}`, http.StatusConflict, fmt.Sprintf(rootfsNotOwnBoxesMsg, "shop")}, |
| + {"an explicit region on a shared deployment", unplacedRootfsApp, `{"host":"shop.example.com","region":"uk"}`, http.StatusConflict, fmt.Sprintf(rootfsNotOwnBoxesMsg, "shop")}, |
| + {"pooled manifest", pooledRootfsApp, `{"host":"shop.example.com"}`, http.StatusConflict, fmt.Sprintf(rootfsPoolMsg, "shop")}, |
| + {"no ready box on the fleet", notReadyFleetApp, `{"host":"shop.example.com"}`, http.StatusConflict, fmt.Sprintf(rootfsFleetNotReadyMsg, "home")}, |
| + {"seeded from a sibling", readyApp, `{"host":"shop.example.com","from":{"host":"www.example.com"}}`, http.StatusUnprocessableEntity, fmt.Sprintf(rootfsSeededMsg, "shop")}, |
| + {"imported", readyApp, `{"host":"shop.example.com","import":{"sha256":"` + strings.Repeat("a", 64) + `","bytes":1}}`, http.StatusUnprocessableEntity, fmt.Sprintf(rootfsSeededMsg, "shop")}, |
| + // Row 3.5: a fleet-placed app's replica is refused first by the |
| + // door's own 400, so C10 is reached on an unplaced app, where it |
| + // comes before C01. |
| + {"replica", unplacedRootfsApp, `{"host":"shop.example.com","role":"replica","region":"uk"}`, http.StatusUnprocessableEntity, fmt.Sprintf(rootfsReplicaMsg, "shop")}, |
| + } { |
| + t.Run(tc.name, func(t *testing.T) { |
| + fx, token := tc.setup(t) |
| + code, out := createShop(t, fx, token, tc.body) |
| + if code != tc.status || errorText(out) != tc.want { |
| + t.Fatalf("create = %d %s; want %d %q", code, out, tc.status, tc.want) |
| + } |
| + noShopRecord(t, fx, rootfsShopHost) |
| + }) |
| + } |
| +} |
| + |
| +// D9 and spec §5.7: a single-tenant deployment allows any box, but never a |
| +// pool. |
| +func TestRootfsCreateOnASingleTenantDeployment(t *testing.T) { |
| + fx, token := unplacedRootfsApp(t) |
| + fx.srv.cfg.DeploymentSingleTenant = true |
| + writeFleetBox(t, fx, "", "box-1", "", true, time.Now()) |
| + if code, out := createShop(t, fx, token, `{"host":"shop.example.com"}`); code != http.StatusCreated { |
| + t.Fatalf("create = %d %s", code, out) |
| + } |
| + if rec, _ := storedShop(t, fx, rootfsShopHost); rec.Runtime != provision.RuntimeRootfsV1 || rec.Hibernate == nil || *rec.Hibernate || rec.Region != "" { |
| + t.Fatalf("stored record %+v", rec) |
| + } |
| + |
| + fx, token, _ = rootfsCreateWorld(t, "code-rfs-single-pool", func() provision.Manifest { |
| + m := rootfsShopManifest() |
| + m.Pool = "gold" |
| + return m |
| + }()) |
| + shipShop(t, fx, false) |
| + fx.srv.cfg.DeploymentSingleTenant = true |
| + writeFleetBox(t, fx, "", "box-1", "", true, time.Now()) |
| + code, out := createShop(t, fx, token, `{"host":"shop.example.com"}`) |
| + if code != http.StatusConflict || errorText(out) != fmt.Sprintf(rootfsPoolMsg, "shop") { |
| + t.Fatalf("pooled create = %d %s; want 409 C02", code, out) |
| + } |
| + noShopRecord(t, fx, rootfsShopHost) |
| +} |
| + |
| +// Row 3.3: a rootfs record is never born HA (one box per instance, C7), |
| +// even on a single-tenant deployment whose home is an HA region, where the |
| +// same console stamps a binary instance HA. |
| +func TestRootfsCreateIsNeverBornHA(t *testing.T) { |
| + fx, token := unplacedRootfsApp(t) |
| + fx.srv.cfg.DeploymentSingleTenant = true |
| + fx.srv.cfg.HomeRegion = "ie" |
| + fx.srv.cfg.HARegions = []string{"ie"} |
| + writeFleetBox(t, fx, "", "box-1", "ie", true, time.Now()) |
| + if code, out := createShop(t, fx, token, `{"host":"shop.example.com"}`); code != http.StatusCreated { |
| + t.Fatalf("create = %d %s", code, out) |
| + } |
| + if rec, keys := storedShop(t, fx, rootfsShopHost); rec.Runtime != provision.RuntimeRootfsV1 || rec.HA || keys["ha"] != nil { |
| + t.Fatalf("stored record %+v; want rootfs-v1 and not HA", rec) |
| + } |
| + // The control: kass, a binary app, in the same HA home. |
| + enableInstances(t, fx, "kass", provision.Manifest{Schema: 1, App: "kass", Domain: "example.com", Channel: "stable"}) |
| + if code, _, out := rawReq(t, http.MethodPost, instancesURL(fx, fx.sqid, "kass"), token, `{"host":"kass.example.com"}`); code != http.StatusCreated { |
| + t.Fatalf("kass create = %d %s", code, out) |
| + } |
| + if rec, err := provision.GetRecord(context.Background(), fx.rel, fx.sqid, "kass", "kass.example.com"); err != nil || !rec.HA || rec.Runtime != "" { |
| + t.Fatalf("kass record %+v, %v; want binary and HA", rec, err) |
| + } |
| +} |
| + |
| +// shipBinaryRelease ships binary release v1 of shop and points edge at it. |
| +func shipBinaryRelease(t *testing.T, fx *consoleFixture) { |
| + t.Helper() |
| + m := release.Manifest{Schema: 1, App: "shop", Version: "v1", Kind: "binary", BuiltAt: "2026-10-24T10:00:00Z", |
| + Artifacts: map[string]release.Artifact{"linux-amd64": {File: "shop"}}} |
| + if err := release.Ship(context.Background(), fx.rel, fx.sqid, m, map[string][]byte{"linux-amd64": []byte("binary v1")}); err != nil { |
| + t.Fatal(err) |
| + } |
| + seedChannel(t, fx, "shop", "edge", "v1") |
| +} |
| + |
| +// A binary app's records are minted exactly as before: no runtime and no |
| +// hibernate key in the stored JSON, placed or not. |
| +func TestBinaryCreateIsUnchanged(t *testing.T) { |
| + for _, placed := range []bool{false, true} { |
| + t.Run(fmt.Sprintf("placed=%v", placed), func(t *testing.T) { |
| + fx, token, _ := rootfsCreateWorld(t, "code-rfs-binary-create", rootfsShopManifest()) |
| + if placed { |
| + placeShop(t, fx, token, "home") |
| + } |
| + shipBinaryRelease(t, fx) |
| + if code, out := createShop(t, fx, token, `{"host":"shop.example.com"}`); code != http.StatusCreated { |
| + t.Fatalf("create = %d %s", code, out) |
| + } |
| + rec, keys := storedShop(t, fx, rootfsShopHost) |
| + if rec.Runtime != "" || rec.Hibernate != nil || keys["runtime"] != nil || keys["hibernate"] != nil { |
| + t.Fatalf("stored record %+v (keys %v); want no runtime and no hibernate", rec, keys) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// A static record of a rootfs app is not a process the platform starts: it |
| +// is minted plain, and none of the rootfs refusals apply (this app is |
| +// unplaced on a shared deployment, which C01 refuses for an instance). |
| +func TestRootfsCreateStaticRecordStaysPlain(t *testing.T) { |
| + fx, token := unplacedRootfsApp(t) |
| + if code, out := createShop(t, fx, token, `{"host":"shop.example.com","kind":"static"}`); code != http.StatusCreated { |
| + t.Fatalf("static create = %d %s", code, out) |
| + } |
| + rec, keys := storedShop(t, fx, rootfsShopHost) |
| + if rec.Kind != "static" || rec.Runtime != "" || keys["runtime"] != nil || keys["hibernate"] != nil { |
| + t.Fatalf("stored record %+v; want a plain static record", rec) |
| + } |
| +} |
| + |
| +// Plans-caps 3b and 4c leave always-on rootfs instances alone (row 2.5): |
| +// with a plan catalog on, the create still mints hibernate false. |
| +func TestRootfsCreateUnderPlansMintsAlwaysOn(t *testing.T) { |
| + fx, token := rootfsReadyFleetApp(t, "code-rfs-create-plans", false) |
| + fx.srv.cfg.PlanCatalog = examplePlanCatalog(t) |
| + ops, _ := fx.st.AccountBySqid(fx.sqid) |
| + if _, err := fx.st.SetAccountPlan(ops.ID, "personal", nil, PlanSourceOperator, nil, "r", "ops@example.com", planNow); err != nil { |
| + t.Fatal(err) |
| + } |
| + if code, out := createShop(t, fx, token, `{"host":"shop.example.com"}`); code != http.StatusCreated { |
| + t.Fatalf("create = %d %s", code, out) |
| + } |
| + if rec, _ := storedShop(t, fx, rootfsShopHost); rec.Runtime != provision.RuntimeRootfsV1 || rec.Hibernate == nil || *rec.Hibernate { |
| + t.Fatalf("stored record %+v", rec) |
| + } |
| +} |
| + |
| +// establishShopRootfs fixes shop's kind rootfs as a first ship does before |
| +// it publishes: the marker only, no manifest. |
| +func establishShopRootfs(t *testing.T, fx *consoleFixture) { |
| + t.Helper() |
| + m := release.Manifest{Schema: 1, App: "shop", Version: "r1", Kind: release.KindRootfs, |
| + Artifacts: map[string]release.Artifact{release.RootfsArtifactKey: {File: release.RootfsArtifactFile, SHA256: strings.Repeat("a", 64), Size: 1}}, |
| + Processes: map[string]release.Process{release.ProcessWeb: {Command: []string{"/rails/bin/web"}}}} |
| + if err := release.EstablishFirstKind(context.Background(), fx.rel, fx.sqid, &m); err != nil { |
| + t.Fatal(err) |
| + } |
| +} |
| + |
| +// Astra R2 finding 2, the door's half: a first ship that has fixed the |
| +// kind and not yet published decides the create, never binary. |
| +func TestCreateHonoursTheMarkerOfAnUnpublishedFirstShip(t *testing.T) { |
| + fx, token, reg := rootfsCreateWorld(t, "code-rfs-marker-placed", rootfsShopManifest()) |
| + placeShop(t, fx, token, "home") |
| + fleetBoxNow(t, fx, reg, "home", "pi-1", true) |
| + establishShopRootfs(t, fx) |
| + if code, out := createShop(t, fx, token, `{"host":"shop.example.com"}`); code != http.StatusCreated { |
| + t.Fatalf("create = %d %s", code, out) |
| + } |
| + if rec, _ := storedShop(t, fx, rootfsShopHost); rec.Runtime != provision.RuntimeRootfsV1 || rec.Hibernate == nil || *rec.Hibernate { |
| + t.Fatalf("stored record %+v", rec) |
| + } |
| + |
| + fx, token, _ = rootfsCreateWorld(t, "code-rfs-marker-unplaced", rootfsShopManifest()) |
| + establishShopRootfs(t, fx) |
| + code, out := createShop(t, fx, token, `{"host":"shop.example.com"}`) |
| + if code != http.StatusConflict || errorText(out) != fmt.Sprintf(rootfsNotOwnBoxesMsg, "shop") { |
| + t.Fatalf("unplaced create = %d %s; want 409 C01", code, out) |
| + } |
| + noShopRecord(t, fx, rootfsShopHost) |
| +} |
| + |
| +// markerReadStore counts reads of one key. |
| +type markerReadStore struct { |
| + release.Store |
| + key string |
| + n atomic.Int32 |
| +} |
| + |
| +func (s *markerReadStore) Get(ctx context.Context, key string) ([]byte, string, error) { |
| + if key == s.key { |
| + s.n.Add(1) |
| + } |
| + return s.Store.Get(ctx, key) |
| +} |
| + |
| +// raceTheFirstShip holds shop's app lock as a first rootfs ship does, runs |
| +// create (a request to the door) until it has read shop's kind and is |
| +// waiting for the lock, then writes the rootfs kind marker under the lock |
| +// and lets go. It returns what create answered. |
| +func raceTheFirstShip(t *testing.T, fx *consoleFixture, create func() string) string { |
| + t.Helper() |
| + reads := &markerReadStore{Store: fx.srv.cfg.Releases, key: release.AppKindMarkerKey(fx.sqid, "shop")} |
| + fx.srv.cfg.Releases = reads |
| + t.Cleanup(func() { fx.srv.cfg.Releases = reads.Store }) |
| + waiting := make(chan struct{}) |
| + var once sync.Once |
| + h := func(kind, key, event string) { |
| + if kind == "app" && key == fx.sqid+"/shop" && event == lockWaiting && reads.n.Load() > 0 { |
| + once.Do(func() { close(waiting) }) |
| + } |
| + } |
| + lifetimeLockHook.Store(&h) |
| + t.Cleanup(func() { lifetimeLockHook.Store(nil) }) |
| + unlock := fx.srv.lockApp(fx.sqid, "shop") |
| + answered := make(chan string, 1) |
| + go func() { answered <- create() }() |
| + select { |
| + case <-waiting: |
| + case <-time.After(10 * time.Second): |
| + unlock() |
| + t.Fatalf("the create never waited for the app lock after reading the kind; it answered %s", <-answered) |
| + } |
| + putKindMarker(t, fx, release.KindRootfs) |
| + unlock() |
| + lifetimeLockHook.Store(nil) |
| + return <-answered |
| +} |
| + |
| +// Row 3.2, Review Focus: a first rootfs ship that fixes an unfixed app's |
| +// kind after the create door read it, and before the record writer took |
| +// the app lock, never gets a binary record of a rootfs app. The writer |
| +// reads the kind again under its lock, refuses with the door's try-again |
| +// sentence and writes nothing; the retry mints rootfs. Both writers: the |
| +// lifetimes-off create and the lifetime create. |
| +func TestCreateRechecksTheFirstKindUnderTheWritersLock(t *testing.T) { |
| + for _, lifetimes := range []bool{false, true} { |
| + t.Run(fmt.Sprintf("lifetimes=%v", lifetimes), func(t *testing.T) { |
| + var clock *lifetimesClock |
| + if lifetimes { |
| + clock = useLifetimesClock(t) |
| + } |
| + fx, token, reg := rootfsCreateWorld(t, "code-rfs-race", rootfsShopManifest()) |
| + placeShop(t, fx, token, "home") |
| + fleetBoxNow(t, fx, reg, "home", "pi-1", true) |
| + if lifetimes { |
| + turnLifetimesOn(t, fx.srv, clock) |
| + } |
| + got := raceTheFirstShip(t, fx, func() string { |
| + code, out := createShop(t, fx, token, `{"host":"shop.example.com"}`) |
| + return fmt.Sprintf("%d %s", code, errorText(out)) |
| + }) |
| + if want := fmt.Sprintf("%d %s", http.StatusBadGateway, "could not create the instance — try again"); got != want { |
| + t.Fatalf("create = %s, want %s", got, want) |
| + } |
| + noShopRecord(t, fx, rootfsShopHost) |
| + if code, out := createShop(t, fx, token, `{"host":"shop.example.com"}`); code != http.StatusCreated { |
| + t.Fatalf("retry = %d %s", code, out) |
| + } |
| + if rec, _ := storedShop(t, fx, rootfsShopHost); rec.Runtime != provision.RuntimeRootfsV1 || rec.Hibernate == nil || !*rec.Hibernate { |
| + t.Fatalf("retry stored %+v; want rootfs-v1 with the marker's hibernate true", rec) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// The seed doors write through the same writers, so a --from create of an |
| +// unfixed app that a first rootfs ship overtakes writes nothing either, and |
| +// its retry is the rootfs refusal C09. |
| +func TestSeedCreateRechecksTheFirstKindUnderTheWritersLock(t *testing.T) { |
| + f := newFromFixture(t, 1) |
| + got := raceTheFirstShip(t, f.fx, func() string { |
| + code, out := f.create(t, fromBody) |
| + return fmt.Sprintf("%d %v", code, out["error"]) |
| + }) |
| + if !strings.HasPrefix(got, fmt.Sprint(http.StatusBadGateway)+" ") { |
| + t.Fatalf("seed create = %s, want 502", got) |
| + } |
| + noShopRecord(t, f.fx, "canary.shop.example.com") |
| + if code, out := f.create(t, fromBody); code != http.StatusUnprocessableEntity || out["error"] != fmt.Sprintf(rootfsSeededMsg, "shop") { |
| + t.Fatalf("retry = %d %v; want 422 C09", code, out) |
| + } |
| +} |