-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
http2: add Http2Stream.bufferSize #23711
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
'use strict'; | ||
|
||
const { mustCall, hasCrypto, skip } = require('../common'); | ||
if (!hasCrypto) | ||
skip('missing crypto'); | ||
const assert = require('assert'); | ||
const { createServer, connect } = require('http2'); | ||
const Countdown = require('../common/countdown'); | ||
|
||
// This test ensures that `bufferSize` of Http2Session and Http2Stream work | ||
// as expected. | ||
{ | ||
const SOCKETS = 2; | ||
const TIMES = 10; | ||
const BUFFER_SIZE = 30; | ||
const server = createServer(); | ||
|
||
// Other `bufferSize` tests for net module and tls module | ||
// don't assert `bufferSize` of server-side sockets. | ||
server.on('stream', mustCall((stream) => { | ||
stream.on('data', mustCall()); | ||
stream.on('end', mustCall()); | ||
}, SOCKETS)); | ||
|
||
server.listen(0, mustCall(() => { | ||
const authority = `http://localhost:${server.address().port}`; | ||
const client = connect(authority); | ||
const countdown = new Countdown(SOCKETS, () => { | ||
client.close(); | ||
server.close(); | ||
}); | ||
|
||
client.once('connect', mustCall()); | ||
|
||
for (let j = 0; j < SOCKETS; j += 1) { | ||
const stream = client.request({ ':method': 'POST' }); | ||
stream.on('data', () => {}); | ||
stream.on('close', mustCall(() => { | ||
countdown.dec(); | ||
})); | ||
|
||
for (let i = 0; i < TIMES; i += 1) { | ||
stream.write(Buffer.allocUnsafe(BUFFER_SIZE), mustCall()); | ||
const expectedSocketBufferSize = BUFFER_SIZE * (i + 1); | ||
assert.strictEqual(stream.bufferSize, expectedSocketBufferSize); | ||
} | ||
stream.end(); | ||
stream.close(); | ||
} | ||
})); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
const assert = require('assert'); | ||
const fixtures = require('../common/fixtures'); | ||
const makeDuplexPair = require('../common/duplexpair'); | ||
const tls = require('tls'); | ||
const net = require('net'); | ||
|
||
// This test ensures that `bufferSize` also works for those tlsSockets | ||
// created from `socket` of `Duplex`, with which, TLSSocket will wrap | ||
// sockets in `StreamWrap`. | ||
{ | ||
const iter = 10; | ||
|
||
function createDuplex(port) { | ||
const { clientSide, serverSide } = makeDuplexPair(); | ||
|
||
return new Promise((resolve, reject) => { | ||
const socket = net.connect({ | ||
port, | ||
}, common.mustCall(() => { | ||
clientSide.pipe(socket); | ||
socket.pipe(clientSide); | ||
clientSide.on('close', common.mustCall(() => socket.destroy())); | ||
socket.on('close', common.mustCall(() => clientSide.destroy())); | ||
|
||
resolve(serverSide); | ||
})); | ||
}); | ||
} | ||
|
||
const server = tls.createServer({ | ||
key: fixtures.readKey('agent2-key.pem'), | ||
cert: fixtures.readKey('agent2-cert.pem') | ||
}, common.mustCall((socket) => { | ||
let str = ''; | ||
socket.setEncoding('utf-8'); | ||
socket.on('data', (chunk) => { str += chunk; }); | ||
|
||
socket.on('end', common.mustCall(() => { | ||
assert.strictEqual(str, 'a'.repeat(iter - 1)); | ||
server.close(); | ||
})); | ||
})); | ||
|
||
server.listen(0, common.mustCall(() => { | ||
const { port } = server.address(); | ||
createDuplex(port).then((socket) => { | ||
const client = tls.connect({ | ||
socket, | ||
rejectUnauthorized: false, | ||
}, common.mustCall(() => { | ||
assert.strictEqual(client.bufferSize, 0); | ||
|
||
for (let i = 1; i < iter; i++) { | ||
client.write('a'); | ||
assert.strictEqual(client.bufferSize, i + 1); | ||
} | ||
|
||
// It seems that tlsSockets created from sockets of `Duplex` emit no | ||
// "finish" events. We use "end" event instead. | ||
client.on('end', common.mustCall(() => { | ||
assert.strictEqual(client.bufferSize, undefined); | ||
})); | ||
|
||
client.end(); | ||
})); | ||
}); | ||
})); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At best this is likely an approximation with a high degree of accuracy at any given time. It's likely good enough :-)
What do you think @addaleax?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’d guess it’s good enough, yes :)