Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit edba129

Browse filesBrowse files
trivikraddaleax
authored andcommitted
test: http2 compat response.write() error checks
PR-URL: #18859 Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent c7f9608 commit edba129
Copy full SHA for edba129

File tree

Expand file treeCollapse file tree

2 files changed

+52
-95
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+52
-95
lines changed
Open diff view settings
Collapse file

‎test/parallel/test-http2-compat-serverresponse-write-no-cb.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-http2-compat-serverresponse-write-no-cb.js
-95Lines changed: 0 additions & 95 deletions
This file was deleted.
Collapse file
+52Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
'use strict';
2+
3+
const {
4+
mustCall,
5+
mustNotCall,
6+
expectsError,
7+
hasCrypto,
8+
skip
9+
} = require('../common');
10+
if (!hasCrypto)
11+
skip('missing crypto');
12+
const { createServer, connect } = require('http2');
13+
const assert = require('assert');
14+
15+
const server = createServer();
16+
server.listen(0, mustCall(() => {
17+
const port = server.address().port;
18+
const url = `http://localhost:${port}`;
19+
const client = connect(url, mustCall(() => {
20+
const request = client.request();
21+
request.resume();
22+
request.on('end', mustCall());
23+
request.on('close', mustCall(() => {
24+
client.close();
25+
}));
26+
}));
27+
28+
server.once('request', mustCall((request, response) => {
29+
// response.write() returns true
30+
assert(response.write('muahaha', 'utf8', mustCall()));
31+
32+
response.stream.close(0, mustCall(() => {
33+
response.on('error', mustNotCall());
34+
35+
// response.write() without cb returns error
36+
expectsError(
37+
() => { response.write('muahaha'); },
38+
{
39+
type: Error,
40+
code: 'ERR_HTTP2_INVALID_STREAM',
41+
message: 'The stream has been destroyed'
42+
}
43+
);
44+
45+
// response.write() with cb returns falsy value
46+
assert(!response.write('muahaha', mustCall()));
47+
48+
client.destroy();
49+
server.close();
50+
}));
51+
}));
52+
}));

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.