aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-11-18 14:35:08 +0100
committerChocobozzz <me@florianbigard.com>2021-11-18 15:20:57 +0100
commitad5db1044c8599eaaaa2a578b350777ae996b068 (patch)
tree3e003cccf021152405d49b21c6c91b703c8ae96c /server/tests/api
parentb46cf4b920984492df598c1b61179acfc7f6f22e (diff)
downloadPeerTube-ad5db1044c8599eaaaa2a578b350777ae996b068.tar.gz
PeerTube-ad5db1044c8599eaaaa2a578b350777ae996b068.tar.zst
PeerTube-ad5db1044c8599eaaaa2a578b350777ae996b068.zip
Add ability to run transcoding jobs
Diffstat (limited to 'server/tests/api')
-rw-r--r--server/tests/api/check-params/index.ts1
-rw-r--r--server/tests/api/check-params/transcoding.ts104
-rw-r--r--server/tests/api/check-params/video-files.ts17
-rw-r--r--server/tests/api/videos/index.ts1
-rw-r--r--server/tests/api/videos/video-create-transcoding.ts156
5 files changed, 278 insertions, 1 deletions
diff --git a/server/tests/api/check-params/index.ts b/server/tests/api/check-params/index.ts
index ff7dc4abb..e052296db 100644
--- a/server/tests/api/check-params/index.ts
+++ b/server/tests/api/check-params/index.ts
@@ -15,6 +15,7 @@ import './plugins'
15import './redundancy' 15import './redundancy'
16import './search' 16import './search'
17import './services' 17import './services'
18import './transcoding'
18import './upload-quota' 19import './upload-quota'
19import './user-notifications' 20import './user-notifications'
20import './user-subscriptions' 21import './user-subscriptions'
diff --git a/server/tests/api/check-params/transcoding.ts b/server/tests/api/check-params/transcoding.ts
new file mode 100644
index 000000000..a8daafe3e
--- /dev/null
+++ b/server/tests/api/check-params/transcoding.ts
@@ -0,0 +1,104 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
5import { HttpStatusCode, UserRole } from '@shared/models'
6
7describe('Test transcoding API validators', function () {
8 let servers: PeerTubeServer[]
9
10 let userToken: string
11 let moderatorToken: string
12
13 let remoteId: string
14 let validId: string
15
16 // ---------------------------------------------------------------
17
18 before(async function () {
19 this.timeout(60000)
20
21 servers = await createMultipleServers(2)
22 await setAccessTokensToServers(servers)
23
24 await doubleFollow(servers[0], servers[1])
25
26 userToken = await servers[0].users.generateUserAndToken('user', UserRole.USER)
27 moderatorToken = await servers[0].users.generateUserAndToken('moderator', UserRole.MODERATOR)
28
29 {
30 const { uuid } = await servers[1].videos.quickUpload({ name: 'remote video' })
31 remoteId = uuid
32 }
33
34 {
35 const { uuid } = await servers[0].videos.quickUpload({ name: 'both 1' })
36 validId = uuid
37 }
38
39 await waitJobs(servers)
40
41 await servers[0].config.enableTranscoding()
42 })
43
44 it('Should not run transcoding of a unknown video', async function () {
45 await servers[0].videos.runTranscoding({ videoId: 404, transcodingType: 'hls', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
46 await servers[0].videos.runTranscoding({ videoId: 404, transcodingType: 'webtorrent', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
47 })
48
49 it('Should not run transcoding of a remote video', async function () {
50 const expectedStatus = HttpStatusCode.BAD_REQUEST_400
51
52 await servers[0].videos.runTranscoding({ videoId: remoteId, transcodingType: 'hls', expectedStatus })
53 await servers[0].videos.runTranscoding({ videoId: remoteId, transcodingType: 'webtorrent', expectedStatus })
54 })
55
56 it('Should not run transcoding by a non admin user', async function () {
57 const expectedStatus = HttpStatusCode.FORBIDDEN_403
58
59 await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'hls', token: userToken, expectedStatus })
60 await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'webtorrent', token: moderatorToken, expectedStatus })
61 })
62
63 it('Should not run transcoding without transcoding type', async function () {
64 await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: undefined, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
65 })
66
67 it('Should not run transcoding with an incorrect transcoding type', async function () {
68 const expectedStatus = HttpStatusCode.BAD_REQUEST_400
69
70 await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'toto' as any, expectedStatus })
71 })
72
73 it('Should not run transcoding if the instance disabled it', async function () {
74 const expectedStatus = HttpStatusCode.BAD_REQUEST_400
75
76 await servers[0].config.disableTranscoding()
77
78 await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'hls', expectedStatus })
79 await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'webtorrent', expectedStatus })
80 })
81
82 it('Should run transcoding', async function () {
83 this.timeout(120_000)
84
85 await servers[0].config.enableTranscoding()
86
87 await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'hls' })
88 await waitJobs(servers)
89
90 await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'webtorrent' })
91 await waitJobs(servers)
92 })
93
94 it('Should not run transcoding on a video that is already being transcoded', async function () {
95 await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'webtorrent' })
96
97 const expectedStatus = HttpStatusCode.CONFLICT_409
98 await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'webtorrent', expectedStatus })
99 })
100
101 after(async function () {
102 await cleanupTests(servers)
103 })
104})
diff --git a/server/tests/api/check-params/video-files.ts b/server/tests/api/check-params/video-files.ts
index 48b10d2b5..61936d562 100644
--- a/server/tests/api/check-params/video-files.ts
+++ b/server/tests/api/check-params/video-files.ts
@@ -1,16 +1,19 @@
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
3import 'mocha' 3import 'mocha'
4import { cleanupTests, createMultipleServers, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' 4import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
5import { HttpStatusCode, UserRole } from '@shared/models' 5import { HttpStatusCode, UserRole } from '@shared/models'
6 6
7describe('Test videos files', function () { 7describe('Test videos files', function () {
8 let servers: PeerTubeServer[] 8 let servers: PeerTubeServer[]
9
9 let webtorrentId: string 10 let webtorrentId: string
10 let hlsId: string 11 let hlsId: string
11 let remoteId: string 12 let remoteId: string
13
12 let userToken: string 14 let userToken: string
13 let moderatorToken: string 15 let moderatorToken: string
16
14 let validId1: string 17 let validId1: string
15 let validId2: string 18 let validId2: string
16 19
@@ -22,10 +25,17 @@ describe('Test videos files', function () {
22 servers = await createMultipleServers(2) 25 servers = await createMultipleServers(2)
23 await setAccessTokensToServers(servers) 26 await setAccessTokensToServers(servers)
24 27
28 await doubleFollow(servers[0], servers[1])
29
25 userToken = await servers[0].users.generateUserAndToken('user', UserRole.USER) 30 userToken = await servers[0].users.generateUserAndToken('user', UserRole.USER)
26 moderatorToken = await servers[0].users.generateUserAndToken('moderator', UserRole.MODERATOR) 31 moderatorToken = await servers[0].users.generateUserAndToken('moderator', UserRole.MODERATOR)
27 32
28 { 33 {
34 const { uuid } = await servers[1].videos.quickUpload({ name: 'remote video' })
35 remoteId = uuid
36 }
37
38 {
29 await servers[0].config.enableTranscoding(true, true) 39 await servers[0].config.enableTranscoding(true, true)
30 40
31 { 41 {
@@ -58,6 +68,11 @@ describe('Test videos files', function () {
58 await waitJobs(servers) 68 await waitJobs(servers)
59 }) 69 })
60 70
71 it('Should not delete files of a unknown video', async function () {
72 await servers[0].videos.removeHLSFiles({ videoId: 404, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
73 await servers[0].videos.removeWebTorrentFiles({ videoId: 404, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
74 })
75
61 it('Should not delete files of a remote video', async function () { 76 it('Should not delete files of a remote video', async function () {
62 await servers[0].videos.removeHLSFiles({ videoId: remoteId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) 77 await servers[0].videos.removeHLSFiles({ videoId: remoteId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
63 await servers[0].videos.removeWebTorrentFiles({ videoId: remoteId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) 78 await servers[0].videos.removeWebTorrentFiles({ videoId: remoteId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
diff --git a/server/tests/api/videos/index.ts b/server/tests/api/videos/index.ts
index f92e339e7..bedb9b8b6 100644
--- a/server/tests/api/videos/index.ts
+++ b/server/tests/api/videos/index.ts
@@ -6,6 +6,7 @@ import './video-captions'
6import './video-change-ownership' 6import './video-change-ownership'
7import './video-channels' 7import './video-channels'
8import './video-comments' 8import './video-comments'
9import './video-create-transcoding'
9import './video-description' 10import './video-description'
10import './video-files' 11import './video-files'
11import './video-hls' 12import './video-hls'
diff --git a/server/tests/api/videos/video-create-transcoding.ts b/server/tests/api/videos/video-create-transcoding.ts
new file mode 100644
index 000000000..bae06ac6c
--- /dev/null
+++ b/server/tests/api/videos/video-create-transcoding.ts
@@ -0,0 +1,156 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import * as chai from 'chai'
5import {
6 areObjectStorageTestsDisabled,
7 cleanupTests,
8 createMultipleServers,
9 doubleFollow,
10 expectStartWith,
11 makeRawRequest,
12 ObjectStorageCommand,
13 PeerTubeServer,
14 setAccessTokensToServers,
15 waitJobs
16} from '@shared/extra-utils'
17import { HttpStatusCode, VideoDetails } from '@shared/models'
18
19const expect = chai.expect
20
21async function checkFilesInObjectStorage (video: VideoDetails) {
22 for (const file of video.files) {
23 expectStartWith(file.fileUrl, ObjectStorageCommand.getWebTorrentBaseUrl())
24 await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200)
25 }
26
27 for (const file of video.streamingPlaylists[0].files) {
28 expectStartWith(file.fileUrl, ObjectStorageCommand.getPlaylistBaseUrl())
29 await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200)
30 }
31}
32
33async function expectNoFailedTranscodingJob (server: PeerTubeServer) {
34 const { data } = await server.jobs.listFailed({ jobType: 'video-transcoding' })
35 expect(data).to.have.lengthOf(0)
36}
37
38function runTests (objectStorage: boolean) {
39 let servers: PeerTubeServer[] = []
40 let videoUUID: string
41 let publishedAt: string
42
43 before(async function () {
44 this.timeout(120000)
45
46 const config = objectStorage
47 ? ObjectStorageCommand.getDefaultConfig()
48 : {}
49
50 // Run server 2 to have transcoding enabled
51 servers = await createMultipleServers(2, config)
52 await setAccessTokensToServers(servers)
53
54 await servers[0].config.disableTranscoding()
55
56 await doubleFollow(servers[0], servers[1])
57
58 if (objectStorage) await ObjectStorageCommand.prepareDefaultBuckets()
59
60 const { shortUUID } = await servers[0].videos.quickUpload({ name: 'video' })
61 videoUUID = shortUUID
62
63 const video = await servers[0].videos.get({ id: videoUUID })
64 publishedAt = video.publishedAt as string
65
66 await servers[0].config.enableTranscoding()
67
68 await waitJobs(servers)
69 })
70
71 it('Should generate HLS', async function () {
72 this.timeout(60000)
73
74 await servers[0].videos.runTranscoding({
75 videoId: videoUUID,
76 transcodingType: 'hls'
77 })
78
79 await waitJobs(servers)
80 await expectNoFailedTranscodingJob(servers[0])
81
82 for (const server of servers) {
83 const videoDetails = await server.videos.get({ id: videoUUID })
84
85 expect(videoDetails.files).to.have.lengthOf(1)
86 expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
87 expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(5)
88
89 if (objectStorage) await checkFilesInObjectStorage(videoDetails)
90 }
91 })
92
93 it('Should generate WebTorrent', async function () {
94 this.timeout(60000)
95
96 await servers[0].videos.runTranscoding({
97 videoId: videoUUID,
98 transcodingType: 'webtorrent'
99 })
100
101 await waitJobs(servers)
102
103 for (const server of servers) {
104 const videoDetails = await server.videos.get({ id: videoUUID })
105
106 expect(videoDetails.files).to.have.lengthOf(5)
107 expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
108 expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(5)
109
110 if (objectStorage) await checkFilesInObjectStorage(videoDetails)
111 }
112 })
113
114 it('Should generate WebTorrent from HLS only video', async function () {
115 this.timeout(60000)
116
117 await servers[0].videos.removeWebTorrentFiles({ videoId: videoUUID })
118 await waitJobs(servers)
119
120 await servers[0].videos.runTranscoding({ videoId: videoUUID, transcodingType: 'webtorrent' })
121 await waitJobs(servers)
122
123 for (const server of servers) {
124 const videoDetails = await server.videos.get({ id: videoUUID })
125
126 expect(videoDetails.files).to.have.lengthOf(5)
127 expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
128 expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(5)
129
130 if (objectStorage) await checkFilesInObjectStorage(videoDetails)
131 }
132 })
133
134 it('Should not have updated published at attributes', async function () {
135 const video = await servers[0].videos.get({ id: videoUUID })
136
137 expect(video.publishedAt).to.equal(publishedAt)
138 })
139
140 after(async function () {
141 await cleanupTests(servers)
142 })
143}
144
145describe('Test create transcoding jobs from API', function () {
146
147 describe('On filesystem', function () {
148 runTests(false)
149 })
150
151 describe('On object storage', function () {
152 if (areObjectStorageTestsDisabled()) return
153
154 runTests(true)
155 })
156})