diff options
Diffstat (limited to 'shared')
20 files changed, 441 insertions, 427 deletions
diff --git a/shared/extra-utils/miscs/checks.ts b/shared/extra-utils/miscs/checks.ts index 8f7bdb9b5..c81460330 100644 --- a/shared/extra-utils/miscs/checks.ts +++ b/shared/extra-utils/miscs/checks.ts | |||
@@ -6,7 +6,7 @@ import { join } from 'path' | |||
6 | import { root } from '@server/helpers/core-utils' | 6 | import { root } from '@server/helpers/core-utils' |
7 | import { HttpStatusCode } from '@shared/core-utils' | 7 | import { HttpStatusCode } from '@shared/core-utils' |
8 | import { makeGetRequest } from '../requests' | 8 | import { makeGetRequest } from '../requests' |
9 | import { ServerInfo } from '../server' | 9 | import { PeerTubeServer } from '../server' |
10 | 10 | ||
11 | // Default interval -> 5 minutes | 11 | // Default interval -> 5 minutes |
12 | function dateIsValid (dateString: string, interval = 300000) { | 12 | function dateIsValid (dateString: string, interval = 300000) { |
@@ -33,7 +33,7 @@ async function testImage (url: string, imageName: string, imagePath: string, ext | |||
33 | expect(data.length).to.be.below(maxLength, 'the generated image is way larger than the recorded fixture') | 33 | expect(data.length).to.be.below(maxLength, 'the generated image is way larger than the recorded fixture') |
34 | } | 34 | } |
35 | 35 | ||
36 | async function testFileExistsOrNot (server: ServerInfo, directory: string, filePath: string, exist: boolean) { | 36 | async function testFileExistsOrNot (server: PeerTubeServer, directory: string, filePath: string, exist: boolean) { |
37 | const base = server.servers.buildDirectory(directory) | 37 | const base = server.servers.buildDirectory(directory) |
38 | 38 | ||
39 | expect(await pathExists(join(base, filePath))).to.equal(exist) | 39 | expect(await pathExists(join(base, filePath))).to.equal(exist) |
diff --git a/shared/extra-utils/miscs/webtorrent.ts b/shared/extra-utils/miscs/webtorrent.ts index 84e390b2a..815ea3d56 100644 --- a/shared/extra-utils/miscs/webtorrent.ts +++ b/shared/extra-utils/miscs/webtorrent.ts | |||
@@ -2,7 +2,7 @@ import { readFile } from 'fs-extra' | |||
2 | import * as parseTorrent from 'parse-torrent' | 2 | import * as parseTorrent from 'parse-torrent' |
3 | import { join } from 'path' | 3 | import { join } from 'path' |
4 | import * as WebTorrent from 'webtorrent' | 4 | import * as WebTorrent from 'webtorrent' |
5 | import { ServerInfo } from '../server' | 5 | import { PeerTubeServer } from '../server' |
6 | 6 | ||
7 | let webtorrent: WebTorrent.Instance | 7 | let webtorrent: WebTorrent.Instance |
8 | 8 | ||
@@ -15,7 +15,7 @@ function webtorrentAdd (torrent: string, refreshWebTorrent = false) { | |||
15 | return new Promise<WebTorrent.Torrent>(res => webtorrent.add(torrent, res)) | 15 | return new Promise<WebTorrent.Torrent>(res => webtorrent.add(torrent, res)) |
16 | } | 16 | } |
17 | 17 | ||
18 | async function parseTorrentVideo (server: ServerInfo, videoUUID: string, resolution: number) { | 18 | async function parseTorrentVideo (server: PeerTubeServer, videoUUID: string, resolution: number) { |
19 | const torrentName = videoUUID + '-' + resolution + '.torrent' | 19 | const torrentName = videoUUID + '-' + resolution + '.torrent' |
20 | const torrentPath = server.servers.buildDirectory(join('torrents', torrentName)) | 20 | const torrentPath = server.servers.buildDirectory(join('torrents', torrentName)) |
21 | 21 | ||
diff --git a/shared/extra-utils/server/directories.ts b/shared/extra-utils/server/directories.ts index 3cd38a561..b6465cbf4 100644 --- a/shared/extra-utils/server/directories.ts +++ b/shared/extra-utils/server/directories.ts | |||
@@ -4,9 +4,9 @@ import { expect } from 'chai' | |||
4 | import { pathExists, readdir } from 'fs-extra' | 4 | import { pathExists, readdir } from 'fs-extra' |
5 | import { join } from 'path' | 5 | import { join } from 'path' |
6 | import { root } from '@server/helpers/core-utils' | 6 | import { root } from '@server/helpers/core-utils' |
7 | import { ServerInfo } from './servers' | 7 | import { PeerTubeServer } from './server' |
8 | 8 | ||
9 | async function checkTmpIsEmpty (server: ServerInfo) { | 9 | async function checkTmpIsEmpty (server: PeerTubeServer) { |
10 | await checkDirectoryIsEmpty(server, 'tmp', [ 'plugins-global.css', 'hls', 'resumable-uploads' ]) | 10 | await checkDirectoryIsEmpty(server, 'tmp', [ 'plugins-global.css', 'hls', 'resumable-uploads' ]) |
11 | 11 | ||
12 | if (await pathExists(join('test' + server.internalServerNumber, 'tmp', 'hls'))) { | 12 | if (await pathExists(join('test' + server.internalServerNumber, 'tmp', 'hls'))) { |
@@ -14,7 +14,7 @@ async function checkTmpIsEmpty (server: ServerInfo) { | |||
14 | } | 14 | } |
15 | } | 15 | } |
16 | 16 | ||
17 | async function checkDirectoryIsEmpty (server: ServerInfo, directory: string, exceptions: string[] = []) { | 17 | async function checkDirectoryIsEmpty (server: PeerTubeServer, directory: string, exceptions: string[] = []) { |
18 | const testDirectory = 'test' + server.internalServerNumber | 18 | const testDirectory = 'test' + server.internalServerNumber |
19 | 19 | ||
20 | const directoryPath = join(root(), testDirectory, directory) | 20 | const directoryPath = join(root(), testDirectory, directory) |
diff --git a/shared/extra-utils/server/follows-command.ts b/shared/extra-utils/server/follows-command.ts index 4e1e56d7a..4e9ed9494 100644 --- a/shared/extra-utils/server/follows-command.ts +++ b/shared/extra-utils/server/follows-command.ts | |||
@@ -2,7 +2,7 @@ import { pick } from 'lodash' | |||
2 | import { ActivityPubActorType, ActorFollow, FollowState, ResultList } from '@shared/models' | 2 | import { ActivityPubActorType, ActorFollow, FollowState, ResultList } from '@shared/models' |
3 | import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' | 3 | import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' |
4 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | 4 | import { AbstractCommand, OverrideCommandOptions } from '../shared' |
5 | import { ServerInfo } from './servers' | 5 | import { PeerTubeServer } from './server' |
6 | 6 | ||
7 | export class FollowsCommand extends AbstractCommand { | 7 | export class FollowsCommand extends AbstractCommand { |
8 | 8 | ||
@@ -70,7 +70,7 @@ export class FollowsCommand extends AbstractCommand { | |||
70 | } | 70 | } |
71 | 71 | ||
72 | async unfollow (options: OverrideCommandOptions & { | 72 | async unfollow (options: OverrideCommandOptions & { |
73 | target: ServerInfo | 73 | target: PeerTubeServer |
74 | }) { | 74 | }) { |
75 | const path = '/api/v1/server/following/' + options.target.host | 75 | const path = '/api/v1/server/following/' + options.target.host |
76 | 76 | ||
@@ -112,7 +112,7 @@ export class FollowsCommand extends AbstractCommand { | |||
112 | } | 112 | } |
113 | 113 | ||
114 | removeFollower (options: OverrideCommandOptions & { | 114 | removeFollower (options: OverrideCommandOptions & { |
115 | follower: ServerInfo | 115 | follower: PeerTubeServer |
116 | }) { | 116 | }) { |
117 | const path = '/api/v1/server/followers/peertube@' + options.follower.host | 117 | const path = '/api/v1/server/followers/peertube@' + options.follower.host |
118 | 118 | ||
diff --git a/shared/extra-utils/server/follows.ts b/shared/extra-utils/server/follows.ts index 50ae898cc..0188be1aa 100644 --- a/shared/extra-utils/server/follows.ts +++ b/shared/extra-utils/server/follows.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import { waitJobs } from './jobs' | 1 | import { waitJobs } from './jobs' |
2 | import { ServerInfo } from './servers' | 2 | import { PeerTubeServer } from './server' |
3 | 3 | ||
4 | async function doubleFollow (server1: ServerInfo, server2: ServerInfo) { | 4 | async function doubleFollow (server1: PeerTubeServer, server2: PeerTubeServer) { |
5 | await Promise.all([ | 5 | await Promise.all([ |
6 | server1.follows.follow({ targets: [ server2.url ] }), | 6 | server1.follows.follow({ targets: [ server2.url ] }), |
7 | server2.follows.follow({ targets: [ server1.url ] }) | 7 | server2.follows.follow({ targets: [ server1.url ] }) |
diff --git a/shared/extra-utils/server/index.ts b/shared/extra-utils/server/index.ts index 669b004cd..9055dfc57 100644 --- a/shared/extra-utils/server/index.ts +++ b/shared/extra-utils/server/index.ts | |||
@@ -9,6 +9,7 @@ export * from './jobs-command' | |||
9 | export * from './plugins-command' | 9 | export * from './plugins-command' |
10 | export * from './plugins' | 10 | export * from './plugins' |
11 | export * from './redundancy-command' | 11 | export * from './redundancy-command' |
12 | export * from './server' | ||
12 | export * from './servers-command' | 13 | export * from './servers-command' |
13 | export * from './servers' | 14 | export * from './servers' |
14 | export * from './stats-command' | 15 | export * from './stats-command' |
diff --git a/shared/extra-utils/server/jobs.ts b/shared/extra-utils/server/jobs.ts index 754530977..64a0353eb 100644 --- a/shared/extra-utils/server/jobs.ts +++ b/shared/extra-utils/server/jobs.ts | |||
@@ -1,17 +1,17 @@ | |||
1 | 1 | ||
2 | import { JobState } from '../../models' | 2 | import { JobState } from '../../models' |
3 | import { wait } from '../miscs' | 3 | import { wait } from '../miscs' |
4 | import { ServerInfo } from './servers' | 4 | import { PeerTubeServer } from './server' |
5 | 5 | ||
6 | async function waitJobs (serversArg: ServerInfo[] | ServerInfo) { | 6 | async function waitJobs (serversArg: PeerTubeServer[] | PeerTubeServer) { |
7 | const pendingJobWait = process.env.NODE_PENDING_JOB_WAIT | 7 | const pendingJobWait = process.env.NODE_PENDING_JOB_WAIT |
8 | ? parseInt(process.env.NODE_PENDING_JOB_WAIT, 10) | 8 | ? parseInt(process.env.NODE_PENDING_JOB_WAIT, 10) |
9 | : 250 | 9 | : 250 |
10 | 10 | ||
11 | let servers: ServerInfo[] | 11 | let servers: PeerTubeServer[] |
12 | 12 | ||
13 | if (Array.isArray(serversArg) === false) servers = [ serversArg as ServerInfo ] | 13 | if (Array.isArray(serversArg) === false) servers = [ serversArg as PeerTubeServer ] |
14 | else servers = serversArg as ServerInfo[] | 14 | else servers = serversArg as PeerTubeServer[] |
15 | 15 | ||
16 | const states: JobState[] = [ 'waiting', 'active', 'delayed' ] | 16 | const states: JobState[] = [ 'waiting', 'active', 'delayed' ] |
17 | const repeatableJobs = [ 'videos-views', 'activitypub-cleaner' ] | 17 | const repeatableJobs = [ 'videos-views', 'activitypub-cleaner' ] |
diff --git a/shared/extra-utils/server/plugins.ts b/shared/extra-utils/server/plugins.ts index d1cc7e383..0f5fabd5a 100644 --- a/shared/extra-utils/server/plugins.ts +++ b/shared/extra-utils/server/plugins.ts | |||
@@ -1,9 +1,9 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | 2 | ||
3 | import { expect } from 'chai' | 3 | import { expect } from 'chai' |
4 | import { ServerInfo } from '../server/servers' | 4 | import { PeerTubeServer } from '../server/server' |
5 | 5 | ||
6 | async function testHelloWorldRegisteredSettings (server: ServerInfo) { | 6 | async function testHelloWorldRegisteredSettings (server: PeerTubeServer) { |
7 | const body = await server.plugins.getRegisteredSettings({ npmName: 'peertube-plugin-hello-world' }) | 7 | const body = await server.plugins.getRegisteredSettings({ npmName: 'peertube-plugin-hello-world' }) |
8 | 8 | ||
9 | const registeredSettings = body.registeredSettings | 9 | const registeredSettings = body.registeredSettings |
diff --git a/shared/extra-utils/server/server.ts b/shared/extra-utils/server/server.ts new file mode 100644 index 000000000..b1347661f --- /dev/null +++ b/shared/extra-utils/server/server.ts | |||
@@ -0,0 +1,376 @@ | |||
1 | import { ChildProcess, fork } from 'child_process' | ||
2 | import { copy } from 'fs-extra' | ||
3 | import { join } from 'path' | ||
4 | import { root } from '@server/helpers/core-utils' | ||
5 | import { randomInt } from '../../core-utils/miscs/miscs' | ||
6 | import { VideoChannel } from '../../models/videos' | ||
7 | import { BulkCommand } from '../bulk' | ||
8 | import { CLICommand } from '../cli' | ||
9 | import { CustomPagesCommand } from '../custom-pages' | ||
10 | import { FeedCommand } from '../feeds' | ||
11 | import { LogsCommand } from '../logs' | ||
12 | import { parallelTests, SQLCommand } from '../miscs' | ||
13 | import { AbusesCommand } from '../moderation' | ||
14 | import { OverviewsCommand } from '../overviews' | ||
15 | import { SearchCommand } from '../search' | ||
16 | import { SocketIOCommand } from '../socket' | ||
17 | import { AccountsCommand, BlocklistCommand, LoginCommand, NotificationsCommand, SubscriptionsCommand, UsersCommand } from '../users' | ||
18 | import { | ||
19 | BlacklistCommand, | ||
20 | CaptionsCommand, | ||
21 | ChangeOwnershipCommand, | ||
22 | ChannelsCommand, | ||
23 | HistoryCommand, | ||
24 | ImportsCommand, | ||
25 | LiveCommand, | ||
26 | PlaylistsCommand, | ||
27 | ServicesCommand, | ||
28 | StreamingPlaylistsCommand, | ||
29 | VideosCommand | ||
30 | } from '../videos' | ||
31 | import { CommentsCommand } from '../videos/comments-command' | ||
32 | import { ConfigCommand } from './config-command' | ||
33 | import { ContactFormCommand } from './contact-form-command' | ||
34 | import { DebugCommand } from './debug-command' | ||
35 | import { FollowsCommand } from './follows-command' | ||
36 | import { JobsCommand } from './jobs-command' | ||
37 | import { PluginsCommand } from './plugins-command' | ||
38 | import { RedundancyCommand } from './redundancy-command' | ||
39 | import { ServersCommand } from './servers-command' | ||
40 | import { StatsCommand } from './stats-command' | ||
41 | |||
42 | export type RunServerOptions = { | ||
43 | hideLogs?: boolean | ||
44 | execArgv?: string[] | ||
45 | } | ||
46 | |||
47 | export class PeerTubeServer { | ||
48 | app?: ChildProcess | ||
49 | |||
50 | url: string | ||
51 | host?: string | ||
52 | hostname?: string | ||
53 | port?: number | ||
54 | |||
55 | rtmpPort?: number | ||
56 | |||
57 | parallel?: boolean | ||
58 | internalServerNumber: number | ||
59 | |||
60 | serverNumber?: number | ||
61 | customConfigFile?: string | ||
62 | |||
63 | store?: { | ||
64 | client?: { | ||
65 | id?: string | ||
66 | secret?: string | ||
67 | } | ||
68 | |||
69 | user?: { | ||
70 | username: string | ||
71 | password: string | ||
72 | email?: string | ||
73 | } | ||
74 | |||
75 | channel?: VideoChannel | ||
76 | |||
77 | video?: { | ||
78 | id: number | ||
79 | uuid: string | ||
80 | shortUUID: string | ||
81 | name?: string | ||
82 | url?: string | ||
83 | |||
84 | account?: { | ||
85 | name: string | ||
86 | } | ||
87 | |||
88 | embedPath?: string | ||
89 | } | ||
90 | |||
91 | videos?: { id: number, uuid: string }[] | ||
92 | } | ||
93 | |||
94 | accessToken?: string | ||
95 | refreshToken?: string | ||
96 | |||
97 | bulk?: BulkCommand | ||
98 | cli?: CLICommand | ||
99 | customPage?: CustomPagesCommand | ||
100 | feed?: FeedCommand | ||
101 | logs?: LogsCommand | ||
102 | abuses?: AbusesCommand | ||
103 | overviews?: OverviewsCommand | ||
104 | search?: SearchCommand | ||
105 | contactForm?: ContactFormCommand | ||
106 | debug?: DebugCommand | ||
107 | follows?: FollowsCommand | ||
108 | jobs?: JobsCommand | ||
109 | plugins?: PluginsCommand | ||
110 | redundancy?: RedundancyCommand | ||
111 | stats?: StatsCommand | ||
112 | config?: ConfigCommand | ||
113 | socketIO?: SocketIOCommand | ||
114 | accounts?: AccountsCommand | ||
115 | blocklist?: BlocklistCommand | ||
116 | subscriptions?: SubscriptionsCommand | ||
117 | live?: LiveCommand | ||
118 | services?: ServicesCommand | ||
119 | blacklist?: BlacklistCommand | ||
120 | captions?: CaptionsCommand | ||
121 | changeOwnership?: ChangeOwnershipCommand | ||
122 | playlists?: PlaylistsCommand | ||
123 | history?: HistoryCommand | ||
124 | imports?: ImportsCommand | ||
125 | streamingPlaylists?: StreamingPlaylistsCommand | ||
126 | channels?: ChannelsCommand | ||
127 | comments?: CommentsCommand | ||
128 | sql?: SQLCommand | ||
129 | notifications?: NotificationsCommand | ||
130 | servers?: ServersCommand | ||
131 | login?: LoginCommand | ||
132 | users?: UsersCommand | ||
133 | videos?: VideosCommand | ||
134 | |||
135 | constructor (options: { serverNumber: number } | { url: string }) { | ||
136 | if ((options as any).url) { | ||
137 | this.setUrl((options as any).url) | ||
138 | } else { | ||
139 | this.setServerNumber((options as any).serverNumber) | ||
140 | } | ||
141 | |||
142 | this.store = { | ||
143 | client: { | ||
144 | id: null, | ||
145 | secret: null | ||
146 | }, | ||
147 | user: { | ||
148 | username: null, | ||
149 | password: null | ||
150 | } | ||
151 | } | ||
152 | |||
153 | this.assignCommands() | ||
154 | } | ||
155 | |||
156 | setServerNumber (serverNumber: number) { | ||
157 | this.serverNumber = serverNumber | ||
158 | |||
159 | this.parallel = parallelTests() | ||
160 | |||
161 | this.internalServerNumber = this.parallel ? this.randomServer() : this.serverNumber | ||
162 | this.rtmpPort = this.parallel ? this.randomRTMP() : 1936 | ||
163 | this.port = 9000 + this.internalServerNumber | ||
164 | |||
165 | this.url = `http://localhost:${this.port}` | ||
166 | this.host = `localhost:${this.port}` | ||
167 | this.hostname = 'localhost' | ||
168 | } | ||
169 | |||
170 | setUrl (url: string) { | ||
171 | const parsed = new URL(url) | ||
172 | |||
173 | this.url = url | ||
174 | this.host = parsed.host | ||
175 | this.hostname = parsed.hostname | ||
176 | this.port = parseInt(parsed.port) | ||
177 | } | ||
178 | |||
179 | async flushAndRun (configOverride?: Object, args = [], options: RunServerOptions = {}) { | ||
180 | await ServersCommand.flushTests(this.internalServerNumber) | ||
181 | |||
182 | return this.run(configOverride, args, options) | ||
183 | } | ||
184 | |||
185 | async run (configOverrideArg?: any, args = [], options: RunServerOptions = {}) { | ||
186 | // These actions are async so we need to be sure that they have both been done | ||
187 | const serverRunString = { | ||
188 | 'HTTP server listening': false | ||
189 | } | ||
190 | const key = 'Database peertube_test' + this.internalServerNumber + ' is ready' | ||
191 | serverRunString[key] = false | ||
192 | |||
193 | const regexps = { | ||
194 | client_id: 'Client id: (.+)', | ||
195 | client_secret: 'Client secret: (.+)', | ||
196 | user_username: 'Username: (.+)', | ||
197 | user_password: 'User password: (.+)' | ||
198 | } | ||
199 | |||
200 | await this.assignCustomConfigFile() | ||
201 | |||
202 | const configOverride = this.buildConfigOverride() | ||
203 | |||
204 | if (configOverrideArg !== undefined) { | ||
205 | Object.assign(configOverride, configOverrideArg) | ||
206 | } | ||
207 | |||
208 | // Share the environment | ||
209 | const env = Object.create(process.env) | ||
210 | env['NODE_ENV'] = 'test' | ||
211 | env['NODE_APP_INSTANCE'] = this.internalServerNumber.toString() | ||
212 | env['NODE_CONFIG'] = JSON.stringify(configOverride) | ||
213 | |||
214 | const forkOptions = { | ||
215 | silent: true, | ||
216 | env, | ||
217 | detached: true, | ||
218 | execArgv: options.execArgv || [] | ||
219 | } | ||
220 | |||
221 | return new Promise<void>(res => { | ||
222 | this.app = fork(join(root(), 'dist', 'server.js'), args, forkOptions) | ||
223 | this.app.stdout.on('data', function onStdout (data) { | ||
224 | let dontContinue = false | ||
225 | |||
226 | // Capture things if we want to | ||
227 | for (const key of Object.keys(regexps)) { | ||
228 | const regexp = regexps[key] | ||
229 | const matches = data.toString().match(regexp) | ||
230 | if (matches !== null) { | ||
231 | if (key === 'client_id') this.store.client.id = matches[1] | ||
232 | else if (key === 'client_secret') this.store.client.secret = matches[1] | ||
233 | else if (key === 'user_username') this.store.user.username = matches[1] | ||
234 | else if (key === 'user_password') this.store.user.password = matches[1] | ||
235 | } | ||
236 | } | ||
237 | |||
238 | // Check if all required sentences are here | ||
239 | for (const key of Object.keys(serverRunString)) { | ||
240 | if (data.toString().indexOf(key) !== -1) serverRunString[key] = true | ||
241 | if (serverRunString[key] === false) dontContinue = true | ||
242 | } | ||
243 | |||
244 | // If no, there is maybe one thing not already initialized (client/user credentials generation...) | ||
245 | if (dontContinue === true) return | ||
246 | |||
247 | if (options.hideLogs === false) { | ||
248 | console.log(data.toString()) | ||
249 | } else { | ||
250 | this.app.stdout.removeListener('data', onStdout) | ||
251 | } | ||
252 | |||
253 | process.on('exit', () => { | ||
254 | try { | ||
255 | process.kill(this.server.app.pid) | ||
256 | } catch { /* empty */ } | ||
257 | }) | ||
258 | |||
259 | res() | ||
260 | }) | ||
261 | }) | ||
262 | } | ||
263 | |||
264 | async kill () { | ||
265 | if (!this.app) return | ||
266 | |||
267 | await this.sql.cleanup() | ||
268 | |||
269 | process.kill(-this.app.pid) | ||
270 | |||
271 | this.app = null | ||
272 | } | ||
273 | |||
274 | private randomServer () { | ||
275 | const low = 10 | ||
276 | const high = 10000 | ||
277 | |||
278 | return randomInt(low, high) | ||
279 | } | ||
280 | |||
281 | private randomRTMP () { | ||
282 | const low = 1900 | ||
283 | const high = 2100 | ||
284 | |||
285 | return randomInt(low, high) | ||
286 | } | ||
287 | |||
288 | private async assignCustomConfigFile () { | ||
289 | if (this.internalServerNumber === this.serverNumber) return | ||
290 | |||
291 | const basePath = join(root(), 'config') | ||
292 | |||
293 | const tmpConfigFile = join(basePath, `test-${this.internalServerNumber}.yaml`) | ||
294 | await copy(join(basePath, `test-${this.serverNumber}.yaml`), tmpConfigFile) | ||
295 | |||
296 | this.customConfigFile = tmpConfigFile | ||
297 | } | ||
298 | |||
299 | private buildConfigOverride () { | ||
300 | if (!this.parallel) return {} | ||
301 | |||
302 | return { | ||
303 | listen: { | ||
304 | port: this.port | ||
305 | }, | ||
306 | webserver: { | ||
307 | port: this.port | ||
308 | }, | ||
309 | database: { | ||
310 | suffix: '_test' + this.internalServerNumber | ||
311 | }, | ||
312 | storage: { | ||
313 | tmp: `test${this.internalServerNumber}/tmp/`, | ||
314 | avatars: `test${this.internalServerNumber}/avatars/`, | ||
315 | videos: `test${this.internalServerNumber}/videos/`, | ||
316 | streaming_playlists: `test${this.internalServerNumber}/streaming-playlists/`, | ||
317 | redundancy: `test${this.internalServerNumber}/redundancy/`, | ||
318 | logs: `test${this.internalServerNumber}/logs/`, | ||
319 | previews: `test${this.internalServerNumber}/previews/`, | ||
320 | thumbnails: `test${this.internalServerNumber}/thumbnails/`, | ||
321 | torrents: `test${this.internalServerNumber}/torrents/`, | ||
322 | captions: `test${this.internalServerNumber}/captions/`, | ||
323 | cache: `test${this.internalServerNumber}/cache/`, | ||
324 | plugins: `test${this.internalServerNumber}/plugins/` | ||
325 | }, | ||
326 | admin: { | ||
327 | email: `admin${this.internalServerNumber}@example.com` | ||
328 | }, | ||
329 | live: { | ||
330 | rtmp: { | ||
331 | port: this.rtmpPort | ||
332 | } | ||
333 | } | ||
334 | } | ||
335 | } | ||
336 | |||
337 | private assignCommands () { | ||
338 | this.bulk = new BulkCommand(this) | ||
339 | this.cli = new CLICommand(this) | ||
340 | this.customPage = new CustomPagesCommand(this) | ||
341 | this.feed = new FeedCommand(this) | ||
342 | this.logs = new LogsCommand(this) | ||
343 | this.abuses = new AbusesCommand(this) | ||
344 | this.overviews = new OverviewsCommand(this) | ||
345 | this.search = new SearchCommand(this) | ||
346 | this.contactForm = new ContactFormCommand(this) | ||
347 | this.debug = new DebugCommand(this) | ||
348 | this.follows = new FollowsCommand(this) | ||
349 | this.jobs = new JobsCommand(this) | ||
350 | this.plugins = new PluginsCommand(this) | ||
351 | this.redundancy = new RedundancyCommand(this) | ||
352 | this.stats = new StatsCommand(this) | ||
353 | this.config = new ConfigCommand(this) | ||
354 | this.socketIO = new SocketIOCommand(this) | ||
355 | this.accounts = new AccountsCommand(this) | ||
356 | this.blocklist = new BlocklistCommand(this) | ||
357 | this.subscriptions = new SubscriptionsCommand(this) | ||
358 | this.live = new LiveCommand(this) | ||
359 | this.services = new ServicesCommand(this) | ||
360 | this.blacklist = new BlacklistCommand(this) | ||
361 | this.captions = new CaptionsCommand(this) | ||
362 | this.changeOwnership = new ChangeOwnershipCommand(this) | ||
363 | this.playlists = new PlaylistsCommand(this) | ||
364 | this.history = new HistoryCommand(this) | ||
365 | this.imports = new ImportsCommand(this) | ||
366 | this.streamingPlaylists = new StreamingPlaylistsCommand(this) | ||
367 | this.channels = new ChannelsCommand(this) | ||
368 | this.comments = new CommentsCommand(this) | ||
369 | this.sql = new SQLCommand(this) | ||
370 | this.notifications = new NotificationsCommand(this) | ||
371 | this.servers = new ServersCommand(this) | ||
372 | this.login = new LoginCommand(this) | ||
373 | this.users = new UsersCommand(this) | ||
374 | this.videos = new VideosCommand(this) | ||
375 | } | ||
376 | } | ||
diff --git a/shared/extra-utils/server/servers-command.ts b/shared/extra-utils/server/servers-command.ts index a7c5a868d..1a7b2aade 100644 --- a/shared/extra-utils/server/servers-command.ts +++ b/shared/extra-utils/server/servers-command.ts | |||
@@ -37,7 +37,7 @@ export class ServersCommand extends AbstractCommand { | |||
37 | if (isGithubCI()) { | 37 | if (isGithubCI()) { |
38 | await ensureDir('artifacts') | 38 | await ensureDir('artifacts') |
39 | 39 | ||
40 | const origin = this.server.servers.buildDirectory('logs/peertube.log') | 40 | const origin = this.buildDirectory('logs/peertube.log') |
41 | const destname = `peertube-${this.server.internalServerNumber}.log` | 41 | const destname = `peertube-${this.server.internalServerNumber}.log` |
42 | console.log('Saving logs %s.', destname) | 42 | console.log('Saving logs %s.', destname) |
43 | 43 | ||
diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index ea3f19a92..87d7e9449 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts | |||
@@ -1,391 +1,30 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/no-floating-promises */ | 1 | import { ensureDir } from 'fs-extra' |
2 | import { isGithubCI } from '../miscs' | ||
3 | import { PeerTubeServer, RunServerOptions } from './server' | ||
2 | 4 | ||
3 | import { ChildProcess, fork } from 'child_process' | 5 | async function createSingleServer (serverNumber: number, configOverride?: Object, args = [], options: RunServerOptions = {}) { |
4 | import { copy, ensureDir } from 'fs-extra' | 6 | const server = new PeerTubeServer({ serverNumber }) |
5 | import { join } from 'path' | ||
6 | import { root } from '@server/helpers/core-utils' | ||
7 | import { randomInt } from '../../core-utils/miscs/miscs' | ||
8 | import { VideoChannel } from '../../models/videos' | ||
9 | import { BulkCommand } from '../bulk' | ||
10 | import { CLICommand } from '../cli' | ||
11 | import { CustomPagesCommand } from '../custom-pages' | ||
12 | import { FeedCommand } from '../feeds' | ||
13 | import { LogsCommand } from '../logs' | ||
14 | import { isGithubCI, parallelTests, SQLCommand } from '../miscs' | ||
15 | import { AbusesCommand } from '../moderation' | ||
16 | import { OverviewsCommand } from '../overviews' | ||
17 | import { SearchCommand } from '../search' | ||
18 | import { SocketIOCommand } from '../socket' | ||
19 | import { AccountsCommand, BlocklistCommand, LoginCommand, NotificationsCommand, SubscriptionsCommand, UsersCommand } from '../users' | ||
20 | import { | ||
21 | BlacklistCommand, | ||
22 | CaptionsCommand, | ||
23 | ChangeOwnershipCommand, | ||
24 | ChannelsCommand, | ||
25 | HistoryCommand, | ||
26 | ImportsCommand, | ||
27 | LiveCommand, | ||
28 | PlaylistsCommand, | ||
29 | ServicesCommand, | ||
30 | StreamingPlaylistsCommand, | ||
31 | VideosCommand | ||
32 | } from '../videos' | ||
33 | import { CommentsCommand } from '../videos/comments-command' | ||
34 | import { ConfigCommand } from './config-command' | ||
35 | import { ContactFormCommand } from './contact-form-command' | ||
36 | import { DebugCommand } from './debug-command' | ||
37 | import { FollowsCommand } from './follows-command' | ||
38 | import { JobsCommand } from './jobs-command' | ||
39 | import { PluginsCommand } from './plugins-command' | ||
40 | import { RedundancyCommand } from './redundancy-command' | ||
41 | import { ServersCommand } from './servers-command' | ||
42 | import { StatsCommand } from './stats-command' | ||
43 | 7 | ||
44 | interface ServerInfo { | 8 | await server.flushAndRun(configOverride, args, options) |
45 | app?: ChildProcess | ||
46 | 9 | ||
47 | url: string | 10 | return server |
48 | host?: string | ||
49 | hostname?: string | ||
50 | port?: number | ||
51 | |||
52 | rtmpPort?: number | ||
53 | |||
54 | parallel?: boolean | ||
55 | internalServerNumber: number | ||
56 | |||
57 | serverNumber?: number | ||
58 | customConfigFile?: string | ||
59 | |||
60 | store?: { | ||
61 | client?: { | ||
62 | id?: string | ||
63 | secret?: string | ||
64 | } | ||
65 | |||
66 | user?: { | ||
67 | username: string | ||
68 | password: string | ||
69 | email?: string | ||
70 | } | ||
71 | |||
72 | channel?: VideoChannel | ||
73 | |||
74 | video?: { | ||
75 | id: number | ||
76 | uuid: string | ||
77 | shortUUID: string | ||
78 | name?: string | ||
79 | url?: string | ||
80 | |||
81 | account?: { | ||
82 | name: string | ||
83 | } | ||
84 | |||
85 | embedPath?: string | ||
86 | } | ||
87 | |||
88 | videos?: { id: number, uuid: string }[] | ||
89 | } | ||
90 | |||
91 | accessToken?: string | ||
92 | refreshToken?: string | ||
93 | |||
94 | bulk?: BulkCommand | ||
95 | cli?: CLICommand | ||
96 | customPage?: CustomPagesCommand | ||
97 | feed?: FeedCommand | ||
98 | logs?: LogsCommand | ||
99 | abuses?: AbusesCommand | ||
100 | overviews?: OverviewsCommand | ||
101 | search?: SearchCommand | ||
102 | contactForm?: ContactFormCommand | ||
103 | debug?: DebugCommand | ||
104 | follows?: FollowsCommand | ||
105 | jobs?: JobsCommand | ||
106 | plugins?: PluginsCommand | ||
107 | redundancy?: RedundancyCommand | ||
108 | stats?: StatsCommand | ||
109 | config?: ConfigCommand | ||
110 | socketIO?: SocketIOCommand | ||
111 | accounts?: AccountsCommand | ||
112 | blocklist?: BlocklistCommand | ||
113 | subscriptions?: SubscriptionsCommand | ||
114 | live?: LiveCommand | ||
115 | services?: ServicesCommand | ||
116 | blacklist?: BlacklistCommand | ||
117 | captions?: CaptionsCommand | ||
118 | changeOwnership?: ChangeOwnershipCommand | ||
119 | playlists?: PlaylistsCommand | ||
120 | history?: HistoryCommand | ||
121 | imports?: ImportsCommand | ||
122 | streamingPlaylists?: StreamingPlaylistsCommand | ||
123 | channels?: ChannelsCommand | ||
124 | comments?: CommentsCommand | ||
125 | sql?: SQLCommand | ||
126 | notifications?: NotificationsCommand | ||
127 | servers?: ServersCommand | ||
128 | login?: LoginCommand | ||
129 | users?: UsersCommand | ||
130 | videos?: VideosCommand | ||
131 | } | ||
132 | |||
133 | function flushAndRunMultipleServers (totalServers: number, configOverride?: Object) { | ||
134 | const apps = [] | ||
135 | let i = 0 | ||
136 | |||
137 | return new Promise<ServerInfo[]>(res => { | ||
138 | function anotherServerDone (serverNumber, app) { | ||
139 | apps[serverNumber - 1] = app | ||
140 | i++ | ||
141 | if (i === totalServers) { | ||
142 | return res(apps) | ||
143 | } | ||
144 | } | ||
145 | |||
146 | for (let j = 1; j <= totalServers; j++) { | ||
147 | flushAndRunServer(j, configOverride).then(app => anotherServerDone(j, app)) | ||
148 | } | ||
149 | }) | ||
150 | } | ||
151 | |||
152 | function randomServer () { | ||
153 | const low = 10 | ||
154 | const high = 10000 | ||
155 | |||
156 | return randomInt(low, high) | ||
157 | } | ||
158 | |||
159 | function randomRTMP () { | ||
160 | const low = 1900 | ||
161 | const high = 2100 | ||
162 | |||
163 | return randomInt(low, high) | ||
164 | } | ||
165 | |||
166 | type RunServerOptions = { | ||
167 | hideLogs?: boolean | ||
168 | execArgv?: string[] | ||
169 | } | ||
170 | |||
171 | async function flushAndRunServer (serverNumber: number, configOverride?: Object, args = [], options: RunServerOptions = {}) { | ||
172 | const parallel = parallelTests() | ||
173 | |||
174 | const internalServerNumber = parallel ? randomServer() : serverNumber | ||
175 | const rtmpPort = parallel ? randomRTMP() : 1936 | ||
176 | const port = 9000 + internalServerNumber | ||
177 | |||
178 | await ServersCommand.flushTests(internalServerNumber) | ||
179 | |||
180 | const server: ServerInfo = { | ||
181 | app: null, | ||
182 | port, | ||
183 | internalServerNumber, | ||
184 | rtmpPort, | ||
185 | parallel, | ||
186 | serverNumber, | ||
187 | url: `http://localhost:${port}`, | ||
188 | host: `localhost:${port}`, | ||
189 | hostname: 'localhost', | ||
190 | store: { | ||
191 | client: { | ||
192 | id: null, | ||
193 | secret: null | ||
194 | }, | ||
195 | user: { | ||
196 | username: null, | ||
197 | password: null | ||
198 | } | ||
199 | } | ||
200 | } | ||
201 | |||
202 | return runServer(server, configOverride, args, options) | ||
203 | } | 11 | } |
204 | 12 | ||
205 | async function runServer (server: ServerInfo, configOverrideArg?: any, args = [], options: RunServerOptions = {}) { | 13 | function createMultipleServers (totalServers: number, configOverride?: Object) { |
206 | // These actions are async so we need to be sure that they have both been done | 14 | const serverPromises: Promise<PeerTubeServer>[] = [] |
207 | const serverRunString = { | ||
208 | 'HTTP server listening': false | ||
209 | } | ||
210 | const key = 'Database peertube_test' + server.internalServerNumber + ' is ready' | ||
211 | serverRunString[key] = false | ||
212 | |||
213 | const regexps = { | ||
214 | client_id: 'Client id: (.+)', | ||
215 | client_secret: 'Client secret: (.+)', | ||
216 | user_username: 'Username: (.+)', | ||
217 | user_password: 'User password: (.+)' | ||
218 | } | ||
219 | |||
220 | if (server.internalServerNumber !== server.serverNumber) { | ||
221 | const basePath = join(root(), 'config') | ||
222 | |||
223 | const tmpConfigFile = join(basePath, `test-${server.internalServerNumber}.yaml`) | ||
224 | await copy(join(basePath, `test-${server.serverNumber}.yaml`), tmpConfigFile) | ||
225 | |||
226 | server.customConfigFile = tmpConfigFile | ||
227 | } | ||
228 | |||
229 | const configOverride: any = {} | ||
230 | |||
231 | if (server.parallel) { | ||
232 | Object.assign(configOverride, { | ||
233 | listen: { | ||
234 | port: server.port | ||
235 | }, | ||
236 | webserver: { | ||
237 | port: server.port | ||
238 | }, | ||
239 | database: { | ||
240 | suffix: '_test' + server.internalServerNumber | ||
241 | }, | ||
242 | storage: { | ||
243 | tmp: `test${server.internalServerNumber}/tmp/`, | ||
244 | avatars: `test${server.internalServerNumber}/avatars/`, | ||
245 | videos: `test${server.internalServerNumber}/videos/`, | ||
246 | streaming_playlists: `test${server.internalServerNumber}/streaming-playlists/`, | ||
247 | redundancy: `test${server.internalServerNumber}/redundancy/`, | ||
248 | logs: `test${server.internalServerNumber}/logs/`, | ||
249 | previews: `test${server.internalServerNumber}/previews/`, | ||
250 | thumbnails: `test${server.internalServerNumber}/thumbnails/`, | ||
251 | torrents: `test${server.internalServerNumber}/torrents/`, | ||
252 | captions: `test${server.internalServerNumber}/captions/`, | ||
253 | cache: `test${server.internalServerNumber}/cache/`, | ||
254 | plugins: `test${server.internalServerNumber}/plugins/` | ||
255 | }, | ||
256 | admin: { | ||
257 | email: `admin${server.internalServerNumber}@example.com` | ||
258 | }, | ||
259 | live: { | ||
260 | rtmp: { | ||
261 | port: server.rtmpPort | ||
262 | } | ||
263 | } | ||
264 | }) | ||
265 | } | ||
266 | |||
267 | if (configOverrideArg !== undefined) { | ||
268 | Object.assign(configOverride, configOverrideArg) | ||
269 | } | ||
270 | |||
271 | // Share the environment | ||
272 | const env = Object.create(process.env) | ||
273 | env['NODE_ENV'] = 'test' | ||
274 | env['NODE_APP_INSTANCE'] = server.internalServerNumber.toString() | ||
275 | env['NODE_CONFIG'] = JSON.stringify(configOverride) | ||
276 | 15 | ||
277 | const forkOptions = { | 16 | for (let i = 1; i <= totalServers; i++) { |
278 | silent: true, | 17 | serverPromises.push(createSingleServer(i, configOverride)) |
279 | env, | ||
280 | detached: true, | ||
281 | execArgv: options.execArgv || [] | ||
282 | } | 18 | } |
283 | 19 | ||
284 | return new Promise<ServerInfo>(res => { | 20 | return Promise.all(serverPromises) |
285 | server.app = fork(join(root(), 'dist', 'server.js'), args, forkOptions) | ||
286 | server.app.stdout.on('data', function onStdout (data) { | ||
287 | let dontContinue = false | ||
288 | |||
289 | // Capture things if we want to | ||
290 | for (const key of Object.keys(regexps)) { | ||
291 | const regexp = regexps[key] | ||
292 | const matches = data.toString().match(regexp) | ||
293 | if (matches !== null) { | ||
294 | if (key === 'client_id') server.store.client.id = matches[1] | ||
295 | else if (key === 'client_secret') server.store.client.secret = matches[1] | ||
296 | else if (key === 'user_username') server.store.user.username = matches[1] | ||
297 | else if (key === 'user_password') server.store.user.password = matches[1] | ||
298 | } | ||
299 | } | ||
300 | |||
301 | // Check if all required sentences are here | ||
302 | for (const key of Object.keys(serverRunString)) { | ||
303 | if (data.toString().indexOf(key) !== -1) serverRunString[key] = true | ||
304 | if (serverRunString[key] === false) dontContinue = true | ||
305 | } | ||
306 | |||
307 | // If no, there is maybe one thing not already initialized (client/user credentials generation...) | ||
308 | if (dontContinue === true) return | ||
309 | |||
310 | if (options.hideLogs === false) { | ||
311 | console.log(data.toString()) | ||
312 | } else { | ||
313 | server.app.stdout.removeListener('data', onStdout) | ||
314 | } | ||
315 | |||
316 | process.on('exit', () => { | ||
317 | try { | ||
318 | process.kill(server.app.pid) | ||
319 | } catch { /* empty */ } | ||
320 | }) | ||
321 | |||
322 | assignCommands(server) | ||
323 | |||
324 | res(server) | ||
325 | }) | ||
326 | }) | ||
327 | } | ||
328 | |||
329 | function assignCommands (server: ServerInfo) { | ||
330 | server.bulk = new BulkCommand(server) | ||
331 | server.cli = new CLICommand(server) | ||
332 | server.customPage = new CustomPagesCommand(server) | ||
333 | server.feed = new FeedCommand(server) | ||
334 | server.logs = new LogsCommand(server) | ||
335 | server.abuses = new AbusesCommand(server) | ||
336 | server.overviews = new OverviewsCommand(server) | ||
337 | server.search = new SearchCommand(server) | ||
338 | server.contactForm = new ContactFormCommand(server) | ||
339 | server.debug = new DebugCommand(server) | ||
340 | server.follows = new FollowsCommand(server) | ||
341 | server.jobs = new JobsCommand(server) | ||
342 | server.plugins = new PluginsCommand(server) | ||
343 | server.redundancy = new RedundancyCommand(server) | ||
344 | server.stats = new StatsCommand(server) | ||
345 | server.config = new ConfigCommand(server) | ||
346 | server.socketIO = new SocketIOCommand(server) | ||
347 | server.accounts = new AccountsCommand(server) | ||
348 | server.blocklist = new BlocklistCommand(server) | ||
349 | server.subscriptions = new SubscriptionsCommand(server) | ||
350 | server.live = new LiveCommand(server) | ||
351 | server.services = new ServicesCommand(server) | ||
352 | server.blacklist = new BlacklistCommand(server) | ||
353 | server.captions = new CaptionsCommand(server) | ||
354 | server.changeOwnership = new ChangeOwnershipCommand(server) | ||
355 | server.playlists = new PlaylistsCommand(server) | ||
356 | server.history = new HistoryCommand(server) | ||
357 | server.imports = new ImportsCommand(server) | ||
358 | server.streamingPlaylists = new StreamingPlaylistsCommand(server) | ||
359 | server.channels = new ChannelsCommand(server) | ||
360 | server.comments = new CommentsCommand(server) | ||
361 | server.sql = new SQLCommand(server) | ||
362 | server.notifications = new NotificationsCommand(server) | ||
363 | server.servers = new ServersCommand(server) | ||
364 | server.login = new LoginCommand(server) | ||
365 | server.users = new UsersCommand(server) | ||
366 | server.videos = new VideosCommand(server) | ||
367 | } | ||
368 | |||
369 | async function reRunServer (server: ServerInfo, configOverride?: any) { | ||
370 | const newServer = await runServer(server, configOverride) | ||
371 | server.app = newServer.app | ||
372 | |||
373 | return server | ||
374 | } | 21 | } |
375 | 22 | ||
376 | async function killallServers (servers: ServerInfo[]) { | 23 | async function killallServers (servers: PeerTubeServer[]) { |
377 | for (const server of servers) { | 24 | return Promise.all(servers.map(s => s.kill())) |
378 | if (!server.app) continue | ||
379 | |||
380 | await server.sql.cleanup() | ||
381 | |||
382 | process.kill(-server.app.pid) | ||
383 | |||
384 | server.app = null | ||
385 | } | ||
386 | } | 25 | } |
387 | 26 | ||
388 | async function cleanupTests (servers: ServerInfo[]) { | 27 | async function cleanupTests (servers: PeerTubeServer[]) { |
389 | await killallServers(servers) | 28 | await killallServers(servers) |
390 | 29 | ||
391 | if (isGithubCI()) { | 30 | if (isGithubCI()) { |
@@ -403,11 +42,8 @@ async function cleanupTests (servers: ServerInfo[]) { | |||
403 | // --------------------------------------------------------------------------- | 42 | // --------------------------------------------------------------------------- |
404 | 43 | ||
405 | export { | 44 | export { |
406 | ServerInfo, | 45 | createSingleServer, |
46 | createMultipleServers, | ||
407 | cleanupTests, | 47 | cleanupTests, |
408 | flushAndRunMultipleServers, | 48 | killallServers |
409 | flushAndRunServer, | ||
410 | killallServers, | ||
411 | reRunServer, | ||
412 | assignCommands | ||
413 | } | 49 | } |
diff --git a/shared/extra-utils/shared/abstract-command.ts b/shared/extra-utils/shared/abstract-command.ts index 5fddcf639..967f8f2ac 100644 --- a/shared/extra-utils/shared/abstract-command.ts +++ b/shared/extra-utils/shared/abstract-command.ts | |||
@@ -9,7 +9,7 @@ import { | |||
9 | unwrapBody, | 9 | unwrapBody, |
10 | unwrapText | 10 | unwrapText |
11 | } from '../requests/requests' | 11 | } from '../requests/requests' |
12 | import { ServerInfo } from '../server/servers' | 12 | import { PeerTubeServer } from '../server/server' |
13 | 13 | ||
14 | export interface OverrideCommandOptions { | 14 | export interface OverrideCommandOptions { |
15 | token?: string | 15 | token?: string |
@@ -38,7 +38,7 @@ interface InternalGetCommandOptions extends InternalCommonCommandOptions { | |||
38 | abstract class AbstractCommand { | 38 | abstract class AbstractCommand { |
39 | 39 | ||
40 | constructor ( | 40 | constructor ( |
41 | protected server: ServerInfo | 41 | protected server: PeerTubeServer |
42 | ) { | 42 | ) { |
43 | 43 | ||
44 | } | 44 | } |
diff --git a/shared/extra-utils/users/accounts.ts b/shared/extra-utils/users/accounts.ts index 2c9a4b71c..9fc1bcfc4 100644 --- a/shared/extra-utils/users/accounts.ts +++ b/shared/extra-utils/users/accounts.ts | |||
@@ -4,10 +4,10 @@ import { expect } from 'chai' | |||
4 | import { pathExists, readdir } from 'fs-extra' | 4 | import { pathExists, readdir } from 'fs-extra' |
5 | import { join } from 'path' | 5 | import { join } from 'path' |
6 | import { root } from '@server/helpers/core-utils' | 6 | import { root } from '@server/helpers/core-utils' |
7 | import { ServerInfo } from '../server' | 7 | import { PeerTubeServer } from '../server' |
8 | 8 | ||
9 | async function expectAccountFollows (options: { | 9 | async function expectAccountFollows (options: { |
10 | server: ServerInfo | 10 | server: PeerTubeServer |
11 | handle: string | 11 | handle: string |
12 | followers: number | 12 | followers: number |
13 | following: number | 13 | following: number |
diff --git a/shared/extra-utils/users/login.ts b/shared/extra-utils/users/login.ts index d0c26a4f0..f1df027d3 100644 --- a/shared/extra-utils/users/login.ts +++ b/shared/extra-utils/users/login.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import { ServerInfo } from '../server/servers' | 1 | import { PeerTubeServer } from '../server/server' |
2 | 2 | ||
3 | function setAccessTokensToServers (servers: ServerInfo[]) { | 3 | function setAccessTokensToServers (servers: PeerTubeServer[]) { |
4 | const tasks: Promise<any>[] = [] | 4 | const tasks: Promise<any>[] = [] |
5 | 5 | ||
6 | for (const server of servers) { | 6 | for (const server of servers) { |
diff --git a/shared/extra-utils/users/notifications.ts b/shared/extra-utils/users/notifications.ts index 9196f0bf5..4c42fad3e 100644 --- a/shared/extra-utils/users/notifications.ts +++ b/shared/extra-utils/users/notifications.ts | |||
@@ -5,8 +5,9 @@ import { inspect } from 'util' | |||
5 | import { AbuseState, PluginType } from '@shared/models' | 5 | import { AbuseState, PluginType } from '@shared/models' |
6 | import { UserNotification, UserNotificationSetting, UserNotificationSettingValue, UserNotificationType } from '../../models/users' | 6 | import { UserNotification, UserNotificationSetting, UserNotificationSettingValue, UserNotificationType } from '../../models/users' |
7 | import { MockSmtpServer } from '../mock-servers/mock-email' | 7 | import { MockSmtpServer } from '../mock-servers/mock-email' |
8 | import { PeerTubeServer } from '../server' | ||
8 | import { doubleFollow } from '../server/follows' | 9 | import { doubleFollow } from '../server/follows' |
9 | import { flushAndRunMultipleServers, ServerInfo } from '../server/servers' | 10 | import { createMultipleServers } from '../server/servers' |
10 | import { setAccessTokensToServers } from './login' | 11 | import { setAccessTokensToServers } from './login' |
11 | 12 | ||
12 | function getAllNotificationsSettings (): UserNotificationSetting { | 13 | function getAllNotificationsSettings (): UserNotificationSetting { |
@@ -31,7 +32,7 @@ function getAllNotificationsSettings (): UserNotificationSetting { | |||
31 | } | 32 | } |
32 | 33 | ||
33 | type CheckerBaseParams = { | 34 | type CheckerBaseParams = { |
34 | server: ServerInfo | 35 | server: PeerTubeServer |
35 | emails: any[] | 36 | emails: any[] |
36 | socketNotifications: UserNotification[] | 37 | socketNotifications: UserNotification[] |
37 | token: string | 38 | token: string |
@@ -642,7 +643,7 @@ async function prepareNotificationsTest (serversCount = 3, overrideConfigArg: an | |||
642 | limit: 20 | 643 | limit: 20 |
643 | } | 644 | } |
644 | } | 645 | } |
645 | const servers = await flushAndRunMultipleServers(serversCount, Object.assign(overrideConfig, overrideConfigArg)) | 646 | const servers = await createMultipleServers(serversCount, Object.assign(overrideConfig, overrideConfigArg)) |
646 | 647 | ||
647 | await setAccessTokensToServers(servers) | 648 | await setAccessTokensToServers(servers) |
648 | 649 | ||
diff --git a/shared/extra-utils/videos/channels.ts b/shared/extra-utils/videos/channels.ts index 81e818094..756c47453 100644 --- a/shared/extra-utils/videos/channels.ts +++ b/shared/extra-utils/videos/channels.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import { ServerInfo } from '../server/servers' | 1 | import { PeerTubeServer } from '../server/server' |
2 | 2 | ||
3 | function setDefaultVideoChannel (servers: ServerInfo[]) { | 3 | function setDefaultVideoChannel (servers: PeerTubeServer[]) { |
4 | const tasks: Promise<any>[] = [] | 4 | const tasks: Promise<any>[] = [] |
5 | 5 | ||
6 | for (const server of servers) { | 6 | for (const server of servers) { |
diff --git a/shared/extra-utils/videos/live.ts b/shared/extra-utils/videos/live.ts index 353595811..502964b1a 100644 --- a/shared/extra-utils/videos/live.ts +++ b/shared/extra-utils/videos/live.ts | |||
@@ -5,7 +5,7 @@ import * as ffmpeg from 'fluent-ffmpeg' | |||
5 | import { pathExists, readdir } from 'fs-extra' | 5 | import { pathExists, readdir } from 'fs-extra' |
6 | import { join } from 'path' | 6 | import { join } from 'path' |
7 | import { buildAbsoluteFixturePath, wait } from '../miscs' | 7 | import { buildAbsoluteFixturePath, wait } from '../miscs' |
8 | import { ServerInfo } from '../server/servers' | 8 | import { PeerTubeServer } from '../server/server' |
9 | 9 | ||
10 | function sendRTMPStream (rtmpBaseUrl: string, streamKey: string, fixtureName = 'video_short.mp4') { | 10 | function sendRTMPStream (rtmpBaseUrl: string, streamKey: string, fixtureName = 'video_short.mp4') { |
11 | const fixture = buildAbsoluteFixturePath(fixtureName) | 11 | const fixture = buildAbsoluteFixturePath(fixtureName) |
@@ -70,13 +70,13 @@ async function stopFfmpeg (command: ffmpeg.FfmpegCommand) { | |||
70 | await wait(500) | 70 | await wait(500) |
71 | } | 71 | } |
72 | 72 | ||
73 | async function waitUntilLivePublishedOnAllServers (servers: ServerInfo[], videoId: string) { | 73 | async function waitUntilLivePublishedOnAllServers (servers: PeerTubeServer[], videoId: string) { |
74 | for (const server of servers) { | 74 | for (const server of servers) { |
75 | await server.live.waitUntilPublished({ videoId }) | 75 | await server.live.waitUntilPublished({ videoId }) |
76 | } | 76 | } |
77 | } | 77 | } |
78 | 78 | ||
79 | async function checkLiveCleanup (server: ServerInfo, videoUUID: string, resolutions: number[] = []) { | 79 | async function checkLiveCleanup (server: PeerTubeServer, videoUUID: string, resolutions: number[] = []) { |
80 | const basePath = server.servers.buildDirectory('streaming-playlists') | 80 | const basePath = server.servers.buildDirectory('streaming-playlists') |
81 | const hlsPath = join(basePath, 'hls', videoUUID) | 81 | const hlsPath = join(basePath, 'hls', videoUUID) |
82 | 82 | ||
diff --git a/shared/extra-utils/videos/streaming-playlists.ts b/shared/extra-utils/videos/streaming-playlists.ts index e8fd2f232..002ae08b2 100644 --- a/shared/extra-utils/videos/streaming-playlists.ts +++ b/shared/extra-utils/videos/streaming-playlists.ts | |||
@@ -2,10 +2,10 @@ import { expect } from 'chai' | |||
2 | import { sha256 } from '@server/helpers/core-utils' | 2 | import { sha256 } from '@server/helpers/core-utils' |
3 | import { HttpStatusCode } from '@shared/core-utils' | 3 | import { HttpStatusCode } from '@shared/core-utils' |
4 | import { VideoStreamingPlaylist } from '@shared/models' | 4 | import { VideoStreamingPlaylist } from '@shared/models' |
5 | import { ServerInfo } from '../server' | 5 | import { PeerTubeServer } from '../server' |
6 | 6 | ||
7 | async function checkSegmentHash (options: { | 7 | async function checkSegmentHash (options: { |
8 | server: ServerInfo | 8 | server: PeerTubeServer |
9 | baseUrlPlaylist: string | 9 | baseUrlPlaylist: string |
10 | baseUrlSegment: string | 10 | baseUrlSegment: string |
11 | videoUUID: string | 11 | videoUUID: string |
@@ -36,7 +36,7 @@ async function checkSegmentHash (options: { | |||
36 | } | 36 | } |
37 | 37 | ||
38 | async function checkLiveSegmentHash (options: { | 38 | async function checkLiveSegmentHash (options: { |
39 | server: ServerInfo | 39 | server: PeerTubeServer |
40 | baseUrlSegment: string | 40 | baseUrlSegment: string |
41 | videoUUID: string | 41 | videoUUID: string |
42 | segmentName: string | 42 | segmentName: string |
@@ -52,7 +52,7 @@ async function checkLiveSegmentHash (options: { | |||
52 | } | 52 | } |
53 | 53 | ||
54 | async function checkResolutionsInMasterPlaylist (options: { | 54 | async function checkResolutionsInMasterPlaylist (options: { |
55 | server: ServerInfo | 55 | server: PeerTubeServer |
56 | playlistUrl: string | 56 | playlistUrl: string |
57 | resolutions: number[] | 57 | resolutions: number[] |
58 | }) { | 58 | }) { |
diff --git a/shared/extra-utils/videos/videos-command.ts b/shared/extra-utils/videos/videos-command.ts index 5556cddf6..feef5a771 100644 --- a/shared/extra-utils/videos/videos-command.ts +++ b/shared/extra-utils/videos/videos-command.ts | |||
@@ -22,7 +22,7 @@ import { | |||
22 | } from '@shared/models' | 22 | } from '@shared/models' |
23 | import { buildAbsoluteFixturePath, wait } from '../miscs' | 23 | import { buildAbsoluteFixturePath, wait } from '../miscs' |
24 | import { unwrapBody } from '../requests' | 24 | import { unwrapBody } from '../requests' |
25 | import { ServerInfo, waitJobs } from '../server' | 25 | import { PeerTubeServer, waitJobs } from '../server' |
26 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | 26 | import { AbstractCommand, OverrideCommandOptions } from '../shared' |
27 | 27 | ||
28 | export type VideoEdit = Partial<Omit<VideoCreate, 'thumbnailfile' | 'previewfile'>> & { | 28 | export type VideoEdit = Partial<Omit<VideoCreate, 'thumbnailfile' | 'previewfile'>> & { |
@@ -33,7 +33,7 @@ export type VideoEdit = Partial<Omit<VideoCreate, 'thumbnailfile' | 'previewfile | |||
33 | 33 | ||
34 | export class VideosCommand extends AbstractCommand { | 34 | export class VideosCommand extends AbstractCommand { |
35 | 35 | ||
36 | constructor (server: ServerInfo) { | 36 | constructor (server: PeerTubeServer) { |
37 | super(server) | 37 | super(server) |
38 | 38 | ||
39 | loadLanguages() | 39 | loadLanguages() |
diff --git a/shared/extra-utils/videos/videos.ts b/shared/extra-utils/videos/videos.ts index 86f49384d..b41533808 100644 --- a/shared/extra-utils/videos/videos.ts +++ b/shared/extra-utils/videos/videos.ts | |||
@@ -9,12 +9,12 @@ import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } fr | |||
9 | import { dateIsValid, testImage, webtorrentAdd } from '../miscs' | 9 | import { dateIsValid, testImage, webtorrentAdd } from '../miscs' |
10 | import { makeRawRequest } from '../requests/requests' | 10 | import { makeRawRequest } from '../requests/requests' |
11 | import { waitJobs } from '../server' | 11 | import { waitJobs } from '../server' |
12 | import { ServerInfo } from '../server/servers' | 12 | import { PeerTubeServer } from '../server/server' |
13 | import { VideoEdit } from './videos-command' | 13 | import { VideoEdit } from './videos-command' |
14 | 14 | ||
15 | async function checkVideoFilesWereRemoved ( | 15 | async function checkVideoFilesWereRemoved ( |
16 | videoUUID: string, | 16 | videoUUID: string, |
17 | server: ServerInfo, | 17 | server: PeerTubeServer, |
18 | directories = [ | 18 | directories = [ |
19 | 'redundancy', | 19 | 'redundancy', |
20 | 'videos', | 20 | 'videos', |
@@ -40,7 +40,7 @@ async function checkVideoFilesWereRemoved ( | |||
40 | } | 40 | } |
41 | 41 | ||
42 | function checkUploadVideoParam ( | 42 | function checkUploadVideoParam ( |
43 | server: ServerInfo, | 43 | server: PeerTubeServer, |
44 | token: string, | 44 | token: string, |
45 | attributes: Partial<VideoEdit>, | 45 | attributes: Partial<VideoEdit>, |
46 | expectedStatus = HttpStatusCode.OK_200, | 46 | expectedStatus = HttpStatusCode.OK_200, |
@@ -52,7 +52,7 @@ function checkUploadVideoParam ( | |||
52 | } | 52 | } |
53 | 53 | ||
54 | async function completeVideoCheck ( | 54 | async function completeVideoCheck ( |
55 | server: ServerInfo, | 55 | server: PeerTubeServer, |
56 | video: any, | 56 | video: any, |
57 | attributes: { | 57 | attributes: { |
58 | name: string | 58 | name: string |
@@ -197,7 +197,7 @@ async function completeVideoCheck ( | |||
197 | 197 | ||
198 | // serverNumber starts from 1 | 198 | // serverNumber starts from 1 |
199 | async function uploadRandomVideoOnServers ( | 199 | async function uploadRandomVideoOnServers ( |
200 | servers: ServerInfo[], | 200 | servers: PeerTubeServer[], |
201 | serverNumber: number, | 201 | serverNumber: number, |
202 | additionalParams?: VideoEdit & { prefixName?: string } | 202 | additionalParams?: VideoEdit & { prefixName?: string } |
203 | ) { | 203 | ) { |