diff --git a/test/async-hooks/test-writewrap.js b/test/async-hooks/test-writewrap.js index ed17887684c9c2..4f3455480ba849 100644 --- a/test/async-hooks/test-writewrap.js +++ b/test/async-hooks/test-writewrap.js @@ -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'); diff --git a/test/sequential/test-async-wrap-getasyncid.js b/test/sequential/test-async-wrap-getasyncid.js index 5a3fd3b2f1e22f..4e01b5fbb24c43 100644 --- a/test/sequential/test-async-wrap-getasyncid.js +++ b/test/sequential/test-async-wrap-getasyncid.js @@ -195,7 +195,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'); @@ -204,20 +203,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);