diff options
author | Chocobozzz <me@florianbigard.com> | 2023-07-31 14:34:36 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2023-08-11 15:02:33 +0200 |
commit | 3a4992633ee62d5edfbb484d9c6bcb3cf158489d (patch) | |
tree | e4510b39bdac9c318fdb4b47018d08f15368b8f0 /server/tests/peertube-runner | |
parent | 04d1da5621d25d59bd5fa1543b725c497bf5d9a8 (diff) | |
download | PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.tar.gz PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.tar.zst PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.zip |
Migrate server to ESM
Sorry for the very big commit that may lead to git log issues and merge
conflicts, but it's a major step forward:
* Server can be faster at startup because imports() are async and we can
easily lazy import big modules
* Angular doesn't seem to support ES import (with .js extension), so we
had to correctly organize peertube into a monorepo:
* Use yarn workspace feature
* Use typescript reference projects for dependencies
* Shared projects have been moved into "packages", each one is now a
node module (with a dedicated package.json/tsconfig.json)
* server/tools have been moved into apps/ and is now a dedicated app
bundled and published on NPM so users don't have to build peertube
cli tools manually
* server/tests have been moved into packages/ so we don't compile
them every time we want to run the server
* Use isolatedModule option:
* Had to move from const enum to const
(https://www.typescriptlang.org/docs/handbook/enums.html#objects-vs-enums)
* Had to explictely specify "type" imports when used in decorators
* Prefer tsx (that uses esbuild under the hood) instead of ts-node to
load typescript files (tests with mocha or scripts):
* To reduce test complexity as esbuild doesn't support decorator
metadata, we only test server files that do not import server
models
* We still build tests files into js files for a faster CI
* Remove unmaintained peertube CLI import script
* Removed some barrels to speed up execution (less imports)
Diffstat (limited to 'server/tests/peertube-runner')
-rw-r--r-- | server/tests/peertube-runner/client-cli.ts | 70 | ||||
-rw-r--r-- | server/tests/peertube-runner/index.ts | 4 | ||||
-rw-r--r-- | server/tests/peertube-runner/live-transcoding.ts | 201 | ||||
-rw-r--r-- | server/tests/peertube-runner/studio-transcoding.ts | 124 | ||||
-rw-r--r-- | server/tests/peertube-runner/vod-transcoding.ts | 350 |
5 files changed, 0 insertions, 749 deletions
diff --git a/server/tests/peertube-runner/client-cli.ts b/server/tests/peertube-runner/client-cli.ts deleted file mode 100644 index 5cbdc4e77..000000000 --- a/server/tests/peertube-runner/client-cli.ts +++ /dev/null | |||
@@ -1,70 +0,0 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { expect } from 'chai' | ||
4 | import { PeerTubeRunnerProcess } from '@server/tests/shared' | ||
5 | import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel } from '@shared/server-commands' | ||
6 | |||
7 | describe('Test peertube-runner program client CLI', function () { | ||
8 | let server: PeerTubeServer | ||
9 | let peertubeRunner: PeerTubeRunnerProcess | ||
10 | |||
11 | before(async function () { | ||
12 | this.timeout(120_000) | ||
13 | |||
14 | server = await createSingleServer(1) | ||
15 | |||
16 | await setAccessTokensToServers([ server ]) | ||
17 | await setDefaultVideoChannel([ server ]) | ||
18 | |||
19 | await server.config.enableRemoteTranscoding() | ||
20 | |||
21 | peertubeRunner = new PeerTubeRunnerProcess(server) | ||
22 | await peertubeRunner.runServer() | ||
23 | }) | ||
24 | |||
25 | it('Should not have PeerTube instance listed', async function () { | ||
26 | const data = await peertubeRunner.listRegisteredPeerTubeInstances() | ||
27 | |||
28 | expect(data).to.not.contain(server.url) | ||
29 | }) | ||
30 | |||
31 | it('Should register a new PeerTube instance', async function () { | ||
32 | const registrationToken = await server.runnerRegistrationTokens.getFirstRegistrationToken() | ||
33 | |||
34 | await peertubeRunner.registerPeerTubeInstance({ | ||
35 | registrationToken, | ||
36 | runnerName: 'my super runner', | ||
37 | runnerDescription: 'super description' | ||
38 | }) | ||
39 | }) | ||
40 | |||
41 | it('Should list this new PeerTube instance', async function () { | ||
42 | const data = await peertubeRunner.listRegisteredPeerTubeInstances() | ||
43 | |||
44 | expect(data).to.contain(server.url) | ||
45 | expect(data).to.contain('my super runner') | ||
46 | expect(data).to.contain('super description') | ||
47 | }) | ||
48 | |||
49 | it('Should still have the configuration after a restart', async function () { | ||
50 | peertubeRunner.kill() | ||
51 | |||
52 | await peertubeRunner.runServer() | ||
53 | }) | ||
54 | |||
55 | it('Should unregister the PeerTube instance', async function () { | ||
56 | await peertubeRunner.unregisterPeerTubeInstance({ runnerName: 'my super runner' }) | ||
57 | }) | ||
58 | |||
59 | it('Should not have PeerTube instance listed', async function () { | ||
60 | const data = await peertubeRunner.listRegisteredPeerTubeInstances() | ||
61 | |||
62 | expect(data).to.not.contain(server.url) | ||
63 | }) | ||
64 | |||
65 | after(async function () { | ||
66 | peertubeRunner.kill() | ||
67 | |||
68 | await cleanupTests([ server ]) | ||
69 | }) | ||
70 | }) | ||
diff --git a/server/tests/peertube-runner/index.ts b/server/tests/peertube-runner/index.ts deleted file mode 100644 index 470316417..000000000 --- a/server/tests/peertube-runner/index.ts +++ /dev/null | |||
@@ -1,4 +0,0 @@ | |||
1 | export * from './client-cli' | ||
2 | export * from './live-transcoding' | ||
3 | export * from './studio-transcoding' | ||
4 | export * from './vod-transcoding' | ||
diff --git a/server/tests/peertube-runner/live-transcoding.ts b/server/tests/peertube-runner/live-transcoding.ts deleted file mode 100644 index 41b01f8d5..000000000 --- a/server/tests/peertube-runner/live-transcoding.ts +++ /dev/null | |||
@@ -1,201 +0,0 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | import { expect } from 'chai' | ||
3 | import { | ||
4 | checkPeerTubeRunnerCacheIsEmpty, | ||
5 | expectStartWith, | ||
6 | PeerTubeRunnerProcess, | ||
7 | SQLCommand, | ||
8 | testLiveVideoResolutions | ||
9 | } from '@server/tests/shared' | ||
10 | import { areMockObjectStorageTestsDisabled, wait } from '@shared/core-utils' | ||
11 | import { HttpStatusCode, VideoPrivacy } from '@shared/models' | ||
12 | import { | ||
13 | cleanupTests, | ||
14 | createMultipleServers, | ||
15 | doubleFollow, | ||
16 | findExternalSavedVideo, | ||
17 | makeRawRequest, | ||
18 | ObjectStorageCommand, | ||
19 | PeerTubeServer, | ||
20 | setAccessTokensToServers, | ||
21 | setDefaultVideoChannel, | ||
22 | stopFfmpeg, | ||
23 | waitJobs, | ||
24 | waitUntilLivePublishedOnAllServers, | ||
25 | waitUntilLiveWaitingOnAllServers | ||
26 | } from '@shared/server-commands' | ||
27 | |||
28 | describe('Test Live transcoding in peertube-runner program', function () { | ||
29 | let servers: PeerTubeServer[] = [] | ||
30 | let peertubeRunner: PeerTubeRunnerProcess | ||
31 | let sqlCommandServer1: SQLCommand | ||
32 | |||
33 | function runSuite (options: { | ||
34 | objectStorage?: ObjectStorageCommand | ||
35 | } = {}) { | ||
36 | const { objectStorage } = options | ||
37 | |||
38 | it('Should enable transcoding without additional resolutions', async function () { | ||
39 | this.timeout(120000) | ||
40 | |||
41 | const { video } = await servers[0].live.quickCreate({ permanentLive: true, saveReplay: false, privacy: VideoPrivacy.PUBLIC }) | ||
42 | |||
43 | const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: video.uuid }) | ||
44 | await waitUntilLivePublishedOnAllServers(servers, video.uuid) | ||
45 | await waitJobs(servers) | ||
46 | |||
47 | await testLiveVideoResolutions({ | ||
48 | originServer: servers[0], | ||
49 | sqlCommand: sqlCommandServer1, | ||
50 | servers, | ||
51 | liveVideoId: video.uuid, | ||
52 | resolutions: [ 720, 480, 360, 240, 144 ], | ||
53 | objectStorage, | ||
54 | transcoded: true | ||
55 | }) | ||
56 | |||
57 | await stopFfmpeg(ffmpegCommand) | ||
58 | |||
59 | await waitUntilLiveWaitingOnAllServers(servers, video.uuid) | ||
60 | await servers[0].videos.remove({ id: video.id }) | ||
61 | }) | ||
62 | |||
63 | it('Should transcode audio only RTMP stream', async function () { | ||
64 | this.timeout(120000) | ||
65 | |||
66 | const { video } = await servers[0].live.quickCreate({ permanentLive: true, saveReplay: false, privacy: VideoPrivacy.UNLISTED }) | ||
67 | |||
68 | const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: video.uuid, fixtureName: 'video_short_no_audio.mp4' }) | ||
69 | await waitUntilLivePublishedOnAllServers(servers, video.uuid) | ||
70 | await waitJobs(servers) | ||
71 | |||
72 | await stopFfmpeg(ffmpegCommand) | ||
73 | |||
74 | await waitUntilLiveWaitingOnAllServers(servers, video.uuid) | ||
75 | await servers[0].videos.remove({ id: video.id }) | ||
76 | }) | ||
77 | |||
78 | it('Should save a replay', async function () { | ||
79 | this.timeout(240000) | ||
80 | |||
81 | const { video } = await servers[0].live.quickCreate({ permanentLive: true, saveReplay: true }) | ||
82 | |||
83 | const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: video.uuid }) | ||
84 | await waitUntilLivePublishedOnAllServers(servers, video.uuid) | ||
85 | |||
86 | await testLiveVideoResolutions({ | ||
87 | originServer: servers[0], | ||
88 | sqlCommand: sqlCommandServer1, | ||
89 | servers, | ||
90 | liveVideoId: video.uuid, | ||
91 | resolutions: [ 720, 480, 360, 240, 144 ], | ||
92 | objectStorage, | ||
93 | transcoded: true | ||
94 | }) | ||
95 | |||
96 | await stopFfmpeg(ffmpegCommand) | ||
97 | |||
98 | await waitUntilLiveWaitingOnAllServers(servers, video.uuid) | ||
99 | await waitJobs(servers) | ||
100 | |||
101 | const session = await servers[0].live.findLatestSession({ videoId: video.uuid }) | ||
102 | expect(session.endingProcessed).to.be.true | ||
103 | expect(session.endDate).to.exist | ||
104 | expect(session.saveReplay).to.be.true | ||
105 | |||
106 | const videoLiveDetails = await servers[0].videos.get({ id: video.uuid }) | ||
107 | const replay = await findExternalSavedVideo(servers[0], videoLiveDetails) | ||
108 | |||
109 | for (const server of servers) { | ||
110 | const video = await server.videos.get({ id: replay.uuid }) | ||
111 | |||
112 | expect(video.files).to.have.lengthOf(0) | ||
113 | expect(video.streamingPlaylists).to.have.lengthOf(1) | ||
114 | |||
115 | const files = video.streamingPlaylists[0].files | ||
116 | expect(files).to.have.lengthOf(5) | ||
117 | |||
118 | for (const file of files) { | ||
119 | if (objectStorage) { | ||
120 | expectStartWith(file.fileUrl, objectStorage.getMockPlaylistBaseUrl()) | ||
121 | } | ||
122 | |||
123 | await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 }) | ||
124 | } | ||
125 | } | ||
126 | }) | ||
127 | } | ||
128 | |||
129 | before(async function () { | ||
130 | this.timeout(120_000) | ||
131 | |||
132 | servers = await createMultipleServers(2) | ||
133 | |||
134 | await setAccessTokensToServers(servers) | ||
135 | await setDefaultVideoChannel(servers) | ||
136 | |||
137 | await doubleFollow(servers[0], servers[1]) | ||
138 | |||
139 | sqlCommandServer1 = new SQLCommand(servers[0]) | ||
140 | |||
141 | await servers[0].config.enableRemoteTranscoding() | ||
142 | await servers[0].config.enableTranscoding({ hls: true, webVideo: true, with0p: true }) | ||
143 | await servers[0].config.enableLive({ allowReplay: true, resolutions: 'max', transcoding: true }) | ||
144 | |||
145 | const registrationToken = await servers[0].runnerRegistrationTokens.getFirstRegistrationToken() | ||
146 | |||
147 | peertubeRunner = new PeerTubeRunnerProcess(servers[0]) | ||
148 | await peertubeRunner.runServer() | ||
149 | await peertubeRunner.registerPeerTubeInstance({ registrationToken, runnerName: 'runner' }) | ||
150 | }) | ||
151 | |||
152 | describe('With lives on local filesystem storage', function () { | ||
153 | |||
154 | before(async function () { | ||
155 | await servers[0].config.enableTranscoding({ webVideo: true, hls: false, with0p: true }) | ||
156 | }) | ||
157 | |||
158 | runSuite() | ||
159 | }) | ||
160 | |||
161 | describe('With lives on object storage', function () { | ||
162 | if (areMockObjectStorageTestsDisabled()) return | ||
163 | |||
164 | const objectStorage = new ObjectStorageCommand() | ||
165 | |||
166 | before(async function () { | ||
167 | await objectStorage.prepareDefaultMockBuckets() | ||
168 | |||
169 | await servers[0].kill() | ||
170 | |||
171 | await servers[0].run(objectStorage.getDefaultMockConfig()) | ||
172 | |||
173 | // Wait for peertube runner socket reconnection | ||
174 | await wait(1500) | ||
175 | }) | ||
176 | |||
177 | runSuite({ objectStorage }) | ||
178 | |||
179 | after(async function () { | ||
180 | await objectStorage.cleanupMock() | ||
181 | }) | ||
182 | }) | ||
183 | |||
184 | describe('Check cleanup', function () { | ||
185 | |||
186 | it('Should have an empty cache directory', async function () { | ||
187 | await checkPeerTubeRunnerCacheIsEmpty(peertubeRunner) | ||
188 | }) | ||
189 | }) | ||
190 | |||
191 | after(async function () { | ||
192 | if (peertubeRunner) { | ||
193 | await peertubeRunner.unregisterPeerTubeInstance({ runnerName: 'runner' }) | ||
194 | peertubeRunner.kill() | ||
195 | } | ||
196 | |||
197 | if (sqlCommandServer1) await sqlCommandServer1.cleanup() | ||
198 | |||
199 | await cleanupTests(servers) | ||
200 | }) | ||
201 | }) | ||
diff --git a/server/tests/peertube-runner/studio-transcoding.ts b/server/tests/peertube-runner/studio-transcoding.ts deleted file mode 100644 index 56bfef897..000000000 --- a/server/tests/peertube-runner/studio-transcoding.ts +++ /dev/null | |||
@@ -1,124 +0,0 @@ | |||
1 | |||
2 | import { expect } from 'chai' | ||
3 | import { checkPeerTubeRunnerCacheIsEmpty, checkVideoDuration, expectStartWith, PeerTubeRunnerProcess } from '@server/tests/shared' | ||
4 | import { areMockObjectStorageTestsDisabled, getAllFiles, wait } from '@shared/core-utils' | ||
5 | import { | ||
6 | cleanupTests, | ||
7 | createMultipleServers, | ||
8 | doubleFollow, | ||
9 | ObjectStorageCommand, | ||
10 | PeerTubeServer, | ||
11 | setAccessTokensToServers, | ||
12 | setDefaultVideoChannel, | ||
13 | VideoStudioCommand, | ||
14 | waitJobs | ||
15 | } from '@shared/server-commands' | ||
16 | |||
17 | describe('Test studio transcoding in peertube-runner program', function () { | ||
18 | let servers: PeerTubeServer[] = [] | ||
19 | let peertubeRunner: PeerTubeRunnerProcess | ||
20 | |||
21 | function runSuite (options: { | ||
22 | objectStorage?: ObjectStorageCommand | ||
23 | } = {}) { | ||
24 | const { objectStorage } = options | ||
25 | |||
26 | it('Should run a complex studio transcoding', async function () { | ||
27 | this.timeout(120000) | ||
28 | |||
29 | const { uuid } = await servers[0].videos.quickUpload({ name: 'mp4', fixture: 'video_short.mp4' }) | ||
30 | await waitJobs(servers) | ||
31 | |||
32 | const video = await servers[0].videos.get({ id: uuid }) | ||
33 | const oldFileUrls = getAllFiles(video).map(f => f.fileUrl) | ||
34 | |||
35 | await servers[0].videoStudio.createEditionTasks({ videoId: uuid, tasks: VideoStudioCommand.getComplexTask() }) | ||
36 | await waitJobs(servers, { runnerJobs: true }) | ||
37 | |||
38 | for (const server of servers) { | ||
39 | const video = await server.videos.get({ id: uuid }) | ||
40 | const files = getAllFiles(video) | ||
41 | |||
42 | for (const f of files) { | ||
43 | expect(oldFileUrls).to.not.include(f.fileUrl) | ||
44 | } | ||
45 | |||
46 | if (objectStorage) { | ||
47 | for (const webVideoFile of video.files) { | ||
48 | expectStartWith(webVideoFile.fileUrl, objectStorage.getMockWebVideosBaseUrl()) | ||
49 | } | ||
50 | |||
51 | for (const hlsFile of video.streamingPlaylists[0].files) { | ||
52 | expectStartWith(hlsFile.fileUrl, objectStorage.getMockPlaylistBaseUrl()) | ||
53 | } | ||
54 | } | ||
55 | |||
56 | await checkVideoDuration(server, uuid, 9) | ||
57 | } | ||
58 | }) | ||
59 | } | ||
60 | |||
61 | before(async function () { | ||
62 | this.timeout(120_000) | ||
63 | |||
64 | servers = await createMultipleServers(2) | ||
65 | |||
66 | await setAccessTokensToServers(servers) | ||
67 | await setDefaultVideoChannel(servers) | ||
68 | |||
69 | await doubleFollow(servers[0], servers[1]) | ||
70 | |||
71 | await servers[0].config.enableTranscoding({ hls: true, webVideo: true }) | ||
72 | await servers[0].config.enableStudio() | ||
73 | await servers[0].config.enableRemoteStudio() | ||
74 | |||
75 | const registrationToken = await servers[0].runnerRegistrationTokens.getFirstRegistrationToken() | ||
76 | |||
77 | peertubeRunner = new PeerTubeRunnerProcess(servers[0]) | ||
78 | await peertubeRunner.runServer() | ||
79 | await peertubeRunner.registerPeerTubeInstance({ registrationToken, runnerName: 'runner' }) | ||
80 | }) | ||
81 | |||
82 | describe('With videos on local filesystem storage', function () { | ||
83 | runSuite() | ||
84 | }) | ||
85 | |||
86 | describe('With videos on object storage', function () { | ||
87 | if (areMockObjectStorageTestsDisabled()) return | ||
88 | |||
89 | const objectStorage = new ObjectStorageCommand() | ||
90 | |||
91 | before(async function () { | ||
92 | await objectStorage.prepareDefaultMockBuckets() | ||
93 | |||
94 | await servers[0].kill() | ||
95 | |||
96 | await servers[0].run(objectStorage.getDefaultMockConfig()) | ||
97 | |||
98 | // Wait for peertube runner socket reconnection | ||
99 | await wait(1500) | ||
100 | }) | ||
101 | |||
102 | runSuite({ objectStorage }) | ||
103 | |||
104 | after(async function () { | ||
105 | await objectStorage.cleanupMock() | ||
106 | }) | ||
107 | }) | ||
108 | |||
109 | describe('Check cleanup', function () { | ||
110 | |||
111 | it('Should have an empty cache directory', async function () { | ||
112 | await checkPeerTubeRunnerCacheIsEmpty(peertubeRunner) | ||
113 | }) | ||
114 | }) | ||
115 | |||
116 | after(async function () { | ||
117 | if (peertubeRunner) { | ||
118 | await peertubeRunner.unregisterPeerTubeInstance({ runnerName: 'runner' }) | ||
119 | peertubeRunner.kill() | ||
120 | } | ||
121 | |||
122 | await cleanupTests(servers) | ||
123 | }) | ||
124 | }) | ||
diff --git a/server/tests/peertube-runner/vod-transcoding.ts b/server/tests/peertube-runner/vod-transcoding.ts deleted file mode 100644 index b3b62e5e0..000000000 --- a/server/tests/peertube-runner/vod-transcoding.ts +++ /dev/null | |||
@@ -1,350 +0,0 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | import { expect } from 'chai' | ||
3 | import { | ||
4 | checkPeerTubeRunnerCacheIsEmpty, | ||
5 | completeCheckHlsPlaylist, | ||
6 | completeWebVideoFilesCheck, | ||
7 | PeerTubeRunnerProcess | ||
8 | } from '@server/tests/shared' | ||
9 | import { areMockObjectStorageTestsDisabled, getAllFiles, wait } from '@shared/core-utils' | ||
10 | import { VideoPrivacy } from '@shared/models' | ||
11 | import { | ||
12 | cleanupTests, | ||
13 | createMultipleServers, | ||
14 | doubleFollow, | ||
15 | ObjectStorageCommand, | ||
16 | PeerTubeServer, | ||
17 | setAccessTokensToServers, | ||
18 | setDefaultVideoChannel, | ||
19 | waitJobs | ||
20 | } from '@shared/server-commands' | ||
21 | |||
22 | describe('Test VOD transcoding in peertube-runner program', function () { | ||
23 | let servers: PeerTubeServer[] = [] | ||
24 | let peertubeRunner: PeerTubeRunnerProcess | ||
25 | |||
26 | function runSuite (options: { | ||
27 | webVideoEnabled: boolean | ||
28 | hlsEnabled: boolean | ||
29 | objectStorage?: ObjectStorageCommand | ||
30 | }) { | ||
31 | const { webVideoEnabled, hlsEnabled, objectStorage } = options | ||
32 | |||
33 | const objectStorageBaseUrlWebVideo = objectStorage | ||
34 | ? objectStorage.getMockWebVideosBaseUrl() | ||
35 | : undefined | ||
36 | |||
37 | const objectStorageBaseUrlHLS = objectStorage | ||
38 | ? objectStorage.getMockPlaylistBaseUrl() | ||
39 | : undefined | ||
40 | |||
41 | it('Should upload a classic video mp4 and transcode it', async function () { | ||
42 | this.timeout(120000) | ||
43 | |||
44 | const { uuid } = await servers[0].videos.quickUpload({ name: 'mp4', fixture: 'video_short.mp4' }) | ||
45 | |||
46 | await waitJobs(servers, { runnerJobs: true }) | ||
47 | |||
48 | for (const server of servers) { | ||
49 | if (webVideoEnabled) { | ||
50 | await completeWebVideoFilesCheck({ | ||
51 | server, | ||
52 | originServer: servers[0], | ||
53 | fixture: 'video_short.mp4', | ||
54 | videoUUID: uuid, | ||
55 | objectStorageBaseUrl: objectStorageBaseUrlWebVideo, | ||
56 | files: [ | ||
57 | { resolution: 0 }, | ||
58 | { resolution: 144 }, | ||
59 | { resolution: 240 }, | ||
60 | { resolution: 360 }, | ||
61 | { resolution: 480 }, | ||
62 | { resolution: 720 } | ||
63 | ] | ||
64 | }) | ||
65 | } | ||
66 | |||
67 | if (hlsEnabled) { | ||
68 | await completeCheckHlsPlaylist({ | ||
69 | hlsOnly: !webVideoEnabled, | ||
70 | servers, | ||
71 | videoUUID: uuid, | ||
72 | objectStorageBaseUrl: objectStorageBaseUrlHLS, | ||
73 | resolutions: [ 720, 480, 360, 240, 144, 0 ] | ||
74 | }) | ||
75 | } | ||
76 | } | ||
77 | }) | ||
78 | |||
79 | it('Should upload a webm video and transcode it', async function () { | ||
80 | this.timeout(120000) | ||
81 | |||
82 | const { uuid } = await servers[0].videos.quickUpload({ name: 'mp4', fixture: 'video_short.webm' }) | ||
83 | |||
84 | await waitJobs(servers, { runnerJobs: true }) | ||
85 | |||
86 | for (const server of servers) { | ||
87 | if (webVideoEnabled) { | ||
88 | await completeWebVideoFilesCheck({ | ||
89 | server, | ||
90 | originServer: servers[0], | ||
91 | fixture: 'video_short.webm', | ||
92 | videoUUID: uuid, | ||
93 | objectStorageBaseUrl: objectStorageBaseUrlWebVideo, | ||
94 | files: [ | ||
95 | { resolution: 0 }, | ||
96 | { resolution: 144 }, | ||
97 | { resolution: 240 }, | ||
98 | { resolution: 360 }, | ||
99 | { resolution: 480 }, | ||
100 | { resolution: 720 } | ||
101 | ] | ||
102 | }) | ||
103 | } | ||
104 | |||
105 | if (hlsEnabled) { | ||
106 | await completeCheckHlsPlaylist({ | ||
107 | hlsOnly: !webVideoEnabled, | ||
108 | servers, | ||
109 | videoUUID: uuid, | ||
110 | objectStorageBaseUrl: objectStorageBaseUrlHLS, | ||
111 | resolutions: [ 720, 480, 360, 240, 144, 0 ] | ||
112 | }) | ||
113 | } | ||
114 | } | ||
115 | }) | ||
116 | |||
117 | it('Should upload an audio only video and transcode it', async function () { | ||
118 | this.timeout(120000) | ||
119 | |||
120 | const attributes = { name: 'audio_without_preview', fixture: 'sample.ogg' } | ||
121 | const { uuid } = await servers[0].videos.upload({ attributes, mode: 'resumable' }) | ||
122 | |||
123 | await waitJobs(servers, { runnerJobs: true }) | ||
124 | |||
125 | for (const server of servers) { | ||
126 | if (webVideoEnabled) { | ||
127 | await completeWebVideoFilesCheck({ | ||
128 | server, | ||
129 | originServer: servers[0], | ||
130 | fixture: 'sample.ogg', | ||
131 | videoUUID: uuid, | ||
132 | objectStorageBaseUrl: objectStorageBaseUrlWebVideo, | ||
133 | files: [ | ||
134 | { resolution: 0 }, | ||
135 | { resolution: 144 }, | ||
136 | { resolution: 240 }, | ||
137 | { resolution: 360 }, | ||
138 | { resolution: 480 } | ||
139 | ] | ||
140 | }) | ||
141 | } | ||
142 | |||
143 | if (hlsEnabled) { | ||
144 | await completeCheckHlsPlaylist({ | ||
145 | hlsOnly: !webVideoEnabled, | ||
146 | servers, | ||
147 | videoUUID: uuid, | ||
148 | objectStorageBaseUrl: objectStorageBaseUrlHLS, | ||
149 | resolutions: [ 480, 360, 240, 144, 0 ] | ||
150 | }) | ||
151 | } | ||
152 | } | ||
153 | }) | ||
154 | |||
155 | it('Should upload a private video and transcode it', async function () { | ||
156 | this.timeout(120000) | ||
157 | |||
158 | const { uuid } = await servers[0].videos.quickUpload({ name: 'mp4', fixture: 'video_short.mp4', privacy: VideoPrivacy.PRIVATE }) | ||
159 | |||
160 | await waitJobs(servers, { runnerJobs: true }) | ||
161 | |||
162 | if (webVideoEnabled) { | ||
163 | await completeWebVideoFilesCheck({ | ||
164 | server: servers[0], | ||
165 | originServer: servers[0], | ||
166 | fixture: 'video_short.mp4', | ||
167 | videoUUID: uuid, | ||
168 | objectStorageBaseUrl: objectStorageBaseUrlWebVideo, | ||
169 | files: [ | ||
170 | { resolution: 0 }, | ||
171 | { resolution: 144 }, | ||
172 | { resolution: 240 }, | ||
173 | { resolution: 360 }, | ||
174 | { resolution: 480 }, | ||
175 | { resolution: 720 } | ||
176 | ] | ||
177 | }) | ||
178 | } | ||
179 | |||
180 | if (hlsEnabled) { | ||
181 | await completeCheckHlsPlaylist({ | ||
182 | hlsOnly: !webVideoEnabled, | ||
183 | servers: [ servers[0] ], | ||
184 | videoUUID: uuid, | ||
185 | objectStorageBaseUrl: objectStorageBaseUrlHLS, | ||
186 | resolutions: [ 720, 480, 360, 240, 144, 0 ] | ||
187 | }) | ||
188 | } | ||
189 | }) | ||
190 | |||
191 | it('Should transcode videos on manual run', async function () { | ||
192 | this.timeout(120000) | ||
193 | |||
194 | await servers[0].config.disableTranscoding() | ||
195 | |||
196 | const { uuid } = await servers[0].videos.quickUpload({ name: 'manual transcoding', fixture: 'video_short.mp4' }) | ||
197 | await waitJobs(servers, { runnerJobs: true }) | ||
198 | |||
199 | { | ||
200 | const video = await servers[0].videos.get({ id: uuid }) | ||
201 | expect(getAllFiles(video)).to.have.lengthOf(1) | ||
202 | } | ||
203 | |||
204 | await servers[0].config.enableTranscoding({ hls: true, webVideo: true, with0p: true }) | ||
205 | |||
206 | await servers[0].videos.runTranscoding({ transcodingType: 'web-video', videoId: uuid }) | ||
207 | await waitJobs(servers, { runnerJobs: true }) | ||
208 | |||
209 | await completeWebVideoFilesCheck({ | ||
210 | server: servers[0], | ||
211 | originServer: servers[0], | ||
212 | fixture: 'video_short.mp4', | ||
213 | videoUUID: uuid, | ||
214 | objectStorageBaseUrl: objectStorageBaseUrlWebVideo, | ||
215 | files: [ | ||
216 | { resolution: 0 }, | ||
217 | { resolution: 144 }, | ||
218 | { resolution: 240 }, | ||
219 | { resolution: 360 }, | ||
220 | { resolution: 480 }, | ||
221 | { resolution: 720 } | ||
222 | ] | ||
223 | }) | ||
224 | |||
225 | await servers[0].videos.runTranscoding({ transcodingType: 'hls', videoId: uuid }) | ||
226 | await waitJobs(servers, { runnerJobs: true }) | ||
227 | |||
228 | await completeCheckHlsPlaylist({ | ||
229 | hlsOnly: false, | ||
230 | servers: [ servers[0] ], | ||
231 | videoUUID: uuid, | ||
232 | objectStorageBaseUrl: objectStorageBaseUrlHLS, | ||
233 | resolutions: [ 720, 480, 360, 240, 144, 0 ] | ||
234 | }) | ||
235 | }) | ||
236 | } | ||
237 | |||
238 | before(async function () { | ||
239 | this.timeout(120_000) | ||
240 | |||
241 | servers = await createMultipleServers(2) | ||
242 | |||
243 | await setAccessTokensToServers(servers) | ||
244 | await setDefaultVideoChannel(servers) | ||
245 | |||
246 | await doubleFollow(servers[0], servers[1]) | ||
247 | |||
248 | await servers[0].config.enableRemoteTranscoding() | ||
249 | |||
250 | const registrationToken = await servers[0].runnerRegistrationTokens.getFirstRegistrationToken() | ||
251 | |||
252 | peertubeRunner = new PeerTubeRunnerProcess(servers[0]) | ||
253 | await peertubeRunner.runServer() | ||
254 | await peertubeRunner.registerPeerTubeInstance({ registrationToken, runnerName: 'runner' }) | ||
255 | }) | ||
256 | |||
257 | describe('With videos on local filesystem storage', function () { | ||
258 | |||
259 | describe('Web video only enabled', function () { | ||
260 | |||
261 | before(async function () { | ||
262 | await servers[0].config.enableTranscoding({ webVideo: true, hls: false, with0p: true }) | ||
263 | }) | ||
264 | |||
265 | runSuite({ webVideoEnabled: true, hlsEnabled: false }) | ||
266 | }) | ||
267 | |||
268 | describe('HLS videos only enabled', function () { | ||
269 | |||
270 | before(async function () { | ||
271 | await servers[0].config.enableTranscoding({ webVideo: false, hls: true, with0p: true }) | ||
272 | }) | ||
273 | |||
274 | runSuite({ webVideoEnabled: false, hlsEnabled: true }) | ||
275 | }) | ||
276 | |||
277 | describe('Web video & HLS enabled', function () { | ||
278 | |||
279 | before(async function () { | ||
280 | await servers[0].config.enableTranscoding({ hls: true, webVideo: true, with0p: true }) | ||
281 | }) | ||
282 | |||
283 | runSuite({ webVideoEnabled: true, hlsEnabled: true }) | ||
284 | }) | ||
285 | }) | ||
286 | |||
287 | describe('With videos on object storage', function () { | ||
288 | if (areMockObjectStorageTestsDisabled()) return | ||
289 | |||
290 | const objectStorage = new ObjectStorageCommand() | ||
291 | |||
292 | before(async function () { | ||
293 | await objectStorage.prepareDefaultMockBuckets() | ||
294 | |||
295 | await servers[0].kill() | ||
296 | |||
297 | await servers[0].run(objectStorage.getDefaultMockConfig()) | ||
298 | |||
299 | // Wait for peertube runner socket reconnection | ||
300 | await wait(1500) | ||
301 | }) | ||
302 | |||
303 | describe('Web video only enabled', function () { | ||
304 | |||
305 | before(async function () { | ||
306 | await servers[0].config.enableTranscoding({ webVideo: true, hls: false, with0p: true }) | ||
307 | }) | ||
308 | |||
309 | runSuite({ webVideoEnabled: true, hlsEnabled: false, objectStorage }) | ||
310 | }) | ||
311 | |||
312 | describe('HLS videos only enabled', function () { | ||
313 | |||
314 | before(async function () { | ||
315 | await servers[0].config.enableTranscoding({ webVideo: false, hls: true, with0p: true }) | ||
316 | }) | ||
317 | |||
318 | runSuite({ webVideoEnabled: false, hlsEnabled: true, objectStorage }) | ||
319 | }) | ||
320 | |||
321 | describe('Web video & HLS enabled', function () { | ||
322 | |||
323 | before(async function () { | ||
324 | await servers[0].config.enableTranscoding({ hls: true, webVideo: true, with0p: true }) | ||
325 | }) | ||
326 | |||
327 | runSuite({ webVideoEnabled: true, hlsEnabled: true, objectStorage }) | ||
328 | }) | ||
329 | |||
330 | after(async function () { | ||
331 | await objectStorage.cleanupMock() | ||
332 | }) | ||
333 | }) | ||
334 | |||
335 | describe('Check cleanup', function () { | ||
336 | |||
337 | it('Should have an empty cache directory', async function () { | ||
338 | await checkPeerTubeRunnerCacheIsEmpty(peertubeRunner) | ||
339 | }) | ||
340 | }) | ||
341 | |||
342 | after(async function () { | ||
343 | if (peertubeRunner) { | ||
344 | await peertubeRunner.unregisterPeerTubeInstance({ runnerName: 'runner' }) | ||
345 | peertubeRunner.kill() | ||
346 | } | ||
347 | |||
348 | await cleanupTests(servers) | ||
349 | }) | ||
350 | }) | ||