aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/live/live-save-replay.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-04-21 09:06:52 +0200
committerChocobozzz <me@florianbigard.com>2022-04-21 11:47:57 +0200
commit4ec52d04dcc5d664612331f8e08d7d90da990415 (patch)
tree4b193f9f8f210caaf2dbe05ef3e37fa3a6fc28f0 /server/tests/api/live/live-save-replay.ts
parent2024a3b9338d667640aa115da6071ea83d088c50 (diff)
downloadPeerTube-4ec52d04dcc5d664612331f8e08d7d90da990415.tar.gz
PeerTube-4ec52d04dcc5d664612331f8e08d7d90da990415.tar.zst
PeerTube-4ec52d04dcc5d664612331f8e08d7d90da990415.zip
Add ability to save replay of permanent lives
Diffstat (limited to 'server/tests/api/live/live-save-replay.ts')
-rw-r--r--server/tests/api/live/live-save-replay.ts155
1 files changed, 137 insertions, 18 deletions
diff --git a/server/tests/api/live/live-save-replay.ts b/server/tests/api/live/live-save-replay.ts
index 95a342b01..ba68a4287 100644
--- a/server/tests/api/live/live-save-replay.ts
+++ b/server/tests/api/live/live-save-replay.ts
@@ -3,7 +3,7 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { FfmpegCommand } from 'fluent-ffmpeg' 5import { FfmpegCommand } from 'fluent-ffmpeg'
6import { checkLiveCleanupAfterSave } from '@server/tests/shared' 6import { checkLiveCleanup } from '@server/tests/shared'
7import { wait } from '@shared/core-utils' 7import { wait } from '@shared/core-utils'
8import { HttpStatusCode, LiveVideoCreate, VideoPrivacy, VideoState } from '@shared/models' 8import { HttpStatusCode, LiveVideoCreate, VideoPrivacy, VideoState } from '@shared/models'
9import { 9import {
@@ -11,6 +11,7 @@ import {
11 ConfigCommand, 11 ConfigCommand,
12 createMultipleServers, 12 createMultipleServers,
13 doubleFollow, 13 doubleFollow,
14 findExternalSavedVideo,
14 PeerTubeServer, 15 PeerTubeServer,
15 setAccessTokensToServers, 16 setAccessTokensToServers,
16 setDefaultVideoChannel, 17 setDefaultVideoChannel,
@@ -18,7 +19,8 @@ import {
18 testFfmpegStreamError, 19 testFfmpegStreamError,
19 waitJobs, 20 waitJobs,
20 waitUntilLivePublishedOnAllServers, 21 waitUntilLivePublishedOnAllServers,
21 waitUntilLiveSavedOnAllServers 22 waitUntilLiveReplacedByReplayOnAllServers,
23 waitUntilLiveWaitingOnAllServers
22} from '@shared/server-commands' 24} from '@shared/server-commands'
23 25
24const expect = chai.expect 26const expect = chai.expect
@@ -28,7 +30,7 @@ describe('Save replay setting', function () {
28 let liveVideoUUID: string 30 let liveVideoUUID: string
29 let ffmpegCommand: FfmpegCommand 31 let ffmpegCommand: FfmpegCommand
30 32
31 async function createLiveWrapper (saveReplay: boolean) { 33 async function createLiveWrapper (options: { permanent: boolean, replay: boolean }) {
32 if (liveVideoUUID) { 34 if (liveVideoUUID) {
33 try { 35 try {
34 await servers[0].videos.remove({ id: liveVideoUUID }) 36 await servers[0].videos.remove({ id: liveVideoUUID })
@@ -40,7 +42,8 @@ describe('Save replay setting', function () {
40 channelId: servers[0].store.channel.id, 42 channelId: servers[0].store.channel.id,
41 privacy: VideoPrivacy.PUBLIC, 43 privacy: VideoPrivacy.PUBLIC,
42 name: 'my super live', 44 name: 'my super live',
43 saveReplay 45 saveReplay: options.replay,
46 permanentLive: options.permanent
44 } 47 }
45 48
46 const { uuid } = await servers[0].live.create({ fields: attributes }) 49 const { uuid } = await servers[0].live.create({ fields: attributes })
@@ -104,7 +107,7 @@ describe('Save replay setting', function () {
104 it('Should correctly create and federate the "waiting for stream" live', async function () { 107 it('Should correctly create and federate the "waiting for stream" live', async function () {
105 this.timeout(20000) 108 this.timeout(20000)
106 109
107 liveVideoUUID = await createLiveWrapper(false) 110 liveVideoUUID = await createLiveWrapper({ permanent: false, replay: false })
108 111
109 await waitJobs(servers) 112 await waitJobs(servers)
110 113
@@ -140,13 +143,13 @@ describe('Save replay setting', function () {
140 await checkVideoState(liveVideoUUID, VideoState.LIVE_ENDED) 143 await checkVideoState(liveVideoUUID, VideoState.LIVE_ENDED)
141 144
142 // No resolutions saved since we did not save replay 145 // No resolutions saved since we did not save replay
143 await checkLiveCleanupAfterSave(servers[0], liveVideoUUID, []) 146 await checkLiveCleanup(servers[0], liveVideoUUID, [])
144 }) 147 })
145 148
146 it('Should correctly terminate the stream on blacklist and delete the live', async function () { 149 it('Should correctly terminate the stream on blacklist and delete the live', async function () {
147 this.timeout(40000) 150 this.timeout(40000)
148 151
149 liveVideoUUID = await createLiveWrapper(false) 152 liveVideoUUID = await createLiveWrapper({ permanent: false, replay: false })
150 153
151 ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) 154 ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID })
152 155
@@ -169,13 +172,13 @@ describe('Save replay setting', function () {
169 172
170 await wait(5000) 173 await wait(5000)
171 await waitJobs(servers) 174 await waitJobs(servers)
172 await checkLiveCleanupAfterSave(servers[0], liveVideoUUID, []) 175 await checkLiveCleanup(servers[0], liveVideoUUID, [])
173 }) 176 })
174 177
175 it('Should correctly terminate the stream on delete and delete the video', async function () { 178 it('Should correctly terminate the stream on delete and delete the video', async function () {
176 this.timeout(40000) 179 this.timeout(40000)
177 180
178 liveVideoUUID = await createLiveWrapper(false) 181 liveVideoUUID = await createLiveWrapper({ permanent: false, replay: false })
179 182
180 ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) 183 ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID })
181 184
@@ -193,16 +196,16 @@ describe('Save replay setting', function () {
193 await waitJobs(servers) 196 await waitJobs(servers)
194 197
195 await checkVideosExist(liveVideoUUID, false, HttpStatusCode.NOT_FOUND_404) 198 await checkVideosExist(liveVideoUUID, false, HttpStatusCode.NOT_FOUND_404)
196 await checkLiveCleanupAfterSave(servers[0], liveVideoUUID, []) 199 await checkLiveCleanup(servers[0], liveVideoUUID, [])
197 }) 200 })
198 }) 201 })
199 202
200 describe('With save replay enabled', function () { 203 describe('With save replay enabled on non permanent live', function () {
201 204
202 it('Should correctly create and federate the "waiting for stream" live', async function () { 205 it('Should correctly create and federate the "waiting for stream" live', async function () {
203 this.timeout(20000) 206 this.timeout(20000)
204 207
205 liveVideoUUID = await createLiveWrapper(true) 208 liveVideoUUID = await createLiveWrapper({ permanent: false, replay: true })
206 209
207 await waitJobs(servers) 210 await waitJobs(servers)
208 211
@@ -227,7 +230,7 @@ describe('Save replay setting', function () {
227 230
228 await stopFfmpeg(ffmpegCommand) 231 await stopFfmpeg(ffmpegCommand)
229 232
230 await waitUntilLiveSavedOnAllServers(servers, liveVideoUUID) 233 await waitUntilLiveReplacedByReplayOnAllServers(servers, liveVideoUUID)
231 await waitJobs(servers) 234 await waitJobs(servers)
232 235
233 // Live has been transcoded 236 // Live has been transcoded
@@ -249,13 +252,13 @@ describe('Save replay setting', function () {
249 }) 252 })
250 253
251 it('Should have cleaned up the live files', async function () { 254 it('Should have cleaned up the live files', async function () {
252 await checkLiveCleanupAfterSave(servers[0], liveVideoUUID, [ 720 ]) 255 await checkLiveCleanup(servers[0], liveVideoUUID, [ 720 ])
253 }) 256 })
254 257
255 it('Should correctly terminate the stream on blacklist and blacklist the saved replay video', async function () { 258 it('Should correctly terminate the stream on blacklist and blacklist the saved replay video', async function () {
256 this.timeout(40000) 259 this.timeout(40000)
257 260
258 liveVideoUUID = await createLiveWrapper(true) 261 liveVideoUUID = await createLiveWrapper({ permanent: false, replay: true })
259 262
260 ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) 263 ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID })
261 await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID) 264 await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID)
@@ -277,13 +280,13 @@ describe('Save replay setting', function () {
277 280
278 await wait(5000) 281 await wait(5000)
279 await waitJobs(servers) 282 await waitJobs(servers)
280 await checkLiveCleanupAfterSave(servers[0], liveVideoUUID, [ 720 ]) 283 await checkLiveCleanup(servers[0], liveVideoUUID, [ 720 ])
281 }) 284 })
282 285
283 it('Should correctly terminate the stream on delete and delete the video', async function () { 286 it('Should correctly terminate the stream on delete and delete the video', async function () {
284 this.timeout(40000) 287 this.timeout(40000)
285 288
286 liveVideoUUID = await createLiveWrapper(true) 289 liveVideoUUID = await createLiveWrapper({ permanent: false, replay: true })
287 290
288 ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) 291 ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID })
289 await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID) 292 await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID)
@@ -300,7 +303,123 @@ describe('Save replay setting', function () {
300 await waitJobs(servers) 303 await waitJobs(servers)
301 304
302 await checkVideosExist(liveVideoUUID, false, HttpStatusCode.NOT_FOUND_404) 305 await checkVideosExist(liveVideoUUID, false, HttpStatusCode.NOT_FOUND_404)
303 await checkLiveCleanupAfterSave(servers[0], liveVideoUUID, []) 306 await checkLiveCleanup(servers[0], liveVideoUUID, [])
307 })
308 })
309
310 describe('With save replay enabled on permanent live', function () {
311 let lastReplayUUID: string
312
313 it('Should correctly create and federate the "waiting for stream" live', async function () {
314 this.timeout(20000)
315
316 liveVideoUUID = await createLiveWrapper({ permanent: true, replay: true })
317
318 await waitJobs(servers)
319
320 await checkVideosExist(liveVideoUUID, false, HttpStatusCode.OK_200)
321 await checkVideoState(liveVideoUUID, VideoState.WAITING_FOR_LIVE)
322 })
323
324 it('Should correctly have updated the live and federated it when streaming in the live', async function () {
325 this.timeout(20000)
326
327 ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID })
328 await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID)
329
330 await waitJobs(servers)
331
332 await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200)
333 await checkVideoState(liveVideoUUID, VideoState.PUBLISHED)
334 })
335
336 it('Should correctly have saved the live and federated it after the streaming', async function () {
337 this.timeout(30000)
338
339 const liveDetails = await servers[0].videos.get({ id: liveVideoUUID })
340
341 await stopFfmpeg(ffmpegCommand)
342
343 await waitUntilLiveWaitingOnAllServers(servers, liveVideoUUID)
344 await waitJobs(servers)
345
346 const video = await findExternalSavedVideo(servers[0], liveDetails)
347 expect(video).to.exist
348
349 for (const server of servers) {
350 await server.videos.get({ id: video.uuid })
351 }
352
353 lastReplayUUID = video.uuid
354 })
355
356 it('Should have cleaned up the live files', async function () {
357 await checkLiveCleanup(servers[0], liveVideoUUID, [])
358 })
359
360 it('Should correctly terminate the stream on blacklist and blacklist the saved replay video', async function () {
361 this.timeout(60000)
362
363 await servers[0].videos.remove({ id: lastReplayUUID })
364
365 liveVideoUUID = await createLiveWrapper({ permanent: true, replay: true })
366
367 ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID })
368 await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID)
369
370 const liveDetails = await servers[0].videos.get({ id: liveVideoUUID })
371
372 await waitJobs(servers)
373 await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200)
374
375 await Promise.all([
376 servers[0].blacklist.add({ videoId: liveVideoUUID, reason: 'bad live', unfederate: true }),
377 testFfmpegStreamError(ffmpegCommand, true)
378 ])
379
380 await waitJobs(servers)
381 await wait(5000)
382 await waitJobs(servers)
383
384 const replay = await findExternalSavedVideo(servers[0], liveDetails)
385 expect(replay).to.exist
386
387 for (const videoId of [ liveVideoUUID, replay.uuid ]) {
388 await checkVideosExist(videoId, false)
389
390 await servers[0].videos.get({ id: videoId, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
391 await servers[1].videos.get({ id: videoId, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
392 }
393
394 await checkLiveCleanup(servers[0], liveVideoUUID, [])
395 })
396
397 it('Should correctly terminate the stream on delete and not save the video', async function () {
398 this.timeout(40000)
399
400 liveVideoUUID = await createLiveWrapper({ permanent: true, replay: true })
401
402 ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID })
403 await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID)
404
405 const liveDetails = await servers[0].videos.get({ id: liveVideoUUID })
406
407 await waitJobs(servers)
408 await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200)
409
410 await Promise.all([
411 servers[0].videos.remove({ id: liveVideoUUID }),
412 testFfmpegStreamError(ffmpegCommand, true)
413 ])
414
415 await wait(5000)
416 await waitJobs(servers)
417
418 const replay = await findExternalSavedVideo(servers[0], liveDetails)
419 expect(replay).to.not.exist
420
421 await checkVideosExist(liveVideoUUID, false, HttpStatusCode.NOT_FOUND_404)
422 await checkLiveCleanup(servers[0], liveVideoUUID, [])
304 }) 423 })
305 }) 424 })
306 425