fix(targets): cancel startup and probe PE offsets
This commit is contained in:
@@ -41,6 +41,23 @@ class FixtureLauncher implements BridgeLauncher {
|
||||
}
|
||||
}
|
||||
|
||||
class SilentLauncher implements BridgeLauncher {
|
||||
launch() {
|
||||
return Promise.resolve(
|
||||
ok({
|
||||
process: spawn(
|
||||
process.execPath,
|
||||
["-e", "setInterval(() => {}, 1000)"],
|
||||
{
|
||||
stdio: ["ignore", "ignore", "pipe"],
|
||||
},
|
||||
),
|
||||
ownsProcessLifetime: true,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const clients: HopperClient[] = [];
|
||||
const startClient = async () => {
|
||||
const client = new HopperClient({
|
||||
@@ -136,6 +153,24 @@ describe("HopperClient", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("cancels bridge startup without waiting for the startup timeout", async () => {
|
||||
const client = new HopperClient({
|
||||
launcher: new SilentLauncher(),
|
||||
startupTimeoutMs: 10_000,
|
||||
});
|
||||
clients.push(client);
|
||||
const controller = new AbortController();
|
||||
const startedAt = Date.now();
|
||||
const pending = client.callTool("echo", {}, { signal: controller.signal });
|
||||
setTimeout(() => {
|
||||
controller.abort();
|
||||
}, 10);
|
||||
const result = await pending;
|
||||
expect(result.ok).toBe(false);
|
||||
if (!result.ok) expect(result.error._tag).toBe("HopperCancelledError");
|
||||
expect(Date.now() - startedAt).toBeLessThan(500);
|
||||
});
|
||||
|
||||
it("ignores more than 1,024 late responses without corrupting the session", async () => {
|
||||
const client = await startClient();
|
||||
const timedOut = await Promise.all(
|
||||
|
||||
Reference in New Issue
Block a user