aboutsummaryrefslogtreecommitdiff
path: root/test/manual/ipc-server-test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'test/manual/ipc-server-test.ts')
-rw-r--r--test/manual/ipc-server-test.ts22
1 files changed, 2 insertions, 20 deletions
diff --git a/test/manual/ipc-server-test.ts b/test/manual/ipc-server-test.ts
index b4da3df..1a67f1a 100644
--- a/test/manual/ipc-server-test.ts
+++ b/test/manual/ipc-server-test.ts
@@ -1,8 +1,3 @@
-/**
- * Manual smoke test for IpcServer.
- * Starts a server, connects a client, tests registration, send, broadcast, disconnect.
- * Run: npx tsx test/manual/ipc-server-test.ts
- */
import { createConnection } from "node:net";
import { createInterface } from "node:readline";
import { createIpcServer } from "../../src/daemon/server";
@@ -19,7 +14,6 @@ async function main() {
else { failed++; console.error(` ✗ ${label}`); }
};
- // ── Start server ──────────────────────────────────────────────────────
console.log("Starting IpcServer...");
const server = createIpcServer();
@@ -34,21 +28,18 @@ async function main() {
await server.start();
console.log("Server started ✓");
- // ── Connect client ────────────────────────────────────────────────────
console.log("\nConnecting client...");
const socket = createConnection(DAEMON_SOCKET_PATH);
const rl = createInterface({ input: socket, crlfDelay: Infinity });
const receivedByClient: WireMessage[] = [];
rl.on("line", (line) => {
- try { receivedByClient.push(JSON.parse(line)); } catch { /* ignore */ }
+ try { receivedByClient.push(JSON.parse(line)); } catch {}
});
await new Promise<void>((resolve) => socket.on("connect", resolve));
console.log("Client connected ✓");
- // ── Test 1: Registration ──────────────────────────────────────────────
- // Send register, expect registered ack.
socket.write(JSON.stringify({ type: "control", action: "register", clientId: TEST_CLIENT_ID }) + "\n");
await sleep(200);
@@ -56,7 +47,6 @@ async function main() {
check(ack != null, "Registration acknowledged");
check(connectCount === 1, "Connect handler fired");
- // ── Test 2: Send message to server ────────────────────────────────────
receivedByServer.length = 0;
const testRequest = { type: "request", id: 1, method: "Page.navigate", params: { url: "https://example.com" } };
socket.write(JSON.stringify(testRequest) + "\n");
@@ -66,7 +56,6 @@ async function main() {
check(received != null, "Server received request from client");
check((received as any)?.method === "Page.navigate", "Method matches");
- // ── Test 3: Server → client send ──────────────────────────────────────
receivedByClient.length = 0;
server.send(TEST_CLIENT_ID, { type: "response", id: 1, result: { frameId: "xyz" } });
await sleep(200);
@@ -74,7 +63,6 @@ async function main() {
const response = receivedByClient.find((m: any) => m.type === "response" && m.id === 1);
check(response != null, "Client received response from server");
- // ── Test 4: Broadcast ─────────────────────────────────────────────────
receivedByClient.length = 0;
const broadcastMsg: WireEvent = {
type: "event",
@@ -88,14 +76,12 @@ async function main() {
const bc = receivedByClient[0] as any;
check(bc?.method === "Target.targetCreated", "Broadcast content matches");
- // ── Test 5: Client disconnect ─────────────────────────────────────────
socket.destroy();
await sleep(500);
check(disconnectCount === 1, "Disconnect handler fired");
check(server.clientCount() === 0, "Client count is 0 after disconnect");
- // ── Test 6: Re-registration (same clientId after disconnect) ──────────
const socket2 = createConnection(DAEMON_SOCKET_PATH);
await new Promise<void>((resolve) => socket2.on("connect", resolve));
@@ -106,12 +92,10 @@ async function main() {
socket2.on("error", () => {}); // suppress EPIPE from server-side cleanup
await sleep(300);
- // ── Test 7: Max clients enforcement ───────────────────────────────────
- // Connect max clients, then one more should be rejected.
const testSockets: ReturnType<typeof createConnection>[] = [];
for (let i = 0; i < 20; i++) {
const s = createConnection(DAEMON_SOCKET_PATH);
- s.on("error", () => {}); // server may reject and destroy this socket
+ s.on("error", () => {});
testSockets.push(s);
await new Promise<void>((resolve) => s.on("connect", resolve));
try { s.write(JSON.stringify({ type: "control", action: "register", clientId: `pi-test-max-${i}` }) + "\n"); } catch {}
@@ -119,13 +103,11 @@ async function main() {
}
await sleep(300);
check(server.clientCount() <= 16, "Max client enforcement works");
- // Clean up test sockets (some already destroyed by server rejection)
for (const s of testSockets) {
try { s.destroy(); } catch {}
s.removeAllListeners();
}
- // ── Cleanup ───────────────────────────────────────────────────────────
console.log(`\nCleaning up...`);
await server.stop();
console.log("Server stopped ✓");