Skip to content

Commit c47e9e0

Browse files
authored
tests: improve skip for unix.js tests, remove skipped tests (#2916)
1 parent ff16351 commit c47e9e0

2 files changed

Lines changed: 124 additions & 141 deletions

File tree

test/node-test/balanced-pool.js

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
const { describe, test } = require('node:test')
44
const assert = require('node:assert/strict')
55
const { BalancedPool, Pool, Client, errors } = require('../..')
6-
const { nodeMajor } = require('../../lib/core/util')
76
const { createServer } = require('node:http')
87
const { promisify } = require('node:util')
98
const { tspl } = require('@matteo.collina/tspl')
@@ -432,22 +431,6 @@ const cases = [
432431

433432
// 7
434433

435-
{
436-
iterations: 100,
437-
maxWeightPerServer: 100,
438-
errorPenalty: 15,
439-
config: [{ server: 'A' }, { server: 'B' }, { server: 'C', downOnRequests: [1] }],
440-
expected: ['A', 'B', 'C', 'A', 'B', 'C/connectionRefused', 'A', 'B', 'A', 'B', 'A', 'B', 'C', 'A', 'B', 'C'],
441-
expectedConnectionRefusedErrors: 1,
442-
expectedSocketErrors: 0,
443-
expectedRatios: [0.34, 0.34, 0.32],
444-
445-
// Skip because the behavior of Node.js has changed
446-
skip: nodeMajor >= 18
447-
},
448-
449-
// 8
450-
451434
{
452435
iterations: 100,
453436
maxWeightPerServer: 100,
@@ -459,7 +442,7 @@ const cases = [
459442
expectedRatios: [0.32, 0.34, 0.34]
460443
},
461444

462-
// 9
445+
// 8
463446

464447
{
465448
iterations: 100,
@@ -472,7 +455,7 @@ const cases = [
472455
expectedRatios: [0.2, 0.2, 0.2, 0.2, 0.2]
473456
},
474457

475-
// 10
458+
// 9
476459
{
477460
iterations: 100,
478461
maxWeightPerServer: 100,

test/node-test/unix.js

Lines changed: 122 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -8,152 +8,152 @@ const pem = require('https-pem')
88
const fs = require('node:fs')
99
const { tspl } = require('@matteo.collina/tspl')
1010

11-
if (process.platform !== 'win32') {
12-
test('http unix get', async (t) => {
13-
let client
14-
const p = tspl(t, { plan: 7 })
15-
16-
const server = http.createServer((req, res) => {
17-
p.equal('/', req.url)
18-
p.equal('GET', req.method)
19-
p.equal('localhost', req.headers.host)
20-
res.setHeader('Content-Type', 'text/plain')
21-
res.end('hello')
22-
})
11+
const skip = process.platform === 'win32'
12+
13+
test('http unix get', { skip }, async (t) => {
14+
let client
15+
const p = tspl(t, { plan: 7 })
16+
17+
const server = http.createServer((req, res) => {
18+
p.equal('/', req.url)
19+
p.equal('GET', req.method)
20+
p.equal('localhost', req.headers.host)
21+
res.setHeader('Content-Type', 'text/plain')
22+
res.end('hello')
23+
})
2324

24-
t.after(() => {
25-
server.close()
26-
client.close()
27-
})
25+
t.after(() => {
26+
server.close()
27+
client.close()
28+
})
2829

29-
try {
30-
fs.unlinkSync('/var/tmp/test3.sock')
31-
} catch (err) {
30+
try {
31+
fs.unlinkSync('/var/tmp/test3.sock')
32+
} catch (err) {
3233

33-
}
34+
}
3435

35-
server.listen('/var/tmp/test3.sock', () => {
36-
client = new Client({
37-
hostname: 'localhost',
38-
protocol: 'http:'
39-
}, {
40-
socketPath: '/var/tmp/test3.sock'
41-
})
36+
server.listen('/var/tmp/test3.sock', () => {
37+
client = new Client({
38+
hostname: 'localhost',
39+
protocol: 'http:'
40+
}, {
41+
socketPath: '/var/tmp/test3.sock'
42+
})
4243

43-
client.request({ path: '/', method: 'GET' }, (err, data) => {
44-
p.ifError(err)
45-
const { statusCode, headers, body } = data
46-
p.equal(statusCode, 200)
47-
p.equal(headers['content-type'], 'text/plain')
48-
const bufs = []
49-
body.on('data', (buf) => {
50-
bufs.push(buf)
51-
})
52-
body.on('end', () => {
53-
p.equal('hello', Buffer.concat(bufs).toString('utf8'))
54-
})
44+
client.request({ path: '/', method: 'GET' }, (err, data) => {
45+
p.ifError(err)
46+
const { statusCode, headers, body } = data
47+
p.equal(statusCode, 200)
48+
p.equal(headers['content-type'], 'text/plain')
49+
const bufs = []
50+
body.on('data', (buf) => {
51+
bufs.push(buf)
52+
})
53+
body.on('end', () => {
54+
p.equal('hello', Buffer.concat(bufs).toString('utf8'))
5555
})
5656
})
57-
58-
await p.completed
5957
})
6058

61-
test('http unix get pool', async (t) => {
62-
let client
63-
const p = tspl(t, { plan: 7 })
59+
await p.completed
60+
})
6461

65-
const server = http.createServer((req, res) => {
66-
p.equal('/', req.url)
67-
p.equal('GET', req.method)
68-
p.equal('localhost', req.headers.host)
69-
res.setHeader('Content-Type', 'text/plain')
70-
res.end('hello')
71-
})
62+
test('http unix get pool', { skip }, async (t) => {
63+
let client
64+
const p = tspl(t, { plan: 7 })
7265

73-
t.after(() => {
74-
server.close()
75-
client.close()
76-
})
66+
const server = http.createServer((req, res) => {
67+
p.equal('/', req.url)
68+
p.equal('GET', req.method)
69+
p.equal('localhost', req.headers.host)
70+
res.setHeader('Content-Type', 'text/plain')
71+
res.end('hello')
72+
})
7773

78-
try {
79-
fs.unlinkSync('/var/tmp/test3.sock')
80-
} catch (err) {
74+
t.after(() => {
75+
server.close()
76+
client.close()
77+
})
8178

82-
}
79+
try {
80+
fs.unlinkSync('/var/tmp/test3.sock')
81+
} catch (err) {
8382

84-
server.listen('/var/tmp/test3.sock', () => {
85-
client = new Pool({
86-
hostname: 'localhost',
87-
protocol: 'http:'
88-
}, {
89-
socketPath: '/var/tmp/test3.sock'
90-
})
83+
}
9184

92-
client.request({ path: '/', method: 'GET' }, (err, data) => {
93-
p.ifError(err)
94-
const { statusCode, headers, body } = data
95-
p.equal(statusCode, 200)
96-
p.equal(headers['content-type'], 'text/plain')
97-
const bufs = []
98-
body.on('data', (buf) => {
99-
bufs.push(buf)
100-
})
101-
body.on('end', () => {
102-
p.equal('hello', Buffer.concat(bufs).toString('utf8'))
103-
})
104-
})
85+
server.listen('/var/tmp/test3.sock', () => {
86+
client = new Pool({
87+
hostname: 'localhost',
88+
protocol: 'http:'
89+
}, {
90+
socketPath: '/var/tmp/test3.sock'
10591
})
10692

107-
await p.completed
93+
client.request({ path: '/', method: 'GET' }, (err, data) => {
94+
p.ifError(err)
95+
const { statusCode, headers, body } = data
96+
p.equal(statusCode, 200)
97+
p.equal(headers['content-type'], 'text/plain')
98+
const bufs = []
99+
body.on('data', (buf) => {
100+
bufs.push(buf)
101+
})
102+
body.on('end', () => {
103+
p.equal('hello', Buffer.concat(bufs).toString('utf8'))
104+
})
105+
})
108106
})
109107

110-
test('https get with tls opts', async (t) => {
111-
let client
112-
const p = tspl(t, { plan: 6 })
108+
await p.completed
109+
})
113110

114-
const server = https.createServer(pem, (req, res) => {
115-
p.equal('/', req.url)
116-
p.equal('GET', req.method)
117-
res.setHeader('content-type', 'text/plain')
118-
res.end('hello')
119-
})
111+
test('https get with tls opts', { skip }, async (t) => {
112+
let client
113+
const p = tspl(t, { plan: 6 })
120114

121-
t.after(() => {
122-
server.close()
123-
client.close()
115+
const server = https.createServer(pem, (req, res) => {
116+
p.equal('/', req.url)
117+
p.equal('GET', req.method)
118+
res.setHeader('content-type', 'text/plain')
119+
res.end('hello')
120+
})
121+
122+
t.after(() => {
123+
server.close()
124+
client.close()
125+
})
126+
127+
try {
128+
fs.unlinkSync('/var/tmp/test3.sock')
129+
} catch (err) {
130+
131+
}
132+
133+
server.listen('/var/tmp/test3.sock', () => {
134+
client = new Client({
135+
hostname: 'localhost',
136+
protocol: 'https:'
137+
}, {
138+
socketPath: '/var/tmp/test3.sock',
139+
tls: {
140+
rejectUnauthorized: false
141+
}
124142
})
125143

126-
try {
127-
fs.unlinkSync('/var/tmp/test3.sock')
128-
} catch (err) {
129-
130-
}
131-
132-
server.listen('/var/tmp/test3.sock', () => {
133-
client = new Client({
134-
hostname: 'localhost',
135-
protocol: 'https:'
136-
}, {
137-
socketPath: '/var/tmp/test3.sock',
138-
tls: {
139-
rejectUnauthorized: false
140-
}
144+
client.request({ path: '/', method: 'GET' }, (err, data) => {
145+
p.ifError(err)
146+
const { statusCode, headers, body } = data
147+
p.equal(statusCode, 200)
148+
p.equal(headers['content-type'], 'text/plain')
149+
const bufs = []
150+
body.on('data', (buf) => {
151+
bufs.push(buf)
141152
})
142-
143-
client.request({ path: '/', method: 'GET' }, (err, data) => {
144-
p.ifError(err)
145-
const { statusCode, headers, body } = data
146-
p.equal(statusCode, 200)
147-
p.equal(headers['content-type'], 'text/plain')
148-
const bufs = []
149-
body.on('data', (buf) => {
150-
bufs.push(buf)
151-
})
152-
body.on('end', () => {
153-
p.equal('hello', Buffer.concat(bufs).toString('utf8'))
154-
})
153+
body.on('end', () => {
154+
p.equal('hello', Buffer.concat(bufs).toString('utf8'))
155155
})
156156
})
157-
await p.completed
158157
})
159-
}
158+
await p.completed
159+
})

0 commit comments

Comments
 (0)