mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
test: make sure WriteWrap tests are actually async
PR-URL: https://github.com/nodejs/node/pull/18676 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
e1271c07c3
commit
0ed9ea861b
@ -47,6 +47,7 @@ function checkDestroyedWriteWraps(n, stage) {
|
||||
}
|
||||
|
||||
function onconnection(conn) {
|
||||
conn.write('hi'); // Let the client know we're ready.
|
||||
conn.resume();
|
||||
//
|
||||
// Server received client connection
|
||||
@ -60,15 +61,35 @@ function onconnect() {
|
||||
//
|
||||
checkDestroyedWriteWraps(0, 'client connected');
|
||||
|
||||
this.once('data', common.mustCall(ondata));
|
||||
}
|
||||
|
||||
function ondata() {
|
||||
//
|
||||
// Destroying client socket
|
||||
// Writing data to client socket
|
||||
//
|
||||
this.write('f'.repeat(128000), () => onafterwrite(this));
|
||||
const write = () => {
|
||||
let writeFinished = false;
|
||||
this.write('f'.repeat(1280000), () => {
|
||||
writeFinished = true;
|
||||
});
|
||||
process.nextTick(() => {
|
||||
if (writeFinished) {
|
||||
// Synchronous finish, write more data immediately.
|
||||
writeFinished = false;
|
||||
write();
|
||||
} else {
|
||||
// Asynchronous write; this is what we are here for.
|
||||
onafterwrite(this);
|
||||
}
|
||||
});
|
||||
};
|
||||
write();
|
||||
}
|
||||
|
||||
function onafterwrite(self) {
|
||||
checkDestroyedWriteWraps(1, 'client destroyed');
|
||||
self.destroy();
|
||||
self.end();
|
||||
|
||||
checkDestroyedWriteWraps(1, 'client destroyed');
|
||||
|
||||
|
@ -197,7 +197,6 @@ if (common.hasCrypto) { // eslint-disable-line crypto-check
|
||||
const handle = new tcp_wrap.TCP(tcp_wrap.constants.SOCKET);
|
||||
const req = new tcp_wrap.TCPConnectWrap();
|
||||
const sreq = new stream_wrap.ShutdownWrap();
|
||||
const wreq = new stream_wrap.WriteWrap();
|
||||
testInitialized(handle, 'TCP');
|
||||
testUninitialized(req, 'TCPConnectWrap');
|
||||
testUninitialized(sreq, 'ShutdownWrap');
|
||||
@ -206,20 +205,25 @@ if (common.hasCrypto) { // eslint-disable-line crypto-check
|
||||
handle.close();
|
||||
});
|
||||
|
||||
wreq.handle = handle;
|
||||
wreq.oncomplete = common.mustCall(() => {
|
||||
handle.shutdown(sreq);
|
||||
testInitialized(sreq, 'ShutdownWrap');
|
||||
});
|
||||
wreq.async = true;
|
||||
|
||||
req.oncomplete = common.mustCall(() => {
|
||||
// Use a long string to make sure the write happens asynchronously.
|
||||
req.oncomplete = common.mustCall(writeData);
|
||||
function writeData() {
|
||||
const wreq = new stream_wrap.WriteWrap();
|
||||
wreq.handle = handle;
|
||||
wreq.oncomplete = () => {
|
||||
handle.shutdown(sreq);
|
||||
testInitialized(sreq, 'ShutdownWrap');
|
||||
};
|
||||
const err = handle.writeLatin1String(wreq, 'hi'.repeat(100000));
|
||||
if (err)
|
||||
throw new Error(`write failed: ${getSystemErrorName(err)}`);
|
||||
if (!wreq.async) {
|
||||
testUninitialized(wreq, 'WriteWrap');
|
||||
// Synchronous finish. Write more data until we hit an
|
||||
// asynchronous write.
|
||||
return writeData();
|
||||
}
|
||||
testInitialized(wreq, 'WriteWrap');
|
||||
});
|
||||
}
|
||||
req.address = common.localhostIPv4;
|
||||
req.port = server.address().port;
|
||||
const err = handle.connect(req, req.address, req.port);
|
||||
|
Loading…
Reference in New Issue
Block a user