Use random port for mock servers in tests

This commit is contained in:
Chocobozzz 2021-06-03 09:06:51 +02:00
parent 38c5c166f4
commit 63da15eb18
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
3 changed files with 10 additions and 6 deletions

View File

@ -40,6 +40,7 @@ describe('Official plugin auto-block videos', function () {
let blocklistServer: MockBlocklist
let server1Videos: Video[] = []
let server2Videos: Video[] = []
let port: number
before(async function () {
this.timeout(60000)
@ -56,7 +57,7 @@ describe('Official plugin auto-block videos', function () {
}
blocklistServer = new MockBlocklist()
await blocklistServer.initialize()
port = await blocklistServer.initialize()
await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' })
await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' })
@ -82,7 +83,7 @@ describe('Official plugin auto-block videos', function () {
accessToken: servers[0].accessToken,
npmName: 'peertube-plugin-auto-block-videos',
settings: {
'blocklist-urls': 'http://localhost:42100/blocklist',
'blocklist-urls': `http://localhost:${port}/blocklist`,
'check-seconds-interval': 1
}
})

View File

@ -31,6 +31,7 @@ describe('Official plugin auto-mute', function () {
const autoMuteListPath = '/plugins/auto-mute/router/api/v1/mute-list'
let servers: ServerInfo[]
let blocklistServer: MockBlocklist
let port: number
before(async function () {
this.timeout(30000)
@ -47,7 +48,7 @@ describe('Official plugin auto-mute', function () {
}
blocklistServer = new MockBlocklist()
await blocklistServer.initialize()
port = await blocklistServer.initialize()
await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' })
await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' })
@ -61,7 +62,7 @@ describe('Official plugin auto-mute', function () {
accessToken: servers[0].accessToken,
npmName: 'peertube-plugin-auto-mute',
settings: {
'blocklist-urls': 'http://localhost:42100/blocklist',
'blocklist-urls': `http://localhost:${port}/blocklist`,
'check-seconds-interval': 1
}
})

View File

@ -1,5 +1,6 @@
import * as express from 'express'
import { Server } from 'http'
import { randomInt } from '@shared/core-utils'
type BlocklistResponse = {
data: {
@ -14,14 +15,15 @@ export class MockBlocklist {
private server: Server
initialize () {
return new Promise<void>(res => {
return new Promise<number>(res => {
const app = express()
app.get('/blocklist', (req: express.Request, res: express.Response) => {
return res.json(this.body)
})
this.server = app.listen(42100, () => res())
const port = 42201 + randomInt(1, 100)
this.server = app.listen(port, () => res(port))
})
}