From 1eec6da17d534d504ff9556912636b0ffd4326a0 Mon Sep 17 00:00:00 2001 From: Sebastiaan Deckers Date: Sun, 9 Jul 2017 14:53:16 +0800 Subject: [PATCH] http2: doc fix & test for http2.connect() optional arguments --- doc/api/http2.md | 2 +- test/parallel/test-http2-connect.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 test/parallel/test-http2-connect.js diff --git a/doc/api/http2.md b/doc/api/http2.md index de9702e543..8bed0c935a 100755 --- a/doc/api/http2.md +++ b/doc/api/http2.md @@ -1388,7 +1388,7 @@ server.on('stream', (stream, headers) => { server.listen(80); ``` -### http2.connect(authority, options, listener) +### http2.connect(authority[, options][, listener]) diff --git a/test/parallel/test-http2-connect.js b/test/parallel/test-http2-connect.js new file mode 100644 index 0000000000..305ea034c9 --- /dev/null +++ b/test/parallel/test-http2-connect.js @@ -0,0 +1,29 @@ +// Flags: --expose-http2 +'use strict'; + +const { mustCall } = require('../common'); +const { doesNotThrow } = require('assert'); +const { createServer, connect } = require('http2'); + +const server = createServer(); +server.listen(0, mustCall(() => { + const authority = `http://localhost:${server.address().port}`; + const options = {}; + const listener = () => mustCall(); + + const clients = new Set(); + doesNotThrow(() => clients.add(connect(authority))); + doesNotThrow(() => clients.add(connect(authority, options))); + doesNotThrow(() => clients.add(connect(authority, options, listener()))); + doesNotThrow(() => clients.add(connect(authority, listener()))); + + for (const client of clients) { + client.once('connect', mustCall((headers) => { + client.destroy(); + clients.delete(client); + if (clients.size === 0) { + server.close(); + } + })); + } +}));