Skip to content

Commit 2556793

Browse files
test(desktop): cut quit-wait tests to the regressions they catch
Drop the evidence driver script and tests that main's quit-budget test or the type system already cover. Extend the quit-budget test past the deadline and keep the concurrent-unregister case with its fake inlined. AI-assisted; verified with the tests and tools listed above.
1 parent efc4ef6 commit 2556793

4 files changed

Lines changed: 61 additions & 471 deletions

File tree

‎apps/desktop/scripts/quit-lock-evidence.sh‎

Lines changed: 0 additions & 200 deletions
This file was deleted.

‎apps/desktop/src/backend/DesktopBackendManager.test.ts‎

Lines changed: 5 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import { HttpClient, HttpClientRequest, HttpClientResponse } from "effect/http";
2525
import { ChildProcess, ChildProcessSpawner } from "effect/process";
2626

2727
import * as DesktopBackendManager from "./DesktopBackendManager.ts";
28-
import { makeFakeBackendProcess } from "./testUtils/FakeBackendProcess.ts";
2928
import * as DesktopObservability from "../app/DesktopObservability.ts";
3029
import * as DesktopTelemetryPublisher from "../telemetry/DesktopTelemetryPublisher.ts";
3130
import * as DesktopBrowserHost from "../preview/DesktopBrowserHost.ts";
@@ -530,94 +529,6 @@ describe("DesktopBackendManager", () => {
530529
),
531530
);
532531

