Verified Commit 254d3579 authored by Chocobozzz's avatar Chocobozzz
Browse files

Use an object to represent a server

parent 89d241a7
import * as autocannon from 'autocannon' import * as autocannon from 'autocannon'
import { writeJson } from 'fs-extra' import { writeJson } from 'fs-extra'
import { flushAndRunServer, killallServers, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils' import { createSingleServer, killallServers, PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils'
import { Video, VideoPrivacy } from '@shared/models' import { Video, VideoPrivacy } from '@shared/models'
import { registerTSPaths } from '../server/helpers/register-ts-paths' import { registerTSPaths } from '../server/helpers/register-ts-paths'
registerTSPaths() registerTSPaths()
let server: ServerInfo let server: PeerTubeServer
let video: Video let video: Video
let threadId: number let threadId: number
...@@ -188,7 +188,7 @@ function runBenchmark (options: { ...@@ -188,7 +188,7 @@ function runBenchmark (options: {
} }
async function prepare () { async function prepare () {
server = await flushAndRunServer(1, { server = await createSingleServer(1, {
rates_limit: { rates_limit: {
api: { api: {
max: 5_000_000 max: 5_000_000
......
...@@ -5,8 +5,8 @@ import * as chai from 'chai' ...@@ -5,8 +5,8 @@ import * as chai from 'chai'
import { import {
cleanupTests, cleanupTests,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, createMultipleServers,
ServerInfo, PeerTubeServer,
setAccessTokensToServers, setAccessTokensToServers,
wait, wait,
waitJobs waitJobs
...@@ -15,7 +15,7 @@ import { ...@@ -15,7 +15,7 @@ import {
const expect = chai.expect const expect = chai.expect
describe('Test AP cleaner', function () { describe('Test AP cleaner', function () {
let servers: ServerInfo[] = [] let servers: PeerTubeServer[] = []
let videoUUID1: string let videoUUID1: string
let videoUUID2: string let videoUUID2: string
let videoUUID3: string let videoUUID3: string
...@@ -30,7 +30,7 @@ describe('Test AP cleaner', function () { ...@@ -30,7 +30,7 @@ describe('Test AP cleaner', function () {
videos: { cleanup_remote_interactions: true } videos: { cleanup_remote_interactions: true }
} }
} }
servers = await flushAndRunMultipleServers(3, config) servers = await createMultipleServers(3, config)
// Get the access tokens // Get the access tokens
await setAccessTokensToServers(servers) await setAccessTokensToServers(servers)
......
...@@ -6,9 +6,9 @@ import { HttpStatusCode } from '@shared/core-utils' ...@@ -6,9 +6,9 @@ import { HttpStatusCode } from '@shared/core-utils'
import { import {
cleanupTests, cleanupTests,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, createMultipleServers,
makeActivityPubGetRequest, makeActivityPubGetRequest,
ServerInfo, PeerTubeServer,
setAccessTokensToServers, setAccessTokensToServers,
setDefaultVideoChannel setDefaultVideoChannel
} from '@shared/extra-utils' } from '@shared/extra-utils'
...@@ -17,7 +17,7 @@ import { VideoPlaylistPrivacy } from '@shared/models' ...@@ -17,7 +17,7 @@ import { VideoPlaylistPrivacy } from '@shared/models'
const expect = chai.expect const expect = chai.expect
describe('Test activitypub', function () { describe('Test activitypub', function () {
let servers: ServerInfo[] = [] let servers: PeerTubeServer[] = []
let video: { id: number, uuid: string, shortUUID: string } let video: { id: number, uuid: string, shortUUID: string }
let playlist: { id: number, uuid: string, shortUUID: string } let playlist: { id: number, uuid: string, shortUUID: string }
...@@ -62,7 +62,7 @@ describe('Test activitypub', function () { ...@@ -62,7 +62,7 @@ describe('Test activitypub', function () {
before(async function () { before(async function () {
this.timeout(30000) this.timeout(30000)
servers = await flushAndRunMultipleServers(2) servers = await createMultipleServers(2)
await setAccessTokensToServers(servers) await setAccessTokensToServers(servers)
await setDefaultVideoChannel(servers) await setDefaultVideoChannel(servers)
......
...@@ -2,19 +2,19 @@ ...@@ -2,19 +2,19 @@
import 'mocha' import 'mocha'
import * as chai from 'chai' import * as chai from 'chai'
import { cleanupTests, doubleFollow, flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' import { cleanupTests, doubleFollow, createMultipleServers, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
const expect = chai.expect const expect = chai.expect
describe('Test ActivityPub fetcher', function () { describe('Test ActivityPub fetcher', function () {
let servers: ServerInfo[] let servers: PeerTubeServer[]
// --------------------------------------------------------------- // ---------------------------------------------------------------
before(async function () { before(async function () {
this.timeout(60000) this.timeout(60000)
servers = await flushAndRunMultipleServers(3) servers = await createMultipleServers(3)
// Get the access tokens // Get the access tokens
await setAccessTokensToServers(servers) await setAccessTokensToServers(servers)
......
...@@ -5,10 +5,9 @@ import { HttpStatusCode } from '@shared/core-utils' ...@@ -5,10 +5,9 @@ import { HttpStatusCode } from '@shared/core-utils'
import { import {
cleanupTests, cleanupTests,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, createMultipleServers,
killallServers, killallServers,
reRunServer, PeerTubeServer,
ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
setDefaultVideoChannel, setDefaultVideoChannel,
wait, wait,
...@@ -17,7 +16,7 @@ import { ...@@ -17,7 +16,7 @@ import {
import { VideoPlaylistPrivacy } from '@shared/models' import { VideoPlaylistPrivacy } from '@shared/models'
describe('Test AP refresher', function () { describe('Test AP refresher', function () {
let servers: ServerInfo[] = [] let servers: PeerTubeServer[] = []
let videoUUID1: string let videoUUID1: string
let videoUUID2: string let videoUUID2: string
let videoUUID3: string let videoUUID3: string
...@@ -27,7 +26,7 @@ describe('Test AP refresher', function () { ...@@ -27,7 +26,7 @@ describe('Test AP refresher', function () {
before(async function () { before(async function () {
this.timeout(60000) this.timeout(60000)
servers = await flushAndRunMultipleServers(2, { transcoding: { enabled: false } }) servers = await createMultipleServers(2, { transcoding: { enabled: false } })
// Get the access tokens // Get the access tokens
await setAccessTokensToServers(servers) await setAccessTokensToServers(servers)
...@@ -95,7 +94,7 @@ describe('Test AP refresher', function () { ...@@ -95,7 +94,7 @@ describe('Test AP refresher', function () {
// The refresh should fail // The refresh should fail
await waitJobs([ servers[0] ]) await waitJobs([ servers[0] ])
await reRunServer(servers[1]) await servers[1].run()
await servers[0].videos.get({ id: videoUUID3 }) await servers[0].videos.get({ id: videoUUID3 })
}) })
......
...@@ -7,10 +7,9 @@ import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-c ...@@ -7,10 +7,9 @@ import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-c
import { import {
buildAbsoluteFixturePath, buildAbsoluteFixturePath,
cleanupTests, cleanupTests,
flushAndRunMultipleServers, createMultipleServers,
killallServers, killallServers,
reRunServer, PeerTubeServer,
ServerInfo,
wait wait
} from '../../../../shared/extra-utils' } from '../../../../shared/extra-utils'
import { makeFollowRequest, makePOSTAPRequest } from '../../../../shared/extra-utils/requests/activitypub' import { makeFollowRequest, makePOSTAPRequest } from '../../../../shared/extra-utils/requests/activitypub'
...@@ -20,7 +19,7 @@ import { buildGlobalHeaders } from '../../../lib/job-queue/handlers/utils/activi ...@@ -20,7 +19,7 @@ import { buildGlobalHeaders } from '../../../lib/job-queue/handlers/utils/activi
const expect = chai.expect const expect = chai.expect
function setKeysOfServer (onServer: ServerInfo, ofServer: ServerInfo, publicKey: string, privateKey: string) { function setKeysOfServer (onServer: PeerTubeServer, ofServer: PeerTubeServer, publicKey: string, privateKey: string) {
const url = 'http://localhost:' + ofServer.port + '/accounts/peertube' const url = 'http://localhost:' + ofServer.port + '/accounts/peertube'
return Promise.all([ return Promise.all([
...@@ -29,7 +28,7 @@ function setKeysOfServer (onServer: ServerInfo, ofServer: ServerInfo, publicKey: ...@@ -29,7 +28,7 @@ function setKeysOfServer (onServer: ServerInfo, ofServer: ServerInfo, publicKey:
]) ])
} }
function setUpdatedAtOfServer (onServer: ServerInfo, ofServer: ServerInfo, updatedAt: string) { function setUpdatedAtOfServer (onServer: PeerTubeServer, ofServer: PeerTubeServer, updatedAt: string) {
const url = 'http://localhost:' + ofServer.port + '/accounts/peertube' const url = 'http://localhost:' + ofServer.port + '/accounts/peertube'
return Promise.all([ return Promise.all([
...@@ -38,7 +37,7 @@ function setUpdatedAtOfServer (onServer: ServerInfo, ofServer: ServerInfo, updat ...@@ -38,7 +37,7 @@ function setUpdatedAtOfServer (onServer: ServerInfo, ofServer: ServerInfo, updat
]) ])
} }
function getAnnounceWithoutContext (server: ServerInfo) { function getAnnounceWithoutContext (server: PeerTubeServer) {
const json = require(buildAbsoluteFixturePath('./ap-json/peertube/announce-without-context.json')) const json = require(buildAbsoluteFixturePath('./ap-json/peertube/announce-without-context.json'))
const result: typeof json = {} const result: typeof json = {}
...@@ -54,7 +53,7 @@ function getAnnounceWithoutContext (server: ServerInfo) { ...@@ -54,7 +53,7 @@ function getAnnounceWithoutContext (server: ServerInfo) {
} }
describe('Test ActivityPub security', function () { describe('Test ActivityPub security', function () {
let servers: ServerInfo[] let servers: PeerTubeServer[]
let url: string let url: string
const keys = require(buildAbsoluteFixturePath('./ap-json/peertube/keys.json')) const keys = require(buildAbsoluteFixturePath('./ap-json/peertube/keys.json'))
...@@ -72,7 +71,7 @@ describe('Test ActivityPub security', function () { ...@@ -72,7 +71,7 @@ describe('Test ActivityPub security', function () {
before(async function () { before(async function () {
this.timeout(60000) this.timeout(60000)
servers = await flushAndRunMultipleServers(3) servers = await createMultipleServers(3)
url = servers[0].url + '/inbox' url = servers[0].url + '/inbox'
...@@ -172,7 +171,7 @@ describe('Test ActivityPub security', function () { ...@@ -172,7 +171,7 @@ describe('Test ActivityPub security', function () {
// Invalid peertube actor cache // Invalid peertube actor cache
await killallServers([ servers[1] ]) await killallServers([ servers[1] ])
await reRunServer(servers[1]) await servers[1].run()
const body = activityPubContextify(getAnnounceWithoutContext(servers[1])) const body = activityPubContextify(getAnnounceWithoutContext(servers[1]))
const headers = buildGlobalHeaders(body) const headers = buildGlobalHeaders(body)
......
...@@ -9,10 +9,10 @@ import { ...@@ -9,10 +9,10 @@ import {
checkBadStartPagination, checkBadStartPagination,
cleanupTests, cleanupTests,
doubleFollow, doubleFollow,
flushAndRunServer, createSingleServer,
makeGetRequest, makeGetRequest,
makePostBodyRequest, makePostBodyRequest,
ServerInfo, PeerTubeServer,
setAccessTokensToServers, setAccessTokensToServers,
waitJobs waitJobs
} from '@shared/extra-utils' } from '@shared/extra-utils'
...@@ -21,7 +21,7 @@ import { AbuseCreate, AbuseState } from '@shared/models' ...@@ -21,7 +21,7 @@ import { AbuseCreate, AbuseState } from '@shared/models'
describe('Test abuses API validators', function () { describe('Test abuses API validators', function () {
const basePath = '/api/v1/abuses/' const basePath = '/api/v1/abuses/'
let server: ServerInfo let server: PeerTubeServer
let userToken = '' let userToken = ''
let userToken2 = '' let userToken2 = ''
...@@ -35,7 +35,7 @@ describe('Test abuses API validators', function () { ...@@ -35,7 +35,7 @@ describe('Test abuses API validators', function () {
before(async function () { before(async function () {
this.timeout(30000) this.timeout(30000)
server = await flushAndRunServer(1) server = await createSingleServer(1)
await setAccessTokensToServers([ server ]) await setAccessTokensToServers([ server ])
...@@ -404,12 +404,12 @@ describe('Test abuses API validators', function () { ...@@ -404,12 +404,12 @@ describe('Test abuses API validators', function () {
describe('When trying to manage messages of a remote abuse', function () { describe('When trying to manage messages of a remote abuse', function () {
let remoteAbuseId: number let remoteAbuseId: number
let anotherServer: ServerInfo let anotherServer: PeerTubeServer
before(async function () { before(async function () {
this.timeout(50000) this.timeout(50000)
anotherServer = await flushAndRunServer(2) anotherServer = await createSingleServer(2)
await setAccessTokensToServers([ anotherServer ]) await setAccessTokensToServers([ anotherServer ])
await doubleFollow(anotherServer, server) await doubleFollow(anotherServer, server)
......
...@@ -7,20 +7,20 @@ import { ...@@ -7,20 +7,20 @@ import {
checkBadSortPagination, checkBadSortPagination,
checkBadStartPagination, checkBadStartPagination,
cleanupTests, cleanupTests,
flushAndRunServer, createSingleServer,
ServerInfo PeerTubeServer
} from '@shared/extra-utils' } from '@shared/extra-utils'
describe('Test accounts API validators', function () { describe('Test accounts API validators', function () {
const path = '/api/v1/accounts/' const path = '/api/v1/accounts/'
let server: ServerInfo let server: PeerTubeServer
// --------------------------------------------------------------- // ---------------------------------------------------------------
before(async function () { before(async function () {
this.timeout(30000) this.timeout(30000)
server = await flushAndRunServer(1) server = await createSingleServer(1)
}) })
describe('When listing accounts', function () { describe('When listing accounts', function () {
......
...@@ -5,11 +5,11 @@ import 'mocha' ...@@ -5,11 +5,11 @@ import 'mocha'
import { import {
cleanupTests, cleanupTests,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, createMultipleServers,
makeDeleteRequest, makeDeleteRequest,
makeGetRequest, makeGetRequest,
makePostBodyRequest, makePostBodyRequest,
ServerInfo, PeerTubeServer,
setAccessTokensToServers setAccessTokensToServers
} from '../../../../shared/extra-utils' } from '../../../../shared/extra-utils'
import { import {
...@@ -20,14 +20,14 @@ import { ...@@ -20,14 +20,14 @@ import {
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
describe('Test blocklist API validators', function () { describe('Test blocklist API validators', function () {
let servers: ServerInfo[] let servers: PeerTubeServer[]
let server: ServerInfo let server: PeerTubeServer
let userAccessToken: string let userAccessToken: string
before(async function () { before(async function () {
this.timeout(60000) this.timeout(60000)
servers = await flushAndRunMultipleServers(2) servers = await createMultipleServers(2)
await setAccessTokensToServers(servers) await setAccessTokensToServers(servers)
server = servers[0] server = servers[0]
......
...@@ -3,15 +3,15 @@ ...@@ -3,15 +3,15 @@
import 'mocha' import 'mocha'
import { import {
cleanupTests, cleanupTests,
flushAndRunServer, createSingleServer,
ServerInfo, PeerTubeServer,
setAccessTokensToServers setAccessTokensToServers
} from '../../../../shared/extra-utils' } from '../../../../shared/extra-utils'
import { makePostBodyRequest } from '../../../../shared/extra-utils/requests/requests' import { makePostBodyRequest } from '../../../../shared/extra-utils/requests/requests'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
describe('Test bulk API validators', function () { describe('Test bulk API validators', function () {
let server: ServerInfo let server: PeerTubeServer
let userAccessToken: string let userAccessToken: string
// --------------------------------------------------------------- // ---------------------------------------------------------------
...@@ -19,7 +19,7 @@ describe('Test bulk API validators', function () { ...@@ -19,7 +19,7 @@ describe('Test bulk API validators', function () {
before(async function () { before(async function () {
this.timeout(120000) this.timeout(120000)
server = await flushAndRunServer(1) server = await createSingleServer(1)
await setAccessTokensToServers([ server ]) await setAccessTokensToServers([ server ])
const user = { username: 'user1', password: 'password' } const user = { username: 'user1', password: 'password' }
......
...@@ -5,18 +5,18 @@ import { omit } from 'lodash' ...@@ -5,18 +5,18 @@ import { omit } from 'lodash'
import { HttpStatusCode } from '@shared/core-utils' import { HttpStatusCode } from '@shared/core-utils'
import { import {
cleanupTests, cleanupTests,
flushAndRunServer, createSingleServer,
makeDeleteRequest, makeDeleteRequest,
makeGetRequest, makeGetRequest,
makePutBodyRequest, makePutBodyRequest,
ServerInfo, PeerTubeServer,
setAccessTokensToServers setAccessTokensToServers
} from '@shared/extra-utils' } from '@shared/extra-utils'
import { CustomConfig } from '@shared/models' import { CustomConfig } from '@shared/models'
describe('Test config API validators', function () { describe('Test config API validators', function () {
const path = '/api/v1/config/custom' const path = '/api/v1/config/custom'
let server: ServerInfo let server: PeerTubeServer
let userAccessToken: string let userAccessToken: string
const updateParams: CustomConfig = { const updateParams: CustomConfig = {
instance: { instance: {
...@@ -197,7 +197,7 @@ describe('Test config API validators', function () { ...@@ -197,7 +197,7 @@ describe('Test config API validators', function () {
before(async function () { before(async function () {
this.timeout(30000) this.timeout(30000)
server = await flushAndRunServer(1) server = await createSingleServer(1)
await setAccessTokensToServers([ server ]) await setAccessTokensToServers([ server ])
......
...@@ -2,11 +2,11 @@ ...@@ -2,11 +2,11 @@
import 'mocha' import 'mocha'
import { HttpStatusCode } from '@shared/core-utils' import { HttpStatusCode } from '@shared/core-utils'
import { cleanupTests, flushAndRunServer, killallServers, MockSmtpServer, reRunServer, ServerInfo } from '@shared/extra-utils' import { cleanupTests, createSingleServer, killallServers, MockSmtpServer, PeerTubeServer } from '@shared/extra-utils'
import { ContactFormCommand } from '@shared/extra-utils/server' import { ContactFormCommand } from '@shared/extra-utils/server'
describe('Test contact form API validators', function () { describe('Test contact form API validators', function () {
let server: ServerInfo let server: PeerTubeServer
const emails: object[] = [] const emails: object[] = []
const defaultBody = { const defaultBody = {
fromName: 'super name', fromName: 'super name',
...@@ -25,7 +25,7 @@ describe('Test contact form API validators', function () { ...@@ -25,7 +25,7 @@ describe('Test contact form API validators', function () {
emailPort = await MockSmtpServer.Instance.collectEmails(emails) emailPort = await MockSmtpServer.Instance.collectEmails(emails)
// Email is disabled // Email is disabled
server = await flushAndRunServer(1) server = await createSingleServer(1)
command = server.contactForm command = server.contactForm
}) })
...@@ -39,7 +39,7 @@ describe('Test contact form API validators', function () { ...@@ -39,7 +39,7 @@ describe('Test contact form API validators', function () {
await killallServers([ server ]) await killallServers([ server ])
// Contact form is disabled // Contact form is disabled
await reRunServer(server, { smtp: { hostname: 'localhost', port: emailPort }, contact_form: { enabled: false } }) await server.run({ smtp: { hostname: 'localhost', port: emailPort }, contact_form: { enabled: false } })