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

Refactor test-tls-pause #18714

Closed
wants to merge 3 commits into from
Closed
Changes from 2 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
26 changes: 14 additions & 12 deletions test/parallel/test-tls-pause.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');

// This test ensures that the data received over tls-server after pause
// is same as what it was send
Copy link
Member

Choose a reason for hiding this comment

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

Nit: send -> sent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changes done

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Trott Thanks for feedback!


const assert = require('assert');
const tls = require('tls');
const fixtures = require('../common/fixtures');
Expand All @@ -37,24 +40,23 @@ const bufSize = 1024 * 1024;
let sent = 0;
let received = 0;

const server = tls.Server(options, function(socket) {
const server = tls.Server(options, common.mustCall((socket) => {
socket.pipe(socket);
socket.on('data', function(c) {
socket.on('data', (c) => {
console.error('data', c.length);
});
});
}));

server.listen(0, function() {
server.listen(0, () => {
Copy link
Member

Choose a reason for hiding this comment

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

The callback to listen could (should?) also be wrapped in common.mustCall.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changes done

let resumed = false;
const client = tls.connect({
port: this.address().port,
port: server.address().port,
rejectUnauthorized: false
}, function() {
}, common.mustCall(() => {
console.error('connected');
client.pause();
console.error('paused');
send();
function send() {
const send = (() => {
console.error('sending');
const ret = client.write(Buffer.allocUnsafe(bufSize));
console.error(`write => ${ret}`);
Expand All @@ -69,9 +71,9 @@ server.listen(0, function() {
resumed = true;
client.resume();
console.error('resumed', client);
}
});
client.on('data', function(data) {
})();
}));
client.on('data', (data) => {
console.error('data');
assert.ok(resumed);
received += data.length;
Expand All @@ -85,6 +87,6 @@ server.listen(0, function() {
});
});

process.on('exit', function() {
process.on('exit', () => {
assert.strictEqual(sent, received);
});