mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2024-11-28 03:23:57 -06:00
Use random port for mock servers in tests
This commit is contained in:
parent
38c5c166f4
commit
63da15eb18
@ -40,6 +40,7 @@ describe('Official plugin auto-block videos', function () {
|
|||||||
let blocklistServer: MockBlocklist
|
let blocklistServer: MockBlocklist
|
||||||
let server1Videos: Video[] = []
|
let server1Videos: Video[] = []
|
||||||
let server2Videos: Video[] = []
|
let server2Videos: Video[] = []
|
||||||
|
let port: number
|
||||||
|
|
||||||
before(async function () {
|
before(async function () {
|
||||||
this.timeout(60000)
|
this.timeout(60000)
|
||||||
@ -56,7 +57,7 @@ describe('Official plugin auto-block videos', function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
blocklistServer = new MockBlocklist()
|
blocklistServer = new MockBlocklist()
|
||||||
await blocklistServer.initialize()
|
port = await blocklistServer.initialize()
|
||||||
|
|
||||||
await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' })
|
await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' })
|
||||||
await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' })
|
await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' })
|
||||||
@ -82,7 +83,7 @@ describe('Official plugin auto-block videos', function () {
|
|||||||
accessToken: servers[0].accessToken,
|
accessToken: servers[0].accessToken,
|
||||||
npmName: 'peertube-plugin-auto-block-videos',
|
npmName: 'peertube-plugin-auto-block-videos',
|
||||||
settings: {
|
settings: {
|
||||||
'blocklist-urls': 'http://localhost:42100/blocklist',
|
'blocklist-urls': `http://localhost:${port}/blocklist`,
|
||||||
'check-seconds-interval': 1
|
'check-seconds-interval': 1
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -31,6 +31,7 @@ describe('Official plugin auto-mute', function () {
|
|||||||
const autoMuteListPath = '/plugins/auto-mute/router/api/v1/mute-list'
|
const autoMuteListPath = '/plugins/auto-mute/router/api/v1/mute-list'
|
||||||
let servers: ServerInfo[]
|
let servers: ServerInfo[]
|
||||||
let blocklistServer: MockBlocklist
|
let blocklistServer: MockBlocklist
|
||||||
|
let port: number
|
||||||
|
|
||||||
before(async function () {
|
before(async function () {
|
||||||
this.timeout(30000)
|
this.timeout(30000)
|
||||||
@ -47,7 +48,7 @@ describe('Official plugin auto-mute', function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
blocklistServer = new MockBlocklist()
|
blocklistServer = new MockBlocklist()
|
||||||
await blocklistServer.initialize()
|
port = await blocklistServer.initialize()
|
||||||
|
|
||||||
await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' })
|
await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' })
|
||||||
await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' })
|
await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' })
|
||||||
@ -61,7 +62,7 @@ describe('Official plugin auto-mute', function () {
|
|||||||
accessToken: servers[0].accessToken,
|
accessToken: servers[0].accessToken,
|
||||||
npmName: 'peertube-plugin-auto-mute',
|
npmName: 'peertube-plugin-auto-mute',
|
||||||
settings: {
|
settings: {
|
||||||
'blocklist-urls': 'http://localhost:42100/blocklist',
|
'blocklist-urls': `http://localhost:${port}/blocklist`,
|
||||||
'check-seconds-interval': 1
|
'check-seconds-interval': 1
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import * as express from 'express'
|
import * as express from 'express'
|
||||||
import { Server } from 'http'
|
import { Server } from 'http'
|
||||||
|
import { randomInt } from '@shared/core-utils'
|
||||||
|
|
||||||
type BlocklistResponse = {
|
type BlocklistResponse = {
|
||||||
data: {
|
data: {
|
||||||
@ -14,14 +15,15 @@ export class MockBlocklist {
|
|||||||
private server: Server
|
private server: Server
|
||||||
|
|
||||||
initialize () {
|
initialize () {
|
||||||
return new Promise<void>(res => {
|
return new Promise<number>(res => {
|
||||||
const app = express()
|
const app = express()
|
||||||
|
|
||||||
app.get('/blocklist', (req: express.Request, res: express.Response) => {
|
app.get('/blocklist', (req: express.Request, res: express.Response) => {
|
||||||
return res.json(this.body)
|
return res.json(this.body)
|
||||||
})
|
})
|
||||||
|
|
||||||
this.server = app.listen(42100, () => res())
|
const port = 42201 + randomInt(1, 100)
|
||||||
|
this.server = app.listen(port, () => res(port))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user