forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stream: make sure 'readable' is emitted before ending the stream
Fixes: nodejs#25810 PR-URL: nodejs#26059 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
- Loading branch information
Showing
9 changed files
with
191 additions
and
33 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
146 changes: 146 additions & 0 deletions
146
test/parallel/test-stream-readable-emit-readable-short-stream.js
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,146 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const stream = require('stream'); | ||
const assert = require('assert'); | ||
|
||
{ | ||
const r = new stream.Readable({ | ||
read: common.mustCall(function() { | ||
this.push('content'); | ||
this.push(null); | ||
}) | ||
}); | ||
|
||
const t = new stream.Transform({ | ||
transform: common.mustCall(function(chunk, encoding, callback) { | ||
this.push(chunk); | ||
return callback(); | ||
}), | ||
flush: common.mustCall(function(callback) { | ||
return callback(); | ||
}) | ||
}); | ||
|
||
r.pipe(t); | ||
t.on('readable', common.mustCall(function() { | ||
while (true) { | ||
const chunk = t.read(); | ||
if (!chunk) | ||
break; | ||
|
||
assert.strictEqual(chunk.toString(), 'content'); | ||
} | ||
}, 2)); | ||
} | ||
|
||
{ | ||
const t = new stream.Transform({ | ||
transform: common.mustCall(function(chunk, encoding, callback) { | ||
this.push(chunk); | ||
return callback(); | ||
}), | ||
flush: common.mustCall(function(callback) { | ||
return callback(); | ||
}) | ||
}); | ||
|
||
t.end('content'); | ||
|
||
t.on('readable', common.mustCall(function() { | ||
while (true) { | ||
const chunk = t.read(); | ||
if (!chunk) | ||
break; | ||
assert.strictEqual(chunk.toString(), 'content'); | ||
} | ||
}, 2)); | ||
} | ||
|
||
{ | ||
const t = new stream.Transform({ | ||
transform: common.mustCall(function(chunk, encoding, callback) { | ||
this.push(chunk); | ||
return callback(); | ||
}), | ||
flush: common.mustCall(function(callback) { | ||
return callback(); | ||
}) | ||
}); | ||
|
||
t.write('content'); | ||
t.end(); | ||
|
||
t.on('readable', common.mustCall(function() { | ||
while (true) { | ||
const chunk = t.read(); | ||
if (!chunk) | ||
break; | ||
assert.strictEqual(chunk.toString(), 'content'); | ||
} | ||
}, 2)); | ||
} | ||
|
||
{ | ||
const t = new stream.Readable({ | ||
read() { | ||
} | ||
}); | ||
|
||
t.on('readable', common.mustCall(function() { | ||
while (true) { | ||
const chunk = t.read(); | ||
if (!chunk) | ||
break; | ||
assert.strictEqual(chunk.toString(), 'content'); | ||
} | ||
}, 2)); | ||
|
||
t.push('content'); | ||
t.push(null); | ||
} | ||
|
||
{ | ||
const t = new stream.Readable({ | ||
read() { | ||
} | ||
}); | ||
|
||
t.on('readable', common.mustCall(function() { | ||
while (true) { | ||
const chunk = t.read(); | ||
if (!chunk) | ||
break; | ||
assert.strictEqual(chunk.toString(), 'content'); | ||
} | ||
}, 2)); | ||
|
||
process.nextTick(() => { | ||
t.push('content'); | ||
t.push(null); | ||
}); | ||
} | ||
|
||
{ | ||
const t = new stream.Transform({ | ||
transform: common.mustCall(function(chunk, encoding, callback) { | ||
this.push(chunk); | ||
return callback(); | ||
}), | ||
flush: common.mustCall(function(callback) { | ||
return callback(); | ||
}) | ||
}); | ||
|
||
t.on('readable', common.mustCall(function() { | ||
while (true) { | ||
const chunk = t.read(); | ||
if (!chunk) | ||
break; | ||
assert.strictEqual(chunk.toString(), 'content'); | ||
} | ||
}, 2)); | ||
|
||
t.write('content'); | ||
t.end(); | ||
} |
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
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