]>
Commit | Line | Data |
---|---|---|
68e70a74 C |
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | ||
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
5 | import { FfmpegCommand } from 'fluent-ffmpeg' | |
6 | import { LiveVideoCreate, VideoDetails, VideoPrivacy, VideoState } from '@shared/models' | |
fae6e4da | 7 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' |
68e70a74 C |
8 | import { |
9 | addVideoToBlacklist, | |
10 | checkLiveCleanup, | |
11 | cleanupTests, | |
12 | createLive, | |
13 | doubleFollow, | |
14 | flushAndRunMultipleServers, | |
15 | getVideo, | |
16 | getVideosList, | |
17 | removeVideo, | |
18 | sendRTMPStreamInVideo, | |
19 | ServerInfo, | |
20 | setAccessTokensToServers, | |
21 | setDefaultVideoChannel, | |
22 | stopFfmpeg, | |
23 | testFfmpegStreamError, | |
24 | updateCustomSubConfig, | |
25 | updateVideo, | |
94d721ef | 26 | wait, |
68e70a74 | 27 | waitJobs, |
fae6e4da | 28 | waitUntilLiveEnded, |
94d721ef C |
29 | waitUntilLivePublished, |
30 | waitUntilLiveSaved | |
68e70a74 C |
31 | } from '../../../../shared/extra-utils' |
32 | ||
33 | const expect = chai.expect | |
34 | ||
35 | describe('Save replay setting', function () { | |
36 | let servers: ServerInfo[] = [] | |
37 | let liveVideoUUID: string | |
38 | let ffmpegCommand: FfmpegCommand | |
39 | ||
40 | async function createLiveWrapper (saveReplay: boolean) { | |
41 | if (liveVideoUUID) { | |
42 | try { | |
43 | await removeVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) | |
44 | await waitJobs(servers) | |
45 | } catch {} | |
46 | } | |
47 | ||
48 | const attributes: LiveVideoCreate = { | |
49 | channelId: servers[0].videoChannel.id, | |
50 | privacy: VideoPrivacy.PUBLIC, | |
51 | name: 'my super live', | |
52 | saveReplay | |
53 | } | |
54 | ||
55 | const res = await createLive(servers[0].url, servers[0].accessToken, attributes) | |
56 | return res.body.video.uuid | |
57 | } | |
58 | ||
59 | async function checkVideosExist (videoId: string, existsInList: boolean, getStatus?: number) { | |
60 | for (const server of servers) { | |
61 | const length = existsInList ? 1 : 0 | |
62 | ||
63 | const resVideos = await getVideosList(server.url) | |
64 | expect(resVideos.body.data).to.have.lengthOf(length) | |
65 | expect(resVideos.body.total).to.equal(length) | |
66 | ||
67 | if (getStatus) { | |
68 | await getVideo(server.url, videoId, getStatus) | |
69 | } | |
70 | } | |
71 | } | |
72 | ||
73 | async function checkVideoState (videoId: string, state: VideoState) { | |
74 | for (const server of servers) { | |
75 | const res = await getVideo(server.url, videoId) | |
76 | expect((res.body as VideoDetails).state.id).to.equal(state) | |
77 | } | |
78 | } | |
79 | ||
fae6e4da C |
80 | async function waitUntilLivePublishedOnAllServers (videoId: string) { |
81 | for (const server of servers) { | |
82 | await waitUntilLivePublished(server.url, server.accessToken, videoId) | |
83 | } | |
84 | } | |
85 | ||
94d721ef C |
86 | async function waitUntilLiveSavedOnAllServers (videoId: string) { |
87 | for (const server of servers) { | |
88 | await waitUntilLiveSaved(server.url, server.accessToken, videoId) | |
89 | } | |
90 | } | |
91 | ||
68e70a74 C |
92 | before(async function () { |
93 | this.timeout(120000) | |
94 | ||
95 | servers = await flushAndRunMultipleServers(2) | |
96 | ||
97 | // Get the access tokens | |
98 | await setAccessTokensToServers(servers) | |
99 | await setDefaultVideoChannel(servers) | |
100 | ||
101 | // Server 1 and server 2 follow each other | |
102 | await doubleFollow(servers[0], servers[1]) | |
103 | ||
104 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { | |
105 | live: { | |
106 | enabled: true, | |
107 | allowReplay: true, | |
c9bc850e | 108 | maxDuration: -1, |
68e70a74 C |
109 | transcoding: { |
110 | enabled: false, | |
111 | resolutions: { | |
112 | '240p': true, | |
113 | '360p': true, | |
114 | '480p': true, | |
115 | '720p': true, | |
116 | '1080p': true, | |
b7085c71 | 117 | '1440p': true, |
68e70a74 C |
118 | '2160p': true |
119 | } | |
120 | } | |
121 | } | |
122 | }) | |
123 | }) | |
124 | ||
125 | describe('With save replay disabled', function () { | |
126 | ||
127 | before(async function () { | |
128 | this.timeout(10000) | |
129 | }) | |
130 | ||
131 | it('Should correctly create and federate the "waiting for stream" live', async function () { | |
132 | this.timeout(20000) | |
133 | ||
134 | liveVideoUUID = await createLiveWrapper(false) | |
135 | ||
136 | await waitJobs(servers) | |
137 | ||
f2eb23cd | 138 | await checkVideosExist(liveVideoUUID, false, HttpStatusCode.OK_200) |
68e70a74 C |
139 | await checkVideoState(liveVideoUUID, VideoState.WAITING_FOR_LIVE) |
140 | }) | |
141 | ||
142 | it('Should correctly have updated the live and federated it when streaming in the live', async function () { | |
fae6e4da | 143 | this.timeout(30000) |
68e70a74 C |
144 | |
145 | ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) | |
fae6e4da C |
146 | |
147 | await waitUntilLivePublishedOnAllServers(liveVideoUUID) | |
68e70a74 C |
148 | |
149 | await waitJobs(servers) | |
150 | ||
f2eb23cd | 151 | await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) |
68e70a74 C |
152 | await checkVideoState(liveVideoUUID, VideoState.PUBLISHED) |
153 | }) | |
154 | ||
155 | it('Should correctly delete the video files after the stream ended', async function () { | |
59fd824c | 156 | this.timeout(40000) |
68e70a74 C |
157 | |
158 | await stopFfmpeg(ffmpegCommand) | |
159 | ||
fae6e4da C |
160 | for (const server of servers) { |
161 | await waitUntilLiveEnded(server.url, server.accessToken, liveVideoUUID) | |
162 | } | |
68e70a74 C |
163 | await waitJobs(servers) |
164 | ||
165 | // Live still exist, but cannot be played anymore | |
f2eb23cd | 166 | await checkVideosExist(liveVideoUUID, false, HttpStatusCode.OK_200) |
68e70a74 C |
167 | await checkVideoState(liveVideoUUID, VideoState.LIVE_ENDED) |
168 | ||
169 | // No resolutions saved since we did not save replay | |
170 | await checkLiveCleanup(servers[0], liveVideoUUID, []) | |
171 | }) | |
172 | ||
173 | it('Should correctly terminate the stream on blacklist and delete the live', async function () { | |
174 | this.timeout(40000) | |
175 | ||
176 | liveVideoUUID = await createLiveWrapper(false) | |
177 | ||
178 | ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) | |
fae6e4da C |
179 | |
180 | await waitUntilLivePublishedOnAllServers(liveVideoUUID) | |
68e70a74 C |
181 | |
182 | await waitJobs(servers) | |
f2eb23cd | 183 | await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) |
68e70a74 C |
184 | |
185 | await Promise.all([ | |
186 | addVideoToBlacklist(servers[0].url, servers[0].accessToken, liveVideoUUID, 'bad live', true), | |
187 | testFfmpegStreamError(ffmpegCommand, true) | |
188 | ]) | |
189 | ||
190 | await waitJobs(servers) | |
191 | ||
192 | await checkVideosExist(liveVideoUUID, false) | |
193 | ||
f2eb23cd RK |
194 | await getVideo(servers[0].url, liveVideoUUID, HttpStatusCode.UNAUTHORIZED_401) |
195 | await getVideo(servers[1].url, liveVideoUUID, HttpStatusCode.NOT_FOUND_404) | |
68e70a74 | 196 | |
94d721ef C |
197 | await wait(5000) |
198 | await waitJobs(servers) | |
68e70a74 C |
199 | await checkLiveCleanup(servers[0], liveVideoUUID, []) |
200 | }) | |
201 | ||
202 | it('Should correctly terminate the stream on delete and delete the video', async function () { | |
203 | this.timeout(40000) | |
204 | ||
205 | liveVideoUUID = await createLiveWrapper(false) | |
206 | ||
207 | ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) | |
fae6e4da C |
208 | |
209 | await waitUntilLivePublishedOnAllServers(liveVideoUUID) | |
68e70a74 C |
210 | |
211 | await waitJobs(servers) | |
f2eb23cd | 212 | await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) |
68e70a74 C |
213 | |
214 | await Promise.all([ | |
215 | testFfmpegStreamError(ffmpegCommand, true), | |
216 | removeVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) | |
217 | ]) | |
218 | ||
94d721ef | 219 | await wait(5000) |
68e70a74 C |
220 | await waitJobs(servers) |
221 | ||
f2eb23cd | 222 | await checkVideosExist(liveVideoUUID, false, HttpStatusCode.NOT_FOUND_404) |
68e70a74 C |
223 | await checkLiveCleanup(servers[0], liveVideoUUID, []) |
224 | }) | |
225 | }) | |
226 | ||
227 | describe('With save replay enabled', function () { | |
228 | ||
229 | it('Should correctly create and federate the "waiting for stream" live', async function () { | |
230 | this.timeout(20000) | |
231 | ||
232 | liveVideoUUID = await createLiveWrapper(true) | |
233 | ||
234 | await waitJobs(servers) | |
235 | ||
f2eb23cd | 236 | await checkVideosExist(liveVideoUUID, false, HttpStatusCode.OK_200) |
68e70a74 C |
237 | await checkVideoState(liveVideoUUID, VideoState.WAITING_FOR_LIVE) |
238 | }) | |
239 | ||
240 | it('Should correctly have updated the live and federated it when streaming in the live', async function () { | |
241 | this.timeout(20000) | |
242 | ||
243 | ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) | |
fae6e4da | 244 | await waitUntilLivePublishedOnAllServers(liveVideoUUID) |
68e70a74 C |
245 | |
246 | await waitJobs(servers) | |
247 | ||
f2eb23cd | 248 | await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) |
68e70a74 C |
249 | await checkVideoState(liveVideoUUID, VideoState.PUBLISHED) |
250 | }) | |
251 | ||
252 | it('Should correctly have saved the live and federated it after the streaming', async function () { | |
253 | this.timeout(30000) | |
254 | ||
255 | await stopFfmpeg(ffmpegCommand) | |
256 | ||
94d721ef | 257 | await waitUntilLiveSavedOnAllServers(liveVideoUUID) |
68e70a74 C |
258 | await waitJobs(servers) |
259 | ||
260 | // Live has been transcoded | |
f2eb23cd | 261 | await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) |
68e70a74 C |
262 | await checkVideoState(liveVideoUUID, VideoState.PUBLISHED) |
263 | }) | |
264 | ||
265 | it('Should update the saved live and correctly federate the updated attributes', async function () { | |
266 | this.timeout(30000) | |
267 | ||
268 | await updateVideo(servers[0].url, servers[0].accessToken, liveVideoUUID, { name: 'video updated' }) | |
269 | await waitJobs(servers) | |
270 | ||
271 | for (const server of servers) { | |
272 | const res = await getVideo(server.url, liveVideoUUID) | |
273 | expect(res.body.name).to.equal('video updated') | |
274 | expect(res.body.isLive).to.be.false | |
275 | } | |
276 | }) | |
277 | ||
278 | it('Should have cleaned up the live files', async function () { | |
279 | await checkLiveCleanup(servers[0], liveVideoUUID, [ 720 ]) | |
280 | }) | |
281 | ||
282 | it('Should correctly terminate the stream on blacklist and blacklist the saved replay video', async function () { | |
283 | this.timeout(40000) | |
284 | ||
285 | liveVideoUUID = await createLiveWrapper(true) | |
286 | ||
287 | ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) | |
fae6e4da | 288 | await waitUntilLivePublishedOnAllServers(liveVideoUUID) |
68e70a74 C |
289 | |
290 | await waitJobs(servers) | |
f2eb23cd | 291 | await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) |
68e70a74 C |
292 | |
293 | await Promise.all([ | |
294 | addVideoToBlacklist(servers[0].url, servers[0].accessToken, liveVideoUUID, 'bad live', true), | |
295 | testFfmpegStreamError(ffmpegCommand, true) | |
296 | ]) | |
297 | ||
298 | await waitJobs(servers) | |
299 | ||
300 | await checkVideosExist(liveVideoUUID, false) | |
301 | ||
f2eb23cd RK |
302 | await getVideo(servers[0].url, liveVideoUUID, HttpStatusCode.UNAUTHORIZED_401) |
303 | await getVideo(servers[1].url, liveVideoUUID, HttpStatusCode.NOT_FOUND_404) | |
68e70a74 | 304 | |
94d721ef C |
305 | await wait(5000) |
306 | await waitJobs(servers) | |
68e70a74 C |
307 | await checkLiveCleanup(servers[0], liveVideoUUID, [ 720 ]) |
308 | }) | |
309 | ||
310 | it('Should correctly terminate the stream on delete and delete the video', async function () { | |
311 | this.timeout(40000) | |
312 | ||
313 | liveVideoUUID = await createLiveWrapper(true) | |
314 | ||
315 | ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) | |
fae6e4da | 316 | await waitUntilLivePublishedOnAllServers(liveVideoUUID) |
68e70a74 C |
317 | |
318 | await waitJobs(servers) | |
f2eb23cd | 319 | await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) |
68e70a74 C |
320 | |
321 | await Promise.all([ | |
322 | removeVideo(servers[0].url, servers[0].accessToken, liveVideoUUID), | |
323 | testFfmpegStreamError(ffmpegCommand, true) | |
324 | ]) | |
325 | ||
94d721ef | 326 | await wait(5000) |
68e70a74 C |
327 | await waitJobs(servers) |
328 | ||
f2eb23cd | 329 | await checkVideosExist(liveVideoUUID, false, HttpStatusCode.NOT_FOUND_404) |
68e70a74 C |
330 | await checkLiveCleanup(servers[0], liveVideoUUID, []) |
331 | }) | |
332 | }) | |
333 | ||
334 | after(async function () { | |
335 | await cleanupTests(servers) | |
336 | }) | |
337 | }) |