diff options
author | Chocobozzz <me@florianbigard.com> | 2020-11-24 15:22:56 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-11-25 10:07:51 +0100 |
commit | ca5c612bfdd225433bcc6ace01c8024df3f674ba (patch) | |
tree | 1b722cc346c9079c65338f0792ce7bcd2a20f8a0 /shared/extra-utils | |
parent | 5a547f69d5dc5867e253f7721513479c754b4f15 (diff) | |
download | PeerTube-ca5c612bfdd225433bcc6ace01c8024df3f674ba.tar.gz PeerTube-ca5c612bfdd225433bcc6ace01c8024df3f674ba.tar.zst PeerTube-ca5c612bfdd225433bcc6ace01c8024df3f674ba.zip |
Add live transcoding bit rate tests
Diffstat (limited to 'shared/extra-utils')
-rw-r--r-- | shared/extra-utils/miscs/miscs.ts | 8 | ||||
-rw-r--r-- | shared/extra-utils/server/plugins.ts | 12 | ||||
-rw-r--r-- | shared/extra-utils/server/servers.ts | 6 | ||||
-rw-r--r-- | shared/extra-utils/videos/live.ts | 10 | ||||
-rw-r--r-- | shared/extra-utils/videos/videos.ts | 15 |
5 files changed, 22 insertions, 29 deletions
diff --git a/shared/extra-utils/miscs/miscs.ts b/shared/extra-utils/miscs/miscs.ts index 3c8191ae8..429083fe9 100644 --- a/shared/extra-utils/miscs/miscs.ts +++ b/shared/extra-utils/miscs/miscs.ts | |||
@@ -1,11 +1,11 @@ | |||
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 * as chai from 'chai' | 3 | import * as chai from 'chai' |
4 | import * as ffmpeg from 'fluent-ffmpeg' | ||
5 | import { ensureDir, pathExists, readFile, stat } from 'fs-extra' | ||
4 | import { basename, dirname, isAbsolute, join, resolve } from 'path' | 6 | import { basename, dirname, isAbsolute, join, resolve } from 'path' |
5 | import * as request from 'supertest' | 7 | import * as request from 'supertest' |
6 | import * as WebTorrent from 'webtorrent' | 8 | import * as WebTorrent from 'webtorrent' |
7 | import { ensureDir, pathExists, readFile, stat } from 'fs-extra' | ||
8 | import * as ffmpeg from 'fluent-ffmpeg' | ||
9 | 9 | ||
10 | const expect = chai.expect | 10 | const expect = chai.expect |
11 | let webtorrent: WebTorrent.Instance | 11 | let webtorrent: WebTorrent.Instance |
@@ -44,8 +44,8 @@ function root () { | |||
44 | return root | 44 | return root |
45 | } | 45 | } |
46 | 46 | ||
47 | function buildServerDirectory (internalServerNumber: number, directory: string) { | 47 | function buildServerDirectory (server: { internalServerNumber: number }, directory: string) { |
48 | return join(root(), 'test' + internalServerNumber, directory) | 48 | return join(root(), 'test' + server.internalServerNumber, directory) |
49 | } | 49 | } |
50 | 50 | ||
51 | async function testImage (url: string, imageName: string, imagePath: string, extension = '.jpg') { | 51 | async function testImage (url: string, imageName: string, imagePath: string, extension = '.jpg') { |
diff --git a/shared/extra-utils/server/plugins.ts b/shared/extra-utils/server/plugins.ts index b6b5e3958..8f370f655 100644 --- a/shared/extra-utils/server/plugins.ts +++ b/shared/extra-utils/server/plugins.ts | |||
@@ -1,10 +1,10 @@ | |||
1 | import { makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests' | ||
2 | import { PluginType } from '../../models/plugins/plugin.type' | ||
3 | import { PeertubePluginIndexList } from '../../models/plugins/peertube-plugin-index-list.model' | ||
4 | import { readJSON, writeJSON } from 'fs-extra' | 1 | import { readJSON, writeJSON } from 'fs-extra' |
5 | import { ServerInfo } from './servers' | ||
6 | import { root } from '../miscs/miscs' | ||
7 | import { join } from 'path' | 2 | import { join } from 'path' |
3 | import { PeertubePluginIndexList } from '../../models/plugins/peertube-plugin-index-list.model' | ||
4 | import { PluginType } from '../../models/plugins/plugin.type' | ||
5 | import { buildServerDirectory, root } from '../miscs/miscs' | ||
6 | import { makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests' | ||
7 | import { ServerInfo } from './servers' | ||
8 | 8 | ||
9 | function listPlugins (parameters: { | 9 | function listPlugins (parameters: { |
10 | url: string | 10 | url: string |
@@ -216,7 +216,7 @@ function getPluginsCSS (url: string) { | |||
216 | } | 216 | } |
217 | 217 | ||
218 | function getPackageJSONPath (server: ServerInfo, npmName: string) { | 218 | function getPackageJSONPath (server: ServerInfo, npmName: string) { |
219 | return join(root(), 'test' + server.internalServerNumber, 'plugins', 'node_modules', npmName, 'package.json') | 219 | return buildServerDirectory(server, join('plugins', 'node_modules', npmName, 'package.json')) |
220 | } | 220 | } |
221 | 221 | ||
222 | function updatePluginPackageJSON (server: ServerInfo, npmName: string, json: any) { | 222 | function updatePluginPackageJSON (server: ServerInfo, npmName: string, json: any) { |
diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index 75e79cc41..1126a7d93 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts | |||
@@ -6,7 +6,7 @@ import { copy, pathExists, readdir, readFile, remove } from 'fs-extra' | |||
6 | import { join } from 'path' | 6 | import { join } from 'path' |
7 | import { randomInt } from '../../core-utils/miscs/miscs' | 7 | import { randomInt } from '../../core-utils/miscs/miscs' |
8 | import { VideoChannel } from '../../models/videos' | 8 | import { VideoChannel } from '../../models/videos' |
9 | import { getFileSize, root, wait } from '../miscs/miscs' | 9 | import { buildServerDirectory, getFileSize, root, wait } from '../miscs/miscs' |
10 | 10 | ||
11 | interface ServerInfo { | 11 | interface ServerInfo { |
12 | app: ChildProcess | 12 | app: ChildProcess |
@@ -309,7 +309,7 @@ function cleanupTests (servers: ServerInfo[]) { | |||
309 | } | 309 | } |
310 | 310 | ||
311 | async function waitUntilLog (server: ServerInfo, str: string, count = 1, strictCount = true) { | 311 | async function waitUntilLog (server: ServerInfo, str: string, count = 1, strictCount = true) { |
312 | const logfile = join(root(), 'test' + server.internalServerNumber, 'logs/peertube.log') | 312 | const logfile = buildServerDirectory(server, 'logs/peertube.log') |
313 | 313 | ||
314 | while (true) { | 314 | while (true) { |
315 | const buf = await readFile(logfile) | 315 | const buf = await readFile(logfile) |
@@ -323,7 +323,7 @@ async function waitUntilLog (server: ServerInfo, str: string, count = 1, strictC | |||
323 | } | 323 | } |
324 | 324 | ||
325 | async function getServerFileSize (server: ServerInfo, subPath: string) { | 325 | async function getServerFileSize (server: ServerInfo, subPath: string) { |
326 | const path = join(root(), 'test' + server.internalServerNumber, subPath) | 326 | const path = buildServerDirectory(server, subPath) |
327 | 327 | ||
328 | return getFileSize(path) | 328 | return getFileSize(path) |
329 | } | 329 | } |
diff --git a/shared/extra-utils/videos/live.ts b/shared/extra-utils/videos/live.ts index 4bfcc583e..85c83c5bb 100644 --- a/shared/extra-utils/videos/live.ts +++ b/shared/extra-utils/videos/live.ts | |||
@@ -53,15 +53,15 @@ function createLive (url: string, token: string, fields: LiveVideoCreate, status | |||
53 | }) | 53 | }) |
54 | } | 54 | } |
55 | 55 | ||
56 | async function sendRTMPStreamInVideo (url: string, token: string, videoId: number | string) { | 56 | async function sendRTMPStreamInVideo (url: string, token: string, videoId: number | string, fixtureName?: string) { |
57 | const res = await getLive(url, token, videoId) | 57 | const res = await getLive(url, token, videoId) |
58 | const videoLive = res.body as LiveVideo | 58 | const videoLive = res.body as LiveVideo |
59 | 59 | ||
60 | return sendRTMPStream(videoLive.rtmpUrl, videoLive.streamKey) | 60 | return sendRTMPStream(videoLive.rtmpUrl, videoLive.streamKey, fixtureName) |
61 | } | 61 | } |
62 | 62 | ||
63 | function sendRTMPStream (rtmpBaseUrl: string, streamKey: string) { | 63 | function sendRTMPStream (rtmpBaseUrl: string, streamKey: string, fixtureName = 'video_short.mp4') { |
64 | const fixture = buildAbsoluteFixturePath('video_short.mp4') | 64 | const fixture = buildAbsoluteFixturePath(fixtureName) |
65 | 65 | ||
66 | const command = ffmpeg(fixture) | 66 | const command = ffmpeg(fixture) |
67 | command.inputOption('-stream_loop -1') | 67 | command.inputOption('-stream_loop -1') |
@@ -140,7 +140,7 @@ async function waitUntilLiveStarts (url: string, token: string, videoId: number | |||
140 | } | 140 | } |
141 | 141 | ||
142 | async function checkLiveCleanup (server: ServerInfo, videoUUID: string, resolutions: number[] = []) { | 142 | async function checkLiveCleanup (server: ServerInfo, videoUUID: string, resolutions: number[] = []) { |
143 | const basePath = buildServerDirectory(server.internalServerNumber, 'streaming-playlists') | 143 | const basePath = buildServerDirectory(server, 'streaming-playlists') |
144 | const hlsPath = join(basePath, 'hls', videoUUID) | 144 | const hlsPath = join(basePath, 'hls', videoUUID) |
145 | 145 | ||
146 | if (resolutions.length === 0) { | 146 | if (resolutions.length === 0) { |
diff --git a/shared/extra-utils/videos/videos.ts b/shared/extra-utils/videos/videos.ts index 29a646541..2b8c55acb 100644 --- a/shared/extra-utils/videos/videos.ts +++ b/shared/extra-utils/videos/videos.ts | |||
@@ -9,15 +9,7 @@ import { v4 as uuidv4 } from 'uuid' | |||
9 | import validator from 'validator' | 9 | import validator from 'validator' |
10 | import { loadLanguages, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../server/initializers/constants' | 10 | import { loadLanguages, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../server/initializers/constants' |
11 | import { VideoDetails, VideoPrivacy } from '../../models/videos' | 11 | import { VideoDetails, VideoPrivacy } from '../../models/videos' |
12 | import { | 12 | import { buildAbsoluteFixturePath, buildServerDirectory, dateIsValid, immutableAssign, testImage, webtorrentAdd } from '../miscs/miscs' |
13 | buildAbsoluteFixturePath, | ||
14 | buildServerDirectory, | ||
15 | dateIsValid, | ||
16 | immutableAssign, | ||
17 | root, | ||
18 | testImage, | ||
19 | webtorrentAdd | ||
20 | } from '../miscs/miscs' | ||
21 | import { makeGetRequest, makePutBodyRequest, makeUploadRequest } from '../requests/requests' | 13 | import { makeGetRequest, makePutBodyRequest, makeUploadRequest } from '../requests/requests' |
22 | import { waitJobs } from '../server/jobs' | 14 | import { waitJobs } from '../server/jobs' |
23 | import { ServerInfo } from '../server/servers' | 15 | import { ServerInfo } from '../server/servers' |
@@ -335,7 +327,7 @@ async function checkVideoFilesWereRemoved ( | |||
335 | ] | 327 | ] |
336 | ) { | 328 | ) { |
337 | for (const directory of directories) { | 329 | for (const directory of directories) { |
338 | const directoryPath = buildServerDirectory(serverNumber, directory) | 330 | const directoryPath = buildServerDirectory({ internalServerNumber: serverNumber }, directory) |
339 | 331 | ||
340 | const directoryExists = await pathExists(directoryPath) | 332 | const directoryExists = await pathExists(directoryPath) |
341 | if (directoryExists === false) continue | 333 | if (directoryExists === false) continue |
@@ -489,7 +481,8 @@ function rateVideo (url: string, accessToken: string, id: number, rating: string | |||
489 | function parseTorrentVideo (server: ServerInfo, videoUUID: string, resolution: number) { | 481 | function parseTorrentVideo (server: ServerInfo, videoUUID: string, resolution: number) { |
490 | return new Promise<any>((res, rej) => { | 482 | return new Promise<any>((res, rej) => { |
491 | const torrentName = videoUUID + '-' + resolution + '.torrent' | 483 | const torrentName = videoUUID + '-' + resolution + '.torrent' |
492 | const torrentPath = join(root(), 'test' + server.internalServerNumber, 'torrents', torrentName) | 484 | const torrentPath = buildServerDirectory(server, join('torrents', torrentName)) |
485 | |||
493 | readFile(torrentPath, (err, data) => { | 486 | readFile(torrentPath, (err, data) => { |
494 | if (err) return rej(err) | 487 | if (err) return rej(err) |
495 | 488 | ||