Skip to content
Closed
Changes from 1 commit
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
47 changes: 47 additions & 0 deletions test/parallel/test-http-hightwatermark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
const http = require('http');

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a description of the test here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your review.
I added a description. Please check it again.

let requestReceived = 0;

const server = http.createServer(function(req, res) {
const id = ++requestReceived;
const enoughToDrain = req.connection.writableHighWaterMark;
const body = 'x'.repeat(enoughToDrain);

if (id === 1) {
// Case of needParse = false
req.connection.once('pause', common.mustCall(() => {
assert(req.connection._paused, '_paused must be true because it exceeds' +
'hightWaterMark by second request');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/hightWaterMark/highWaterMark

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for always review.
I'm sorry for my stupid mistake...
I fixed all typo.

}));
res.write(body);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add an assert here as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got it. I added a assertion.

} else {
// Case of needParse = true
const resume = req.connection.parser.resume.bind(req.connection.parser);
req.connection.parser.resume = common.mustCall((...args) => {
const paused = req.connection._paused;
assert(!paused, '_paused must be false because it become false by ' +
'socketOnDrain when outgoingData falls below ' +
'hightWaterMark');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/hightWaterMark/highWaterMark

return resume(...args);
});
assert(!res.write(body), 'res.write must be fail because it will exceed ' +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be res.write must return false

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got it. I updated error message.

'hightWaterMark on this call');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/hightWaterMark/highWaterMark

}
res.end();
}).on('listening', () => {
const c = net.createConnection(server.address().port, () => {
c.write('GET / HTTP/1.1\r\n\r\n');
c.write('GET / HTTP/1.1\r\n\r\n');
c.end();
});

c.on('data', () => {});
c.on('end', () => {
server.close();
});
})
.listen(0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this go on the previous line or just be its own server.listen(0); statement? It's a bit awkward to follow right now due to the lack of indentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got it.
I split statement as }); and server.listen(0);.