Random listen for mocked servers
This commit is contained in:
parent
5480933b7f
commit
d1bfbdeb20
|
@ -182,7 +182,7 @@ function runTestSuite (options: {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should upload a video and move it to the object storage without transcoding', async function () {
|
it('Should upload a video and move it to the object storage without transcoding', async function () {
|
||||||
this.timeout(20000)
|
this.timeout(40000)
|
||||||
|
|
||||||
const { uuid } = await servers[0].videos.quickUpload({ name: 'video 1' })
|
const { uuid } = await servers[0].videos.quickUpload({ name: 'video 1' })
|
||||||
uuidsToDelete.push(uuid)
|
uuidsToDelete.push(uuid)
|
||||||
|
|
|
@ -1,15 +1,13 @@
|
||||||
import express from 'express'
|
import express from 'express'
|
||||||
import { Server } from 'http'
|
import { Server } from 'http'
|
||||||
import { randomInt } from '@shared/core-utils'
|
import { getPort, randomListen, terminateServer } from './utils'
|
||||||
import { terminateServer } from './utils'
|
|
||||||
|
|
||||||
export class MockInstancesIndex {
|
export class MockInstancesIndex {
|
||||||
private server: Server
|
private server: Server
|
||||||
|
|
||||||
private readonly indexInstances: { host: string, createdAt: string }[] = []
|
private readonly indexInstances: { host: string, createdAt: string }[] = []
|
||||||
|
|
||||||
initialize () {
|
async initialize () {
|
||||||
return new Promise<number>(res => {
|
|
||||||
const app = express()
|
const app = express()
|
||||||
|
|
||||||
app.use('/', (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
app.use('/', (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||||
|
@ -33,9 +31,9 @@ export class MockInstancesIndex {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
const port = 42000 + randomInt(1, 1000)
|
this.server = await randomListen(app)
|
||||||
this.server = app.listen(port, () => res(port))
|
|
||||||
})
|
return getPort(this.server)
|
||||||
}
|
}
|
||||||
|
|
||||||
addInstance (host: string) {
|
addInstance (host: string) {
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
import express from 'express'
|
import express from 'express'
|
||||||
import { randomInt } from '@shared/core-utils'
|
import { Server } from 'http'
|
||||||
|
import { getPort, randomListen } from './utils'
|
||||||
|
|
||||||
export class MockJoinPeerTubeVersions {
|
export class MockJoinPeerTubeVersions {
|
||||||
|
private server: Server
|
||||||
private latestVersion: string
|
private latestVersion: string
|
||||||
|
|
||||||
initialize () {
|
async initialize () {
|
||||||
return new Promise<number>(res => {
|
|
||||||
const app = express()
|
const app = express()
|
||||||
|
|
||||||
app.use('/', (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
app.use('/', (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||||
|
@ -22,9 +23,9 @@ export class MockJoinPeerTubeVersions {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
const port = 43000 + randomInt(1, 1000)
|
this.server = await randomListen(app)
|
||||||
app.listen(port, () => res(port))
|
|
||||||
})
|
return getPort(this.server)
|
||||||
}
|
}
|
||||||
|
|
||||||
setLatestVersion (latestVersion: string) {
|
setLatestVersion (latestVersion: string) {
|
||||||
|
|
|
@ -2,15 +2,13 @@ import express from 'express'
|
||||||
import got, { RequestError } from 'got'
|
import got, { RequestError } from 'got'
|
||||||
import { Server } from 'http'
|
import { Server } from 'http'
|
||||||
import { pipeline } from 'stream'
|
import { pipeline } from 'stream'
|
||||||
import { randomInt } from '@shared/core-utils'
|
|
||||||
import { ObjectStorageCommand } from '../server'
|
import { ObjectStorageCommand } from '../server'
|
||||||
import { terminateServer } from './utils'
|
import { getPort, randomListen, terminateServer } from './utils'
|
||||||
|
|
||||||
export class MockObjectStorage {
|
export class MockObjectStorage {
|
||||||
private server: Server
|
private server: Server
|
||||||
|
|
||||||
initialize () {
|
async initialize () {
|
||||||
return new Promise<number>(res => {
|
|
||||||
const app = express()
|
const app = express()
|
||||||
|
|
||||||
app.get('/:bucketName/:path(*)', (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
app.get('/:bucketName/:path(*)', (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||||
|
@ -32,9 +30,9 @@ export class MockObjectStorage {
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
const port = 44000 + randomInt(1, 1000)
|
this.server = await randomListen(app)
|
||||||
this.server = app.listen(port, () => res(port))
|
|
||||||
})
|
return getPort(this.server)
|
||||||
}
|
}
|
||||||
|
|
||||||
terminate () {
|
terminate () {
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import express, { Request, Response } from 'express'
|
import express, { Request, Response } from 'express'
|
||||||
import { Server } from 'http'
|
import { Server } from 'http'
|
||||||
import { randomInt } from '@shared/core-utils'
|
import { getPort, randomListen, terminateServer } from './utils'
|
||||||
import { terminateServer } from './utils'
|
|
||||||
|
|
||||||
type BlocklistResponse = {
|
type BlocklistResponse = {
|
||||||
data: {
|
data: {
|
||||||
|
@ -15,17 +14,16 @@ export class MockBlocklist {
|
||||||
private body: BlocklistResponse
|
private body: BlocklistResponse
|
||||||
private server: Server
|
private server: Server
|
||||||
|
|
||||||
initialize () {
|
async initialize () {
|
||||||
return new Promise<number>(res => {
|
|
||||||
const app = express()
|
const app = express()
|
||||||
|
|
||||||
app.get('/blocklist', (req: Request, res: Response) => {
|
app.get('/blocklist', (req: Request, res: Response) => {
|
||||||
return res.json(this.body)
|
return res.json(this.body)
|
||||||
})
|
})
|
||||||
|
|
||||||
const port = 45000 + randomInt(1, 1000)
|
this.server = await randomListen(app)
|
||||||
this.server = app.listen(port, () => res(port))
|
|
||||||
})
|
return getPort(this.server)
|
||||||
}
|
}
|
||||||
|
|
||||||
replace (body: BlocklistResponse) {
|
replace (body: BlocklistResponse) {
|
||||||
|
|
|
@ -1,18 +1,15 @@
|
||||||
|
|
||||||
import { createServer, Server } from 'http'
|
import { createServer, Server } from 'http'
|
||||||
import proxy from 'proxy'
|
import proxy from 'proxy'
|
||||||
import { randomInt } from '@shared/core-utils'
|
import { getPort, terminateServer } from './utils'
|
||||||
import { terminateServer } from './utils'
|
|
||||||
|
|
||||||
class MockProxy {
|
class MockProxy {
|
||||||
private server: Server
|
private server: Server
|
||||||
|
|
||||||
initialize () {
|
initialize () {
|
||||||
return new Promise<number>(res => {
|
return new Promise<number>(res => {
|
||||||
const port = 46000 + randomInt(1, 1000)
|
|
||||||
|
|
||||||
this.server = proxy(createServer())
|
this.server = proxy(createServer())
|
||||||
this.server.listen(port, () => res(port))
|
this.server.listen(0, () => res(getPort(this.server)))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,18 @@
|
||||||
|
import { Express } from 'express'
|
||||||
import { Server } from 'http'
|
import { Server } from 'http'
|
||||||
|
import { AddressInfo } from 'net'
|
||||||
|
|
||||||
|
function randomListen (app: Express) {
|
||||||
|
return new Promise<Server>(res => {
|
||||||
|
const server = app.listen(0, () => res(server))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPort (server: Server) {
|
||||||
|
const address = server.address() as AddressInfo
|
||||||
|
|
||||||
|
return address.port
|
||||||
|
}
|
||||||
|
|
||||||
function terminateServer (server: Server) {
|
function terminateServer (server: Server) {
|
||||||
if (!server) return Promise.resolve()
|
if (!server) return Promise.resolve()
|
||||||
|
@ -13,5 +27,7 @@ function terminateServer (server: Server) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
randomListen,
|
||||||
|
getPort,
|
||||||
terminateServer
|
terminateServer
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user