]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/videos/video-create-transcoding.ts
dcdbd9c6ed74caa8ce519c9f28b1e75836a53158
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / video-create-transcoding.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import 'mocha'
4 import * as chai from 'chai'
5 import { expectStartWith } from '@server/tests/shared'
6 import { areObjectStorageTestsDisabled } from '@shared/core-utils'
7 import { HttpStatusCode, VideoDetails } from '@shared/models'
8 import {
9 cleanupTests,
10 createMultipleServers,
11 doubleFollow,
12 expectNoFailedTranscodingJob,
13 makeRawRequest,
14 ObjectStorageCommand,
15 PeerTubeServer,
16 setAccessTokensToServers,
17 waitJobs
18 } from '@shared/server-commands'
19
20 const expect = chai.expect
21
22 async function checkFilesInObjectStorage (video: VideoDetails) {
23 for (const file of video.files) {
24 expectStartWith(file.fileUrl, ObjectStorageCommand.getWebTorrentBaseUrl())
25 await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200)
26 }
27
28 const streamingPlaylistFiles = video.streamingPlaylists.length === 0
29 ? []
30 : video.streamingPlaylists[0].files
31
32 for (const file of streamingPlaylistFiles) {
33 expectStartWith(file.fileUrl, ObjectStorageCommand.getPlaylistBaseUrl())
34 await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200)
35 }
36 }
37
38 function 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 await waitJobs(servers)
64
65 const video = await servers[0].videos.get({ id: videoUUID })
66 publishedAt = video.publishedAt as string
67
68 await servers[0].config.enableTranscoding()
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 only generate WebTorrent', async function () {
135 this.timeout(60000)
136
137 await servers[0].videos.removeHLSFiles({ videoId: videoUUID })
138 await waitJobs(servers)
139
140 await servers[0].videos.runTranscoding({ videoId: videoUUID, transcodingType: 'webtorrent' })
141 await waitJobs(servers)
142
143 for (const server of servers) {
144 const videoDetails = await server.videos.get({ id: videoUUID })
145
146 expect(videoDetails.files).to.have.lengthOf(5)
147 expect(videoDetails.streamingPlaylists).to.have.lengthOf(0)
148
149 if (objectStorage) await checkFilesInObjectStorage(videoDetails)
150 }
151 })
152
153 it('Should not have updated published at attributes', async function () {
154 const video = await servers[0].videos.get({ id: videoUUID })
155
156 expect(video.publishedAt).to.equal(publishedAt)
157 })
158
159 after(async function () {
160 await cleanupTests(servers)
161 })
162 }
163
164 describe('Test create transcoding jobs from API', function () {
165
166 describe('On filesystem', function () {
167 runTests(false)
168 })
169
170 describe('On object storage', function () {
171 if (areObjectStorageTestsDisabled()) return
172
173 runTests(true)
174 })
175 })