Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: http2 compat response.write() error checks #18859

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 0 additions & 95 deletions test/parallel/test-http2-compat-serverresponse-write-no-cb.js

This file was deleted.

52 changes: 52 additions & 0 deletions test/parallel/test-http2-compat-serverresponse-write.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
'use strict';

const {
mustCall,
mustNotCall,
expectsError,
hasCrypto,
skip
} = require('../common');
if (!hasCrypto)
skip('missing crypto');
const { createServer, connect } = require('http2');
const assert = require('assert');

const server = createServer();
server.listen(0, mustCall(() => {
const port = server.address().port;
const url = `http://localhost:${port}`;
const client = connect(url, mustCall(() => {
const request = client.request();
request.resume();
request.on('end', mustCall());
request.on('close', mustCall(() => {
client.close();
}));
}));

server.once('request', mustCall((request, response) => {
// response.write() returns true
assert(response.write('muahaha', 'utf8', mustCall()));

response.stream.close(0, mustCall(() => {
response.on('error', mustNotCall());

// response.write() without cb returns error
expectsError(
() => { response.write('muahaha'); },
{
type: Error,
code: 'ERR_HTTP2_INVALID_STREAM',
message: 'The stream has been destroyed'
}
);

// response.write() with cb returns falsy value
assert(!response.write('muahaha', mustCall()));

client.destroy();
server.close();
}));
}));
}));