Skip to content

Commit a5dab9e

Browse files
lpincatargos
authored andcommitted
test: deflake test-tls-js-stream
`socket.destroy()` can destory the stream before the chunk to write with `socket.end()` is actually sent. Furthermore `socket.destroy()` destroys `p` and not the actual raw socket. As a result it is possible that the connection is left open. Remove `socket.destroy()` to ensure that the chunk is sent. Also use `common.mustCall()` to ensure that the `'secureConnection'` and `'secureConnect'` events are emitted exactly once. PR-URL: #27478 Fixes: #26938 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Sam Roberts <[email protected]> Reviewed-By: Fedor Indutny <[email protected]>
1 parent ec642f1 commit a5dab9e

File tree

2 files changed

+12
-23
lines changed

2 files changed

+12
-23
lines changed

test/parallel/parallel.status

-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ test-http2-client-upload-reject: PASS,FLAKY
2525
[$system==linux]
2626

2727
[$system==macos]
28-
# https://github.com/nodejs/node/issues/26938
29-
test-tls-js-stream: PASS,FLAKY
3028

3129
[$arch==arm || $arch==arm64]
3230
# https://github.com/nodejs/node/issues/26610

test/parallel/test-tls-js-stream.js

+12-21
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,19 @@ if (!common.hasCrypto)
66

77
const fixtures = require('../common/fixtures');
88

9-
const assert = require('assert');
109
const net = require('net');
1110
const stream = require('stream');
1211
const tls = require('tls');
1312

14-
const connected = {
15-
client: 0,
16-
server: 0
17-
};
18-
1913
const server = tls.createServer({
2014
key: fixtures.readKey('agent1-key.pem'),
2115
cert: fixtures.readKey('agent1-cert.pem')
22-
}, function(c) {
16+
}, common.mustCall(function(c) {
2317
console.log('new client');
24-
connected.server++;
18+
19+
c.resume();
2520
c.end('ohai');
26-
}).listen(0, function() {
21+
})).listen(0, common.mustCall(function() {
2722
const raw = net.connect(this.address().port);
2823

2924
let pending = false;
@@ -32,6 +27,10 @@ const server = tls.createServer({
3227
p._read();
3328
});
3429

30+
raw.on('end', function() {
31+
p.push(null);
32+
});
33+
3534
const p = new stream.Duplex({
3635
read: function read() {
3736
pending = false;
@@ -53,23 +52,15 @@ const server = tls.createServer({
5352
const socket = tls.connect({
5453
socket: p,
5554
rejectUnauthorized: false
56-
}, function() {
55+
}, common.mustCall(function() {
5756
console.log('client secure');
5857

59-
connected.client++;
60-
61-
socket.end('hello');
6258
socket.resume();
63-
socket.destroy();
64-
});
59+
socket.end('hello');
60+
}));
6561

6662
socket.once('close', function() {
6763
console.log('client close');
6864
server.close();
6965
});
70-
});
71-
72-
process.once('exit', function() {
73-
assert.strictEqual(connected.client, 1);
74-
assert.strictEqual(connected.server, 1);
75-
});
66+
}));

0 commit comments

Comments
 (0)