Skip to content

Commit 04b1e3d

Browse files
committed
fixup: test
1 parent 3fadeba commit 04b1e3d

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

test/parallel/test-stream-pipeline.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const {
1313
const assert = require('assert');
1414
const http = require('http');
1515
const { promisify } = require('util');
16+
const net = require('net');
1617

1718
{
1819
let finished = false;
@@ -1118,3 +1119,95 @@ const { promisify } = require('util');
11181119
assert.strictEqual(closed, true);
11191120
}));
11201121
}
1122+
1123+
{
1124+
const server = net.createServer(common.mustCall((socket) => {
1125+
// echo server
1126+
pipeline(socket, socket, common.mustCall());
1127+
// 13 force destroys the socket before it has a chance to emit finish
1128+
socket.on('finish', common.mustCall(() => {
1129+
server.close();
1130+
}));
1131+
})).listen(0, common.mustCall(() => {
1132+
const socket = net.connect(server.address().port);
1133+
socket.end();
1134+
}));
1135+
}
1136+
1137+
{
1138+
const d = new Duplex({
1139+
autoDestroy: false,
1140+
write: common.mustCall((data, enc, cb) => {
1141+
d.push(data);
1142+
cb();
1143+
}),
1144+
read: common.mustCall(() => {
1145+
d.push(null);
1146+
}),
1147+
final: common.mustCall((cb) => {
1148+
setTimeout(() => {
1149+
assert.strictEqual(d.destroyed, false);
1150+
cb();
1151+
}, 1000);
1152+
}),
1153+
destroy: common.mustNotCall()
1154+
});
1155+
1156+
const sink = new Writable({
1157+
write: common.mustCall((data, enc, cb) => {
1158+
cb();
1159+
})
1160+
});
1161+
1162+
pipeline(d, sink, common.mustCall());
1163+
1164+
d.write('test');
1165+
d.end();
1166+
}
1167+
1168+
{
1169+
const server = net.createServer(common.mustCall((socket) => {
1170+
// echo server
1171+
pipeline(socket, socket, common.mustCall());
1172+
socket.on('finish', common.mustCall(() => {
1173+
server.close();
1174+
}));
1175+
})).listen(0, common.mustCall(() => {
1176+
const socket = net.connect(server.address().port);
1177+
socket.end();
1178+
}));
1179+
}
1180+
1181+
{
1182+
const d = new Duplex({
1183+
autoDestroy: false,
1184+
write: common.mustCall((data, enc, cb) => {
1185+
d.push(data);
1186+
cb();
1187+
}),
1188+
read: common.mustCall(() => {
1189+
d.push(null);
1190+
}),
1191+
final: common.mustCall((cb) => {
1192+
setTimeout(() => {
1193+
assert.strictEqual(d.destroyed, false);
1194+
cb();
1195+
}, 1000);
1196+
}),
1197+
// `destroy()` won't be invoked by pipeline since
1198+
// the writable side has not completed when
1199+
// the pipeline has completed.
1200+
destroy: common.mustNotCall()
1201+
});
1202+
1203+
const sink = new Writable({
1204+
write: common.mustCall((data, enc, cb) => {
1205+
cb();
1206+
})
1207+
});
1208+
1209+
pipeline(d, sink, common.mustCall());
1210+
1211+
d.write('test');
1212+
d.end();
1213+
}

0 commit comments

Comments
 (0)