Skip to content

Commit 9df82f3

Browse files
committed
test: test timeout in context process exit directly
1 parent 777fa37 commit 9df82f3

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

test/unit/context-process-exit-test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@ describe("context process exit", function () {
3030

3131
it("should not occur when sockets are open and polling", async function () {
3232
this.slow(1000)
33-
const {code} = await createProcess(() => {
33+
const {code, is_timeout} = await createProcess(() => {
3434
const socket1 = new zmq.Dealer()
3535
socket1.connect("inproc://foo")
3636
socket1.receive()
3737
})
3838

3939
assert.equal(code, -1)
40+
assert.equal(is_timeout, true)
4041
})
4142

4243
it("should produce warning when messages are queued with blocky", async function () {
@@ -134,14 +135,15 @@ describe("context process exit", function () {
134135

135136
it("should not occur when sockets are open and polling", async function () {
136137
this.slow(1000)
137-
const {code} = await createProcess(() => {
138+
const {code, is_timeout} = await createProcess(() => {
138139
const context = new zmq.Context()
139140
const socket1 = new zmq.Dealer({context})
140141
socket1.connect("inproc://foo")
141142
socket1.receive()
142143
})
143144

144145
assert.equal(code, -1)
146+
assert.equal(is_timeout, true)
145147
})
146148
})
147149
})

test/unit/helpers.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ interface Result {
148148
code: number
149149
stdout: Buffer
150150
stderr: Buffer
151+
is_timeout: boolean
151152
}
152153

153154
export function createProcess(fn: () => void): Promise<Result> {
@@ -173,15 +174,27 @@ export function createProcess(fn: () => void): Promise<Result> {
173174
return new Promise((resolve, reject) => {
174175
child.on("close", (code: number, signal: string) => {
175176
if (signal) {
176-
reject(new Error(`Child exited with ${signal}`))
177+
reject(
178+
new Error(
179+
`Child exited with ${signal}:\n${stdout.toString()}\n${stderr.toString()}`,
180+
),
181+
)
177182
} else {
178-
resolve({code, stdout, stderr})
183+
if (code !== 0) {
184+
console.error(
185+
`Child exited with code ${code}:\n${stdout.toString()}\n${stderr.toString()}`,
186+
)
187+
}
188+
189+
resolve({code, stdout, stderr, is_timeout: false})
179190
}
180191
})
181192

182193
setTimeout(() => {
183-
resolve({code: -1, stdout, stderr})
184-
console.warn("Process timeout")
194+
resolve({code: -1, stdout, stderr, is_timeout: true})
195+
console.error(
196+
`Child timed out\n${stdout.toString()}\n${stderr.toString()}`,
197+
)
185198
child.kill()
186199
}, 750)
187200
})
@@ -191,7 +204,9 @@ export function captureEvent<E extends zmq.EventType>(
191204
socket: zmq.Socket,
192205
type: E,
193206
): Promise<zmq.EventOfType<E>> {
194-
return new Promise(resolve => socket.events.on<E>(type, resolve))
207+
return new Promise(resolve => {
208+
socket.events.on<E>(type, resolve)
209+
})
195210
}
196211

197212
export async function captureEventsUntil(

0 commit comments

Comments
 (0)