Skip to content

Commit fbfce84

Browse files
committed
fix(server): a restarted launcher repoints the unit after any finished update
1 parent b6dc360 commit fbfce84

2 files changed

Lines changed: 48 additions & 48 deletions

File tree

‎apps/server/src/serviceLauncher.test.ts‎

Lines changed: 48 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -236,53 +236,55 @@ it.layer(NodeServices.layer)("service state persistence", (it) => {
236236
}),
237237
);
238238

239-
it.effect("a fresh launcher repoints a unit left behind by an interrupted commit", () =>
240-
Effect.gen(function* () {
241-
const fs = yield* FileSystem.FileSystem;
242-
const path = yield* Path.Path;
243-
const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-service-launcher-repoint-" });
244-
const statePath = path.join(root, "runtime", "service-state.json");
245-
yield* writeFakeRuntime(
246-
fs,
247-
path,
248-
path.join(root, "runtime", "versions", "1.1.0"),
249-
"setInterval(() => {}, 1_000);\n",
250-
);
251-
yield* Effect.promise(() =>
252-
writeServiceState(statePath, {
253-
protocol: SERVICE_LAUNCHER_PROTOCOL,
254-
activeVersion: "1.1.0",
255-
update: {
256-
id: "update-1",
257-
fromVersion: "1.0.0",
258-
targetVersion: "1.1.0",
259-
status: "committed",
260-
},
261-
}),
262-
);
263-
const unit = yield* fakeServiceUnit(fs, path, root, "1.0.0");
264-
const run = () =>
265-
Effect.gen(function* () {
266-
const launcher = new Launcher(
267-
root,
268-
yield* Effect.promise(() => readServiceState(statePath)),
269-
{ serviceUnit: unit },
270-
);
271-
const running = launcher.run();
272-
yield* Effect.promise(() => launcher.stop("SIGTERM"));
273-
yield* Effect.promise(() => running);
274-
});
275-
276-
yield* run();
277-
assert.equal(
278-
yield* fs.readFileString(unit.path),
279-
renderBootServiceUnit(unitPlan(root, "1.1.0")),
280-
);
281-
assert.equal(unit.reloads, 1);
239+
it.effect.each(["committed", "rolled-back"] as const)(
240+
"a fresh launcher repoints a unit left behind by a %s update",
241+
(status) =>
242+
Effect.gen(function* () {
243+
const fs = yield* FileSystem.FileSystem;
244+
const path = yield* Path.Path;
245+
const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-service-launcher-repoint-" });
246+
const statePath = path.join(root, "runtime", "service-state.json");
247+
yield* writeFakeRuntime(
248+
fs,
249+
path,
250+
path.join(root, "runtime", "versions", "1.1.0"),
251+
"setInterval(() => {}, 1_000);\n",
252+
);
253+
yield* Effect.promise(() =>
254+
writeServiceState(statePath, {
255+
protocol: SERVICE_LAUNCHER_PROTOCOL,
256+
activeVersion: "1.1.0",
257+
update: {
258+
id: "update-1",
259+
fromVersion: status === "committed" ? "1.0.0" : "1.1.0",
260+
targetVersion: status === "committed" ? "1.1.0" : "1.2.0",
261+
status,
262+
},
263+
}),
264+
);
265+
const unit = yield* fakeServiceUnit(fs, path, root, "1.0.0");
266+
const run = () =>
267+
Effect.gen(function* () {
268+
const launcher = new Launcher(
269+
root,
270+
yield* Effect.promise(() => readServiceState(statePath)),
271+
{ serviceUnit: unit },
272+
);
273+
const running = launcher.run();
274+
yield* Effect.promise(() => launcher.stop("SIGTERM"));
275+
yield* Effect.promise(() => running);
276+
});
277+
278+
yield* run();
279+
assert.equal(
280+
yield* fs.readFileString(unit.path),
281+
renderBootServiceUnit(unitPlan(root, "1.1.0")),
282+
);
283+
assert.equal(unit.reloads, 1);
282284

283-
yield* run();
284-
assert.equal(unit.reloads, 1);
285-
}),
285+
yield* run();
286+
assert.equal(unit.reloads, 1);
287+
}),
286288
);
287289

288290
it.effect("stays idle instead of exiting when another server owns the T3 home", () =>

‎apps/server/src/serviceLauncher.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -617,8 +617,6 @@ export class Launcher {
617617
if (update?.status !== "pending") {
618618
if (update !== undefined) {
619619
await discardDatabaseBackup(this.#baseDir, update.id).catch(() => undefined);
620-
}
621-
if (update?.status === "committed") {
622620
await this.#repointServiceUnit(this.#state.activeVersion);
623621
}
624622
await this.#startChild(this.#state.activeVersion, "active", update);

0 commit comments

Comments
 (0)