Skip to content
This repository has been archived by the owner on Jul 6, 2018. It is now read-only.

Commit

Permalink
http2: doc fix & test for http2.connect() optional arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
sebdeckers committed Jul 9, 2017
1 parent 36cfaf9 commit 1eec6da
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion doc/api/http2.md
Original file line number Diff line number Diff line change
Expand Up @@ -1388,7 +1388,7 @@ server.on('stream', (stream, headers) => {
server.listen(80);
```

### http2.connect(authority, options, listener)
### http2.connect(authority[, options][, listener])
<!-- YAML
added: REPLACEME
-->
Expand Down
29 changes: 29 additions & 0 deletions test/parallel/test-http2-connect.js
Original file line number Diff line number Diff line change
@@ -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();
}
}));
}
}));

0 comments on commit 1eec6da

Please sign in to comment.