A real Daemon's connection handling, on a socket of its own. Opens no index.
(socketPath: string)
| 176 | describe('the daemon answers a challenge in its handshake (#3284)', () => { |
| 177 | /** A real Daemon's connection handling, on a socket of its own. Opens no index. */ |
| 178 | async function daemonOn(socketPath: string): Promise<void> { |
| 179 | const daemon = new Daemon(tempDir('cg-proofroot-'), { idleTimeoutMs: 0 }) as unknown as { |
| 180 | socketPath: string; |
| 181 | handleConnection(socket: net.Socket): void; |
| 182 | }; |
| 183 | daemon.socketPath = socketPath; |
| 184 | const accepted = new Set<net.Socket>(); |
| 185 | const server = net.createServer((socket) => { accepted.add(socket); daemon.handleConnection(socket); }); |
| 186 | await new Promise<void>((resolve) => server.listen(socketPath, resolve)); |
| 187 | cleanups.push(() => new Promise<void>((resolve) => { |
| 188 | for (const socket of accepted) socket.destroy(); |
| 189 | server.close(() => resolve()); |
| 190 | })); |
| 191 | } |
| 192 | |
| 193 | async function connect(socketPath: string): Promise<{ socket: net.Socket; next: () => Promise<string> }> { |
| 194 | const socket = net.createConnection(socketPath); |
no test coverage detected