Skip to content

Commit

Permalink
tests: improve skip for unix.js tests, remove skipped tests (#2916)
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzlopak authored Mar 4, 2024
1 parent ff16351 commit c47e9e0
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 141 deletions.
21 changes: 2 additions & 19 deletions test/node-test/balanced-pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const { describe, test } = require('node:test')
const assert = require('node:assert/strict')
const { BalancedPool, Pool, Client, errors } = require('../..')
const { nodeMajor } = require('../../lib/core/util')
const { createServer } = require('node:http')
const { promisify } = require('node:util')
const { tspl } = require('@matteo.collina/tspl')
Expand Down Expand Up @@ -432,22 +431,6 @@ const cases = [

// 7

{
iterations: 100,
maxWeightPerServer: 100,
errorPenalty: 15,
config: [{ server: 'A' }, { server: 'B' }, { server: 'C', downOnRequests: [1] }],
expected: ['A', 'B', 'C', 'A', 'B', 'C/connectionRefused', 'A', 'B', 'A', 'B', 'A', 'B', 'C', 'A', 'B', 'C'],
expectedConnectionRefusedErrors: 1,
expectedSocketErrors: 0,
expectedRatios: [0.34, 0.34, 0.32],

// Skip because the behavior of Node.js has changed
skip: nodeMajor >= 18
},

// 8

{
iterations: 100,
maxWeightPerServer: 100,
Expand All @@ -459,7 +442,7 @@ const cases = [
expectedRatios: [0.32, 0.34, 0.34]
},

// 9
// 8

{
iterations: 100,
Expand All @@ -472,7 +455,7 @@ const cases = [
expectedRatios: [0.2, 0.2, 0.2, 0.2, 0.2]
},

// 10
// 9
{
iterations: 100,
maxWeightPerServer: 100,
Expand Down
244 changes: 122 additions & 122 deletions test/node-test/unix.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,152 +8,152 @@ const pem = require('https-pem')
const fs = require('node:fs')
const { tspl } = require('@matteo.collina/tspl')

if (process.platform !== 'win32') {
test('http unix get', async (t) => {
let client
const p = tspl(t, { plan: 7 })

const server = http.createServer((req, res) => {
p.equal('/', req.url)
p.equal('GET', req.method)
p.equal('localhost', req.headers.host)
res.setHeader('Content-Type', 'text/plain')
res.end('hello')
})
const skip = process.platform === 'win32'

test('http unix get', { skip }, async (t) => {
let client
const p = tspl(t, { plan: 7 })

const server = http.createServer((req, res) => {
p.equal('/', req.url)
p.equal('GET', req.method)
p.equal('localhost', req.headers.host)
res.setHeader('Content-Type', 'text/plain')
res.end('hello')
})

t.after(() => {
server.close()
client.close()
})
t.after(() => {
server.close()
client.close()
})

try {
fs.unlinkSync('/var/tmp/test3.sock')
} catch (err) {
try {
fs.unlinkSync('/var/tmp/test3.sock')
} catch (err) {

}
}

server.listen('/var/tmp/test3.sock', () => {
client = new Client({
hostname: 'localhost',
protocol: 'http:'
}, {
socketPath: '/var/tmp/test3.sock'
})
server.listen('/var/tmp/test3.sock', () => {
client = new Client({
hostname: 'localhost',
protocol: 'http:'
}, {
socketPath: '/var/tmp/test3.sock'
})

client.request({ path: '/', method: 'GET' }, (err, data) => {
p.ifError(err)
const { statusCode, headers, body } = data
p.equal(statusCode, 200)
p.equal(headers['content-type'], 'text/plain')
const bufs = []
body.on('data', (buf) => {
bufs.push(buf)
})
body.on('end', () => {
p.equal('hello', Buffer.concat(bufs).toString('utf8'))
})
client.request({ path: '/', method: 'GET' }, (err, data) => {
p.ifError(err)
const { statusCode, headers, body } = data
p.equal(statusCode, 200)
p.equal(headers['content-type'], 'text/plain')
const bufs = []
body.on('data', (buf) => {
bufs.push(buf)
})
body.on('end', () => {
p.equal('hello', Buffer.concat(bufs).toString('utf8'))
})
})

await p.completed
})

test('http unix get pool', async (t) => {
let client
const p = tspl(t, { plan: 7 })
await p.completed
})

const server = http.createServer((req, res) => {
p.equal('/', req.url)
p.equal('GET', req.method)
p.equal('localhost', req.headers.host)
res.setHeader('Content-Type', 'text/plain')
res.end('hello')
})
test('http unix get pool', { skip }, async (t) => {
let client
const p = tspl(t, { plan: 7 })

t.after(() => {
server.close()
client.close()
})
const server = http.createServer((req, res) => {
p.equal('/', req.url)
p.equal('GET', req.method)
p.equal('localhost', req.headers.host)
res.setHeader('Content-Type', 'text/plain')
res.end('hello')
})

try {
fs.unlinkSync('/var/tmp/test3.sock')
} catch (err) {
t.after(() => {
server.close()
client.close()
})

}
try {
fs.unlinkSync('/var/tmp/test3.sock')
} catch (err) {

server.listen('/var/tmp/test3.sock', () => {
client = new Pool({
hostname: 'localhost',
protocol: 'http:'
}, {
socketPath: '/var/tmp/test3.sock'
})
}

client.request({ path: '/', method: 'GET' }, (err, data) => {
p.ifError(err)
const { statusCode, headers, body } = data
p.equal(statusCode, 200)
p.equal(headers['content-type'], 'text/plain')
const bufs = []
body.on('data', (buf) => {
bufs.push(buf)
})
body.on('end', () => {
p.equal('hello', Buffer.concat(bufs).toString('utf8'))
})
})
server.listen('/var/tmp/test3.sock', () => {
client = new Pool({
hostname: 'localhost',
protocol: 'http:'
}, {
socketPath: '/var/tmp/test3.sock'
})

await p.completed
client.request({ path: '/', method: 'GET' }, (err, data) => {
p.ifError(err)
const { statusCode, headers, body } = data
p.equal(statusCode, 200)
p.equal(headers['content-type'], 'text/plain')
const bufs = []
body.on('data', (buf) => {
bufs.push(buf)
})
body.on('end', () => {
p.equal('hello', Buffer.concat(bufs).toString('utf8'))
})
})
})

test('https get with tls opts', async (t) => {
let client
const p = tspl(t, { plan: 6 })
await p.completed
})

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

t.after(() => {
server.close()
client.close()
const server = https.createServer(pem, (req, res) => {
p.equal('/', req.url)
p.equal('GET', req.method)
res.setHeader('content-type', 'text/plain')
res.end('hello')
})

t.after(() => {
server.close()
client.close()
})

try {
fs.unlinkSync('/var/tmp/test3.sock')
} catch (err) {

}

server.listen('/var/tmp/test3.sock', () => {
client = new Client({
hostname: 'localhost',
protocol: 'https:'
}, {
socketPath: '/var/tmp/test3.sock',
tls: {
rejectUnauthorized: false
}
})

try {
fs.unlinkSync('/var/tmp/test3.sock')
} catch (err) {

}

server.listen('/var/tmp/test3.sock', () => {
client = new Client({
hostname: 'localhost',
protocol: 'https:'
}, {
socketPath: '/var/tmp/test3.sock',
tls: {
rejectUnauthorized: false
}
client.request({ path: '/', method: 'GET' }, (err, data) => {
p.ifError(err)
const { statusCode, headers, body } = data
p.equal(statusCode, 200)
p.equal(headers['content-type'], 'text/plain')
const bufs = []
body.on('data', (buf) => {
bufs.push(buf)
})

client.request({ path: '/', method: 'GET' }, (err, data) => {
p.ifError(err)
const { statusCode, headers, body } = data
p.equal(statusCode, 200)
p.equal(headers['content-type'], 'text/plain')
const bufs = []
body.on('data', (buf) => {
bufs.push(buf)
})
body.on('end', () => {
p.equal('hello', Buffer.concat(bufs).toString('utf8'))
})
body.on('end', () => {
p.equal('hello', Buffer.concat(bufs).toString('utf8'))
})
})
await p.completed
})
}
await p.completed
})

0 comments on commit c47e9e0

Please sign in to comment.