-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
emit warning when worker gracefully exit before finish
- Loading branch information
Showing
4 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const { test } = require('tap') | ||
const ThreadStream = require('../index') | ||
const { join } = require('path') | ||
|
||
function sleep (ms) { | ||
return new Promise((resolve) => { | ||
setTimeout(resolve, ms) | ||
}) | ||
} | ||
|
||
test('emit warning when the worker gracefully exit without the stream ended', async function (t) { | ||
const expectedWarning = 'ThreadStream: process exited before destination stream was drained. this may indicate that the destination stream try to write to a another missing stream' | ||
const stream = new ThreadStream({ | ||
filename: join(__dirname, 'to-next.js') | ||
}) | ||
|
||
let streamWarning | ||
function saveWarning (e) { | ||
if (e.message === expectedWarning) { | ||
streamWarning = e | ||
} | ||
} | ||
process.on('warning', saveWarning) | ||
|
||
for (let i = 0; i < 10_000; i++) { | ||
if (streamWarning?.message === expectedWarning) { | ||
break | ||
} | ||
stream.write('hello') | ||
await new Promise((resolve) => { | ||
setTimeout(resolve, 1) | ||
}) | ||
} | ||
|
||
process.off('warning', saveWarning) | ||
await sleep(10) | ||
|
||
t.equal(stream.destroyed, true) | ||
t.equal(streamWarning?.message, expectedWarning) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict' | ||
|
||
const { PassThrough } = require('stream') | ||
|
||
async function run (opts) { | ||
return new PassThrough({}) | ||
} | ||
|
||
module.exports = run |