533-
it.effect(
534-
"stop with the five-second quit timeout waits for a SIGTERM-ignoring backend to be gone",
535-
() =>
536-
Effect.scoped(
537-
Effect.gen(function* () {
538-
const backend = yield* makeFakeBackendProcess(false);
539-
const ready = yield* Deferred.make<void>();
540-
const instance = yield* makeTestInstance({
541-
spawnerLayer: backend.layer,
542-
onReady: Deferred.succeed(ready, undefined).pipe(Effect.asVoid),
543-
});
544-
yield* instance.start;
545-
yield* backend.started;
546-
yield* Deferred.await(ready);
547-
548-
const stopFiber = yield* instance
549-
.stop({ timeout: Duration.seconds(5) })
550-
.pipe(Effect.forkChild);
551-
assert.equal(yield* Queue.take(backend.signals), "SIGTERM");
552-
yield* TestClock.adjust(Duration.seconds(5));
553-
assert.equal(yield* Queue.take(backend.signals), "SIGKILL");
554-
const completedBeforeExit = yield* Effect.sync(() => stopFiber.pollUnsafe());
555-
const runningBeforeExit = yield* backend.isRunning;
556-
yield* TestClock.adjust(backend.killWait);
557-
yield* Fiber.join(stopFiber);
558-
559-
assert.isTrue(
560-
completedBeforeExit === undefined,
561-
"stop resolved before the backend exited",
562-
);
563-
assert.isTrue(runningBeforeExit);
564-
assert.isFalse(yield* backend.isRunning);
565-
assert.deepEqual(backend.receivedSignals, ["SIGTERM", "SIGKILL"]);
566-
assert.isTrue(Option.isNone((yield* instance.snapshot).activePid));
567-
yield* instance.stop();
568-
assert.deepEqual(backend.receivedSignals, ["SIGTERM", "SIGKILL"]);
569-
}),
570-
),
571-
);
572-
573-
it.effect("the shared quit budget is strictly greater than terminate grace plus kill wait", () =>
574-
Effect.scoped(
575-
Effect.gen(function* () {
576-
const backend = yield* makeFakeBackendProcess(true);
577-
const instance = yield* makeTestInstance({ spawnerLayer: backend.layer });
578-
yield* instance.start;
579-
yield* backend.started;
580-
const terminateGrace = yield* backend.terminateGrace;
581-
yield* instance.stop();
582-
583-
assert.isAbove(
584-
Duration.toMillis(DesktopBackendManager.BACKEND_QUIT_TIMEOUT),
585-
Duration.toMillis(terminateGrace) + Duration.toMillis(backend.killWait),
586-
);
587-
}),
588-
),
589-
);
590-
591-
it.effect("a cooperative backend stops on SIGTERM without SIGKILL", () =>
592-
Effect.scoped(
593-
Effect.gen(function* () {
594-
const backend = yield* makeFakeBackendProcess(true);
595-
const ready = yield* Deferred.make<void>();
596-
const instance = yield* makeTestInstance({
597-
spawnerLayer: backend.layer,
598-
onReady: Deferred.succeed(ready, undefined).pipe(Effect.asVoid),
599-
});
600-
yield* instance.start;
601-
yield* backend.started;
602-
yield* Deferred.await(ready);
603-
604-
yield* instance.stop({ timeout: Duration.seconds(5) });
605-
606-
assert.isFalse(yield* backend.isRunning);
607-
assert.deepEqual(backend.receivedSignals, ["SIGTERM"]);
608-
assert.deepEqual(yield* instance.snapshot, {
609-
desiredRunning: false,
610-
ready: false,
611-
activePid: Option.none(),
612-
restartAttempt: 0,
613-
restartScheduled: false,
614-
});
615-
yield* instance.stop();
616-
assert.deepEqual(backend.receivedSignals, ["SIGTERM"]);
617-
}),
618-
),
619-
);
620-
621532
it.effect("restarts when start is requested during stop teardown", () =>
622533
Effect.scoped(
623534
Effect.gen(function* () {
@@ -811,14 +722,12 @@ describe("DesktopBackendManager", () => {
811722
),
812723
);
813724

814-
it.effect("the quit stop deadline waits for a backend that only exits at the force kill", () =>
725+
it.effect("the quit stop keeps waiting for a backend that outlasts its deadline", () =>
815726
Effect.scoped(
816727
Effect.gen(function* () {
817728
const spawned = yield* Deferred.make<void>();
818729
const teardownStarted = yield* Deferred.make<void>();
819730
const teardownFinished = yield* Deferred.make<void>();
820-
// The real spawner sends SIGTERM, waits the grace, then SIGKILLs. A backend that
821-
// ignores SIGTERM therefore finishes tearing down just after the grace.
822731
const instance = yield* makeTestInstance({
823732
spawnerLayer: Layer.succeed(
824733
ChildProcessSpawner.ChildProcessSpawner,
@@ -829,7 +738,7 @@ describe("DesktopBackendManager", () => {
829738
yield* Scope.addFinalizer(
830739
scope,
831740
Deferred.succeed(teardownStarted, undefined).pipe(
832-
Effect.andThen(Effect.sleep(Duration.seconds(6))),
741+
Effect.andThen(Effect.sleep(Duration.seconds(10))),
833742
Effect.andThen(Deferred.succeed(teardownFinished, undefined)),
834743
Effect.asVoid,
835744
),
@@ -854,11 +763,11 @@ describe("DesktopBackendManager", () => {
854763
.pipe(Effect.andThen(Deferred.succeed(quitDone, undefined)), Effect.forkChild);
855764

856765
yield* Deferred.await(teardownStarted);
857-
// Past the SIGTERM grace but before the force kill lands: quit must still be waiting.
858-
yield* TestClock.adjust(Duration.millis(5_500));
766+
// Past the quit deadline, quit must still wait for the backend to exit.
767+
yield* TestClock.adjust(Duration.seconds(9));
859768
assert.isFalse(yield* Deferred.isDone(quitDone));
860769

861-
yield* TestClock.adjust(Duration.millis(500));
770+
yield* TestClock.adjust(Duration.seconds(1));
862771
yield* Fiber.join(quitFiber);
863772
assert.isTrue(yield* Deferred.isDone(teardownFinished));
864773
}).pipe(Effect.provide(TestClock.layer())),

0 commit comments

Comments
 (0)