aboutsummaryrefslogtreecommitdiff
path: root/test/async-hooks/test-writewrap.js
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2018-01-28 17:26:08 +0100
committerAnna Henningsen <anna@addaleax.net>2018-02-14 10:00:26 +0100
commit82c43aed16cf9b69e2fd44f2e9797a8c56f6fb6d (patch)
tree70f9153d40462c980829d601de75f5ebc7d8dca9 /test/async-hooks/test-writewrap.js
parentb2e20b002bcc36cc027f7121b99cb0376a6f9af7 (diff)
downloadandroid-node-v8-82c43aed16cf9b69e2fd44f2e9797a8c56f6fb6d.tar.gz
android-node-v8-82c43aed16cf9b69e2fd44f2e9797a8c56f6fb6d.tar.bz2
android-node-v8-82c43aed16cf9b69e2fd44f2e9797a8c56f6fb6d.zip
tls_wrap: use DoTryWrite()
Use `DoTryWrite()` to write data to the underlying socket. This does probably not make any difference in performance because the callback is still deferred (for now), but brings TLSWrap in line with other things that write to streams. 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>
Diffstat (limited to 'test/async-hooks/test-writewrap.js')
-rw-r--r--test/async-hooks/test-writewrap.js47
1 files changed, 23 insertions, 24 deletions
diff --git a/test/async-hooks/test-writewrap.js b/test/async-hooks/test-writewrap.js
index d349f63566..ed17887684 100644
--- a/test/async-hooks/test-writewrap.js
+++ b/test/async-hooks/test-writewrap.js
@@ -1,14 +1,10 @@
'use strict';
const common = require('../common');
-if (!common.hasCrypto)
- common.skip('missing crypto');
-
const assert = require('assert');
const initHooks = require('./init-hooks');
-const fixtures = require('../common/fixtures');
const { checkInvocations } = require('./hook-checks');
-const tls = require('tls');
+const net = require('net');
const hooks = initHooks();
hooks.enable();
@@ -16,13 +12,9 @@ hooks.enable();
//
// Creating server and listening on port
//
-const server = tls
- .createServer({
- cert: fixtures.readSync('test_cert.pem'),
- key: fixtures.readSync('test_key.pem')
- })
+const server = net.createServer()
.on('listening', common.mustCall(onlistening))
- .on('secureConnection', common.mustCall(onsecureConnection))
+ .on('connection', common.mustCall(onconnection))
.listen(0);
assert.strictEqual(hooks.activitiesOfTypes('WRITEWRAP').length, 0);
@@ -32,16 +24,17 @@ function onlistening() {
//
// Creating client and connecting it to server
//
- tls
- .connect(server.address().port, { rejectUnauthorized: false })
- .on('secureConnect', common.mustCall(onsecureConnect));
+ net
+ .connect(server.address().port)
+ .on('connect', common.mustCall(onconnect));
assert.strictEqual(hooks.activitiesOfTypes('WRITEWRAP').length, 0);
}
function checkDestroyedWriteWraps(n, stage) {
const as = hooks.activitiesOfTypes('WRITEWRAP');
- assert.strictEqual(as.length, n, `${n} WRITEWRAPs when ${stage}`);
+ assert.strictEqual(as.length, n,
+ `${as.length} out of ${n} WRITEWRAPs when ${stage}`);
function checkValidWriteWrap(w) {
assert.strictEqual(w.type, 'WRITEWRAP');
@@ -53,35 +46,41 @@ function checkDestroyedWriteWraps(n, stage) {
as.forEach(checkValidWriteWrap);
}
-function onsecureConnection() {
+function onconnection(conn) {
+ conn.resume();
//
// Server received client connection
//
- checkDestroyedWriteWraps(3, 'server got secure connection');
+ checkDestroyedWriteWraps(0, 'server got connection');
}
-function onsecureConnect() {
+function onconnect() {
//
// Client connected to server
//
- checkDestroyedWriteWraps(4, 'client connected');
+ checkDestroyedWriteWraps(0, 'client connected');
//
// Destroying client socket
//
- this.destroy();
+ this.write('f'.repeat(128000), () => onafterwrite(this));
+}
+
+function onafterwrite(self) {
+ checkDestroyedWriteWraps(1, 'client destroyed');
+ self.destroy();
- checkDestroyedWriteWraps(4, 'client destroyed');
+ checkDestroyedWriteWraps(1, 'client destroyed');
//
// Closing server
//
server.close(common.mustCall(onserverClosed));
- checkDestroyedWriteWraps(4, 'server closing');
+ checkDestroyedWriteWraps(1, 'server closing');
}
function onserverClosed() {
- checkDestroyedWriteWraps(4, 'server closed');
+ checkDestroyedWriteWraps(1, 'server closed');
}
process.on('exit', onexit);
@@ -89,5 +88,5 @@ process.on('exit', onexit);
function onexit() {
hooks.disable();
hooks.sanityCheck('WRITEWRAP');
- checkDestroyedWriteWraps(4, 'process exits');
+ checkDestroyedWriteWraps(1, 'process exits');
}