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: remove timers from test-tls-socket-close #53019

Merged
Merged
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
36 changes: 18 additions & 18 deletions test/parallel/test-tls-socket-close.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ const cert = fixtures.readKey('agent2-cert.pem');
let serverTlsSocket;
const tlsServer = tls.createServer({ cert, key }, (socket) => {
serverTlsSocket = socket;
socket.on('data', (chunk) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

No common.mustCallAtLeast?

Copy link
Member Author

@lpinca lpinca May 23, 2024

Choose a reason for hiding this comment

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

No, only one byte is sent by the other peer.

assert.strictEqual(chunk[0], 46);
socket.write('.');
});
socket.on('close', dec);
});

Expand All @@ -25,10 +29,10 @@ let netSocketCloseEmitted = false;
const netServer = net.createServer((socket) => {
netSocket = socket;
tlsServer.emit('connection', socket);
socket.on('close', () => {
socket.on('close', common.mustCall(() => {
netSocketCloseEmitted = true;
assert.strictEqual(serverTlsSocket.destroyed, true);
});
}));
}).listen(0, common.mustCall(() => {
connectClient(netServer);
}));
Expand All @@ -45,24 +49,20 @@ function connectClient(server) {
rejectUnauthorized: false
});

clientTlsSocket.write('foo', 'utf8', common.mustCall(() => {
assert(netSocket);
netSocket.setTimeout(common.platformTimeout(10), common.mustCall(() => {
assert(serverTlsSocket);
clientTlsSocket.write('.');

netSocket.destroy();
assert.strictEqual(netSocket.destroyed, true);
clientTlsSocket.on('data', (chunk) => {
assert.strictEqual(chunk[0], 46);

setImmediate(() => {
// Close callbacks are executed after `setImmediate()` callbacks.
assert.strictEqual(netSocketCloseEmitted, false);
assert.strictEqual(serverTlsSocket.destroyed, false);
setImmediate(() => {
assert.strictEqual(netSocketCloseEmitted, true);
});
});
}));
}));
netSocket.destroy();
assert.strictEqual(netSocket.destroyed, true);

setImmediate(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

No common.mustCall here?

Copy link
Member Author

Choose a reason for hiding this comment

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

We have separate tests for setImmediate().

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't really get what you mean, common.mustCall wouldn't be there to validate setImmediate behavior, but to ensure the assertion are actually run. Anyway, it doesn't really matter.

Copy link
Member Author

@lpinca lpinca May 23, 2024

Choose a reason for hiding this comment

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

We are testing that the callback of setImmediate() is called in other tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's not called if e.g. process.exit is called before it's picked up

Copy link
Member Author

Choose a reason for hiding this comment

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

There is no process.exit() in the test.

Copy link
Contributor

Choose a reason for hiding this comment

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

Adding common.mustCall would ensure we catch it if it was ever added

Copy link
Member Author

@lpinca lpinca May 23, 2024

Choose a reason for hiding this comment

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

I've added it only where it is needed given the current assumptions. If the logic changes there are other more places where it would be needed.

// Close callbacks are executed after `setImmediate()` callbacks.
assert.strictEqual(netSocketCloseEmitted, false);
assert.strictEqual(serverTlsSocket.destroyed, false);
});
});

clientTlsSocket.on('close', dec);
}
Expand Down