Skip to content

Commit

Permalink
test: update win32 affordance
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Nov 22, 2023
1 parent 5425d33 commit 5916b69
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ export abstract class SockDaemonServer<
/* c8 ignore stop */
})

server.once('error', er => this.#onServerError(er))
server.on('error', er => this.#onServerError(er))
server.listen(this.#socket, () => this.#onListen(server))

if (!this.#didOnExit) {
Expand Down
32 changes: 17 additions & 15 deletions test/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,7 @@ t.test('dont touch non-server process with recorded pid', async t => {
}, 5000).unref()
const response = await bar
t.equal(response, 'bar: foo wedge test')
t.strictSame(
await exit,
isWindows
? { code: 1, signal: null }
: { code: null, signal: 'SIGKILL' }
)
t.strictSame(await exit, { code: null, signal: 'SIGKILL' })
})

t.test('kill server process that fails ping', async t => {
Expand Down Expand Up @@ -245,14 +240,16 @@ t.test('kill server process that fails ping but writes', async t => {
})

t.test('kill server process writes non-PONG to ping', async t => {
const p = Buffer.concat(message({id: 'xyz', ping: 'not pong!' }))
const d = spawn(process.execPath, [
'-e',
`
const p = Buffer.concat(message({ id: 'xyz', ping: 'not pong!' }))
const d = spawn(
process.execPath,
[
'-e',
`
server = require('net').createServer(c => {
c.write(Buffer.from(${
JSON.stringify(p.toString('hex'))
}, 'hex'))
c.write(Buffer.from(${JSON.stringify(
p.toString('hex')
)}, 'hex'))
})
server.listen(${JSON.stringify(
socketPath
Expand All @@ -261,7 +258,9 @@ t.test('kill server process writes non-PONG to ping', async t => {
process.on('SIGHUP', () => {})
} catch {}
`,
], { stdio: ['ignore', 'pipe', 'inherit' ] })
],
{ stdio: ['ignore', 'pipe', 'inherit'] }
)
await new Promise<void>(r => d.stdout.on('data', () => r()))
await new Promise<void>(r => setTimeout(r, 100))
writeFileSync('.test-service/daemon/pid', String(d.pid))
Expand Down Expand Up @@ -401,5 +400,8 @@ t.test('succession contest', async t => {
for (const c of clients) {
responses.push(c.fooIntoBar('foo'))
}
t.strictSame(await Promise.all(responses), clients.map(() => 'bar: foo'))
t.strictSame(
await Promise.all(responses),
clients.map(() => 'bar: foo')
)
})

0 comments on commit 5916b69

Please sign in to comment.