GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test: fix flaky test · nodejs/node@83ddd3e

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • test/parallel
    • test-tls-set-secure-context.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎test/parallel/test-tls-set-secure-context.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-tls-set-secure-context.js
+36-23Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ const common = require('../common');
44
if (!common.hasCrypto)
55
common.skip('missing crypto');
66

7+
// This test verifies the behavior of the tls setSecureContext() method.
8+
// It also verifies that existing connections are not disrupted when the
9+
// secure context is changed.
10+
711
const assert = require('assert');
812
const https = require('https');
913
const fixtures = require('../common/fixtures');
@@ -19,54 +23,63 @@ const credentialOptions = [
1923
ca: fixtures.readKey('ca2-cert.pem')
2024
}
2125
];
22-
let requestsCount = 0;
2326
let firstResponse;
2427

2528
const server = https.createServer(credentialOptions[0], (req, res) => {
26-
requestsCount++;
29+
const id = +req.headers.id;
2730

28-
if (requestsCount === 1) {
31+
if (id === 1) {
2932
firstResponse = res;
3033
firstResponse.write('multi-');
3134
return;
32-
} else if (requestsCount === 3) {
35+
} else if (id === 4) {
3336
firstResponse.write('success-');
3437
}
3538

3639
res.end('success');
3740
});
3841

39-
server.listen(0, common.mustCall(async () => {
42+
server.listen(0, common.mustCall(() => {
4043
const { port } = server.address();
41-
const firstRequest = makeRequest(port);
44+
const firstRequest = makeRequest(port, 1);
45+
46+
async function makeRemainingRequests() {
47+
// Wait until the first request is guaranteed to have been handled.
48+
if (!firstResponse) {
49+
return setImmediate(makeRemainingRequests);
50+
}
4251

43-
assert.strictEqual(await makeRequest(port), 'success');
52+
assert.strictEqual(await makeRequest(port, 2), 'success');
4453

45-
server.setSecureContext(credentialOptions[1]);
46-
firstResponse.write('request-');
47-
await assert.rejects(async () => {
48-
await makeRequest(port);
49-
}, /^Error: self signed certificate$/);
54+
server.setSecureContext(credentialOptions[1]);
55+
firstResponse.write('request-');
56+
await assert.rejects(async () => {
57+
await makeRequest(port, 3);
58+
}, /^Error: self signed certificate$/);
5059

51-
server.setSecureContext(credentialOptions[0]);
52-
assert.strictEqual(await makeRequest(port), 'success');
60+
server.setSecureContext(credentialOptions[0]);
61+
assert.strictEqual(await makeRequest(port, 4), 'success');
5362

54-
server.setSecureContext(credentialOptions[1]);
55-
firstResponse.end('fun!');
56-
await assert.rejects(async () => {
57-
await makeRequest(port);
58-
}, /^Error: self signed certificate$/);
63+
server.setSecureContext(credentialOptions[1]);
64+
firstResponse.end('fun!');
65+
await assert.rejects(async () => {
66+
await makeRequest(port, 5);
67+
}, /^Error: self signed certificate$/);
68+
69+
assert.strictEqual(await firstRequest, 'multi-request-success-fun!');
70+
server.close();
71+
}
5972

60-
assert.strictEqual(await firstRequest, 'multi-request-success-fun!');
61-
server.close();
73+
makeRemainingRequests();
6274
}));
6375

64-
function makeRequest(port) {
76+
function makeRequest(port, id) {
6577
return new Promise((resolve, reject) => {
6678
const options = {
6779
rejectUnauthorized: true,
6880
ca: credentialOptions[0].ca,
69-
servername: 'agent1'
81+
servername: 'agent1',
82+
headers: { id }
7083
};
7184

7285
https.get(`https://localhost:${port}`, options, (res) => {

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.