aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/live/live-save-replay.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/live/live-save-replay.ts')
-rw-r--r--server/tests/api/live/live-save-replay.ts264
1 files changed, 189 insertions, 75 deletions
diff --git a/server/tests/api/live/live-save-replay.ts b/server/tests/api/live/live-save-replay.ts
index 8f17b4566..3a9a84f7e 100644
--- a/server/tests/api/live/live-save-replay.ts
+++ b/server/tests/api/live/live-save-replay.ts
@@ -27,7 +27,7 @@ describe('Save replay setting', function () {
27 let liveVideoUUID: string 27 let liveVideoUUID: string
28 let ffmpegCommand: FfmpegCommand 28 let ffmpegCommand: FfmpegCommand
29 29
30 async function createLiveWrapper (options: { permanent: boolean, replay: boolean }) { 30 async function createLiveWrapper (options: { permanent: boolean, replay: boolean, replaySettings?: { privacy: VideoPrivacy } }) {
31 if (liveVideoUUID) { 31 if (liveVideoUUID) {
32 try { 32 try {
33 await servers[0].videos.remove({ id: liveVideoUUID }) 33 await servers[0].videos.remove({ id: liveVideoUUID })
@@ -40,6 +40,7 @@ describe('Save replay setting', function () {
40 privacy: VideoPrivacy.PUBLIC, 40 privacy: VideoPrivacy.PUBLIC,
41 name: 'my super live', 41 name: 'my super live',
42 saveReplay: options.replay, 42 saveReplay: options.replay,
43 replaySettings: options.replaySettings,
43 permanentLive: options.permanent 44 permanentLive: options.permanent
44 } 45 }
45 46
@@ -47,7 +48,7 @@ describe('Save replay setting', function () {
47 return uuid 48 return uuid
48 } 49 }
49 50
50 async function publishLive (options: { permanent: boolean, replay: boolean }) { 51 async function publishLive (options: { permanent: boolean, replay: boolean, replaySettings?: { privacy: VideoPrivacy } }) {
51 liveVideoUUID = await createLiveWrapper(options) 52 liveVideoUUID = await createLiveWrapper(options)
52 53
53 const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) 54 const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID })
@@ -61,7 +62,7 @@ describe('Save replay setting', function () {
61 return { ffmpegCommand, liveDetails } 62 return { ffmpegCommand, liveDetails }
62 } 63 }
63 64
64 async function publishLiveAndDelete (options: { permanent: boolean, replay: boolean }) { 65 async function publishLiveAndDelete (options: { permanent: boolean, replay: boolean, replaySettings?: { privacy: VideoPrivacy } }) {
65 const { ffmpegCommand, liveDetails } = await publishLive(options) 66 const { ffmpegCommand, liveDetails } = await publishLive(options)
66 67
67 await Promise.all([ 68 await Promise.all([
@@ -76,7 +77,7 @@ describe('Save replay setting', function () {
76 return { liveDetails } 77 return { liveDetails }
77 } 78 }
78 79
79 async function publishLiveAndBlacklist (options: { permanent: boolean, replay: boolean }) { 80 async function publishLiveAndBlacklist (options: { permanent: boolean, replay: boolean, replaySettings?: { privacy: VideoPrivacy } }) {
80 const { ffmpegCommand, liveDetails } = await publishLive(options) 81 const { ffmpegCommand, liveDetails } = await publishLive(options)
81 82
82 await Promise.all([ 83 await Promise.all([
@@ -112,6 +113,13 @@ describe('Save replay setting', function () {
112 } 113 }
113 } 114 }
114 115
116 async function checkVideoPrivacy (videoId: string, privacy: VideoPrivacy) {
117 for (const server of servers) {
118 const video = await server.videos.get({ id: videoId })
119 expect(video.privacy.id).to.equal(privacy)
120 }
121 }
122
115 before(async function () { 123 before(async function () {
116 this.timeout(120000) 124 this.timeout(120000)
117 125
@@ -247,12 +255,13 @@ describe('Save replay setting', function () {
247 it('Should correctly create and federate the "waiting for stream" live', async function () { 255 it('Should correctly create and federate the "waiting for stream" live', async function () {
248 this.timeout(20000) 256 this.timeout(20000)
249 257
250 liveVideoUUID = await createLiveWrapper({ permanent: false, replay: true }) 258 liveVideoUUID = await createLiveWrapper({ permanent: false, replay: true, replaySettings: { privacy: VideoPrivacy.UNLISTED } })
251 259
252 await waitJobs(servers) 260 await waitJobs(servers)
253 261
254 await checkVideosExist(liveVideoUUID, false, HttpStatusCode.OK_200) 262 await checkVideosExist(liveVideoUUID, false, HttpStatusCode.OK_200)
255 await checkVideoState(liveVideoUUID, VideoState.WAITING_FOR_LIVE) 263 await checkVideoState(liveVideoUUID, VideoState.WAITING_FOR_LIVE)
264 await checkVideoPrivacy(liveVideoUUID, VideoPrivacy.PUBLIC)
256 }) 265 })
257 266
258 it('Should correctly have updated the live and federated it when streaming in the live', async function () { 267 it('Should correctly have updated the live and federated it when streaming in the live', async function () {
@@ -265,6 +274,7 @@ describe('Save replay setting', function () {
265 274
266 await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) 275 await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200)
267 await checkVideoState(liveVideoUUID, VideoState.PUBLISHED) 276 await checkVideoState(liveVideoUUID, VideoState.PUBLISHED)
277 await checkVideoPrivacy(liveVideoUUID, VideoPrivacy.PUBLIC)
268 }) 278 })
269 279
270 it('Should correctly have saved the live and federated it after the streaming', async function () { 280 it('Should correctly have saved the live and federated it after the streaming', async function () {
@@ -274,6 +284,8 @@ describe('Save replay setting', function () {
274 expect(session.endDate).to.not.exist 284 expect(session.endDate).to.not.exist
275 expect(session.endingProcessed).to.be.false 285 expect(session.endingProcessed).to.be.false
276 expect(session.saveReplay).to.be.true 286 expect(session.saveReplay).to.be.true
287 expect(session.replaySettings).to.exist
288 expect(session.replaySettings.privacy).to.equal(VideoPrivacy.UNLISTED)
277 289
278 await stopFfmpeg(ffmpegCommand) 290 await stopFfmpeg(ffmpegCommand)
279 291
@@ -281,8 +293,9 @@ describe('Save replay setting', function () {
281 await waitJobs(servers) 293 await waitJobs(servers)
282 294
283 // Live has been transcoded 295 // Live has been transcoded
284 await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) 296 await checkVideosExist(liveVideoUUID, false, HttpStatusCode.OK_200)
285 await checkVideoState(liveVideoUUID, VideoState.PUBLISHED) 297 await checkVideoState(liveVideoUUID, VideoState.PUBLISHED)
298 await checkVideoPrivacy(liveVideoUUID, VideoPrivacy.UNLISTED)
286 }) 299 })
287 300
288 it('Should find the replay live session', async function () { 301 it('Should find the replay live session', async function () {
@@ -296,6 +309,8 @@ describe('Save replay setting', function () {
296 expect(session.error).to.not.exist 309 expect(session.error).to.not.exist
297 expect(session.saveReplay).to.be.true 310 expect(session.saveReplay).to.be.true
298 expect(session.endingProcessed).to.be.true 311 expect(session.endingProcessed).to.be.true
312 expect(session.replaySettings).to.exist
313 expect(session.replaySettings.privacy).to.equal(VideoPrivacy.UNLISTED)
299 314
300 expect(session.replayVideo).to.exist 315 expect(session.replayVideo).to.exist
301 expect(session.replayVideo.id).to.exist 316 expect(session.replayVideo.id).to.exist
@@ -306,13 +321,14 @@ describe('Save replay setting', function () {
306 it('Should update the saved live and correctly federate the updated attributes', async function () { 321 it('Should update the saved live and correctly federate the updated attributes', async function () {
307 this.timeout(30000) 322 this.timeout(30000)
308 323
309 await servers[0].videos.update({ id: liveVideoUUID, attributes: { name: 'video updated' } }) 324 await servers[0].videos.update({ id: liveVideoUUID, attributes: { name: 'video updated', privacy: VideoPrivacy.PUBLIC } })
310 await waitJobs(servers) 325 await waitJobs(servers)
311 326
312 for (const server of servers) { 327 for (const server of servers) {
313 const video = await server.videos.get({ id: liveVideoUUID }) 328 const video = await server.videos.get({ id: liveVideoUUID })
314 expect(video.name).to.equal('video updated') 329 expect(video.name).to.equal('video updated')
315 expect(video.isLive).to.be.false 330 expect(video.isLive).to.be.false
331 expect(video.privacy.id).to.equal(VideoPrivacy.PUBLIC)
316 } 332 }
317 }) 333 })
318 334
@@ -323,7 +339,7 @@ describe('Save replay setting', function () {
323 it('Should correctly terminate the stream on blacklist and blacklist the saved replay video', async function () { 339 it('Should correctly terminate the stream on blacklist and blacklist the saved replay video', async function () {
324 this.timeout(120000) 340 this.timeout(120000)
325 341
326 await publishLiveAndBlacklist({ permanent: false, replay: true }) 342 await publishLiveAndBlacklist({ permanent: false, replay: true, replaySettings: { privacy: VideoPrivacy.PUBLIC } })
327 343
328 await checkVideosExist(liveVideoUUID, false) 344 await checkVideosExist(liveVideoUUID, false)
329 345
@@ -338,7 +354,7 @@ describe('Save replay setting', function () {
338 it('Should correctly terminate the stream on delete and delete the video', async function () { 354 it('Should correctly terminate the stream on delete and delete the video', async function () {
339 this.timeout(40000) 355 this.timeout(40000)
340 356
341 await publishLiveAndDelete({ permanent: false, replay: true }) 357 await publishLiveAndDelete({ permanent: false, replay: true, replaySettings: { privacy: VideoPrivacy.PUBLIC } })
342 358
343 await checkVideosExist(liveVideoUUID, false, HttpStatusCode.NOT_FOUND_404) 359 await checkVideosExist(liveVideoUUID, false, HttpStatusCode.NOT_FOUND_404)
344 await checkLiveCleanup({ server: servers[0], videoUUID: liveVideoUUID, permanent: false }) 360 await checkLiveCleanup({ server: servers[0], videoUUID: liveVideoUUID, permanent: false })
@@ -348,103 +364,201 @@ describe('Save replay setting', function () {
348 describe('With save replay enabled on permanent live', function () { 364 describe('With save replay enabled on permanent live', function () {
349 let lastReplayUUID: string 365 let lastReplayUUID: string
350 366
351 it('Should correctly create and federate the "waiting for stream" live', async function () { 367 describe('With a first live and its replay', function () {
352 this.timeout(20000)
353 368
354 liveVideoUUID = await createLiveWrapper({ permanent: true, replay: true }) 369 it('Should correctly create and federate the "waiting for stream" live', async function () {
370 this.timeout(20000)
355 371
356 await waitJobs(servers) 372 liveVideoUUID = await createLiveWrapper({ permanent: true, replay: true, replaySettings: { privacy: VideoPrivacy.UNLISTED } })
357 373
358 await checkVideosExist(liveVideoUUID, false, HttpStatusCode.OK_200) 374 await waitJobs(servers)
359 await checkVideoState(liveVideoUUID, VideoState.WAITING_FOR_LIVE)
360 })
361 375
362 it('Should correctly have updated the live and federated it when streaming in the live', async function () { 376 await checkVideosExist(liveVideoUUID, false, HttpStatusCode.OK_200)
363 this.timeout(20000) 377 await checkVideoState(liveVideoUUID, VideoState.WAITING_FOR_LIVE)
378 await checkVideoPrivacy(liveVideoUUID, VideoPrivacy.PUBLIC)
379 })
364 380
365 ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) 381 it('Should correctly have updated the live and federated it when streaming in the live', async function () {
366 await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID) 382 this.timeout(20000)
367 383
368 await waitJobs(servers) 384 ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID })
385 await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID)
369 386
370 await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) 387 await waitJobs(servers)
371 await checkVideoState(liveVideoUUID, VideoState.PUBLISHED)
372 })
373 388
374 it('Should correctly have saved the live and federated it after the streaming', async function () { 389 await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200)
375 this.timeout(30000) 390 await checkVideoState(liveVideoUUID, VideoState.PUBLISHED)
391 await checkVideoPrivacy(liveVideoUUID, VideoPrivacy.PUBLIC)
392 })
376 393
377 const liveDetails = await servers[0].videos.get({ id: liveVideoUUID }) 394 it('Should correctly have saved the live and federated it after the streaming', async function () {
395 this.timeout(30000)
378 396
379 await stopFfmpeg(ffmpegCommand) 397 const liveDetails = await servers[0].videos.get({ id: liveVideoUUID })
380 398
381 await waitUntilLiveWaitingOnAllServers(servers, liveVideoUUID) 399 await stopFfmpeg(ffmpegCommand)
382 await waitJobs(servers)
383 400
384 const video = await findExternalSavedVideo(servers[0], liveDetails) 401 await waitUntilLiveWaitingOnAllServers(servers, liveVideoUUID)
385 expect(video).to.exist 402 await waitJobs(servers)
386 403
387 for (const server of servers) { 404 const video = await findExternalSavedVideo(servers[0], liveDetails)
388 await server.videos.get({ id: video.uuid }) 405 expect(video).to.exist
389 }
390 406
391 lastReplayUUID = video.uuid 407 for (const server of servers) {
392 }) 408 await server.videos.get({ id: video.uuid })
409 }
393 410
394 it('Should have appropriate ended session and replay live session', async function () { 411 lastReplayUUID = video.uuid
395 const { data, total } = await servers[0].live.listSessions({ videoId: liveVideoUUID }) 412 })
396 expect(total).to.equal(1)
397 expect(data).to.have.lengthOf(1)
398 413
399 const sessionFromLive = data[0] 414 it('Should have appropriate ended session and replay live session', async function () {
400 const sessionFromReplay = await servers[0].live.getReplaySession({ videoId: lastReplayUUID }) 415 const { data, total } = await servers[0].live.listSessions({ videoId: liveVideoUUID })
416 expect(total).to.equal(1)
417 expect(data).to.have.lengthOf(1)
401 418
402 for (const session of [ sessionFromLive, sessionFromReplay ]) { 419 const sessionFromLive = data[0]
403 expect(session.startDate).to.exist 420 const sessionFromReplay = await servers[0].live.getReplaySession({ videoId: lastReplayUUID })
404 expect(session.endDate).to.exist
405 421
406 expect(session.error).to.not.exist 422 for (const session of [ sessionFromLive, sessionFromReplay ]) {
423 expect(session.startDate).to.exist
424 expect(session.endDate).to.exist
407 425
408 expect(session.replayVideo).to.exist 426 expect(session.replaySettings).to.exist
409 expect(session.replayVideo.id).to.exist 427 expect(session.replaySettings.privacy).to.equal(VideoPrivacy.UNLISTED)
410 expect(session.replayVideo.shortUUID).to.exist
411 expect(session.replayVideo.uuid).to.equal(lastReplayUUID)
412 }
413 })
414 428
415 it('Should have cleaned up the live files', async function () { 429 expect(session.error).to.not.exist
416 await checkLiveCleanup({ server: servers[0], videoUUID: liveVideoUUID, permanent: false }) 430
431 expect(session.replayVideo).to.exist
432 expect(session.replayVideo.id).to.exist
433 expect(session.replayVideo.shortUUID).to.exist
434 expect(session.replayVideo.uuid).to.equal(lastReplayUUID)
435 }
436 })
437
438 it('Should have the first live replay with correct settings', async function () {
439 await checkVideosExist(lastReplayUUID, false, HttpStatusCode.OK_200)
440 await checkVideoState(lastReplayUUID, VideoState.PUBLISHED)
441 await checkVideoPrivacy(lastReplayUUID, VideoPrivacy.UNLISTED)
442 })
417 }) 443 })
418 444
419 it('Should correctly terminate the stream on blacklist and blacklist the saved replay video', async function () { 445 describe('With a second live and its replay', function () {
420 this.timeout(120000) 446 it('Should update the replay settings', async function () {
447 await servers[0].live.update(
448 { videoId: liveVideoUUID, fields: { replaySettings: { privacy: VideoPrivacy.PUBLIC } } })
449 await waitJobs(servers)
450 const live = await servers[0].live.get({ videoId: liveVideoUUID })
421 451
422 await servers[0].videos.remove({ id: lastReplayUUID }) 452 expect(live.saveReplay).to.be.true
423 const { liveDetails } = await publishLiveAndBlacklist({ permanent: true, replay: true }) 453 expect(live.replaySettings).to.exist
454 expect(live.replaySettings.privacy).to.equal(VideoPrivacy.PUBLIC)
424 455
425 const replay = await findExternalSavedVideo(servers[0], liveDetails) 456 })
426 expect(replay).to.exist
427 457
428 for (const videoId of [ liveVideoUUID, replay.uuid ]) { 458 it('Should correctly have updated the live and federated it when streaming in the live', async function () {
429 await checkVideosExist(videoId, false) 459 this.timeout(20000)
430 460
431 await servers[0].videos.get({ id: videoId, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) 461 ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID })
432 await servers[1].videos.get({ id: videoId, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) 462 await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID)
433 }
434 463
435 await checkLiveCleanup({ server: servers[0], videoUUID: liveVideoUUID, permanent: false }) 464 await waitJobs(servers)
436 })
437 465
438 it('Should correctly terminate the stream on delete and not save the video', async function () { 466 await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200)
439 this.timeout(40000) 467 await checkVideoState(liveVideoUUID, VideoState.PUBLISHED)
468 await checkVideoPrivacy(liveVideoUUID, VideoPrivacy.PUBLIC)
469 })
440 470
441 const { liveDetails } = await publishLiveAndDelete({ permanent: true, replay: true }) 471 it('Should correctly have saved the live and federated it after the streaming', async function () {
472 this.timeout(30000)
473 const liveDetails = await servers[0].videos.get({ id: liveVideoUUID })
442 474
443 const replay = await findExternalSavedVideo(servers[0], liveDetails) 475 await stopFfmpeg(ffmpegCommand)
444 expect(replay).to.not.exist
445 476
446 await checkVideosExist(liveVideoUUID, false, HttpStatusCode.NOT_FOUND_404) 477 await waitUntilLiveWaitingOnAllServers(servers, liveVideoUUID)
447 await checkLiveCleanup({ server: servers[0], videoUUID: liveVideoUUID, permanent: false }) 478 await waitJobs(servers)
479
480 const video = await findExternalSavedVideo(servers[0], liveDetails)
481 expect(video).to.exist
482
483 for (const server of servers) {
484 await server.videos.get({ id: video.uuid })
485 }
486
487 lastReplayUUID = video.uuid
488 })
489
490 it('Should have appropriate ended session and replay live session', async function () {
491 const { data, total } = await servers[0].live.listSessions({ videoId: liveVideoUUID })
492 expect(total).to.equal(2)
493 expect(data).to.have.lengthOf(2)
494
495 const sessionFromLive = data[1]
496 const sessionFromReplay = await servers[0].live.getReplaySession({ videoId: lastReplayUUID })
497
498 for (const session of [ sessionFromLive, sessionFromReplay ]) {
499 expect(session.startDate).to.exist
500 expect(session.endDate).to.exist
501
502 expect(session.replaySettings).to.exist
503 expect(session.replaySettings.privacy).to.equal(VideoPrivacy.PUBLIC)
504
505 expect(session.error).to.not.exist
506
507 expect(session.replayVideo).to.exist
508 expect(session.replayVideo.id).to.exist
509 expect(session.replayVideo.shortUUID).to.exist
510 expect(session.replayVideo.uuid).to.equal(lastReplayUUID)
511 }
512 })
513
514 it('Should have the first live replay with correct settings', async function () {
515 await checkVideosExist(lastReplayUUID, true, HttpStatusCode.OK_200)
516 await checkVideoState(lastReplayUUID, VideoState.PUBLISHED)
517 await checkVideoPrivacy(lastReplayUUID, VideoPrivacy.PUBLIC)
518 })
519
520 it('Should have cleaned up the live files', async function () {
521 await checkLiveCleanup({ server: servers[0], videoUUID: liveVideoUUID, permanent: false })
522 })
523
524 it('Should correctly terminate the stream on blacklist and blacklist the saved replay video', async function () {
525 this.timeout(120000)
526
527 await servers[0].videos.remove({ id: lastReplayUUID })
528 const { liveDetails } = await publishLiveAndBlacklist({
529 permanent: true,
530 replay: true,
531 replaySettings: { privacy: VideoPrivacy.PUBLIC }
532 })
533
534 const replay = await findExternalSavedVideo(servers[0], liveDetails)
535 expect(replay).to.exist
536
537 for (const videoId of [ liveVideoUUID, replay.uuid ]) {
538 await checkVideosExist(videoId, false)
539
540 await servers[0].videos.get({ id: videoId, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
541 await servers[1].videos.get({ id: videoId, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
542 }
543
544 await checkLiveCleanup({ server: servers[0], videoUUID: liveVideoUUID, permanent: false })
545 })
546
547 it('Should correctly terminate the stream on delete and not save the video', async function () {
548 this.timeout(40000)
549
550 const { liveDetails } = await publishLiveAndDelete({
551 permanent: true,
552 replay: true,
553 replaySettings: { privacy: VideoPrivacy.PUBLIC }
554 })
555
556 const replay = await findExternalSavedVideo(servers[0], liveDetails)
557 expect(replay).to.not.exist
558
559 await checkVideosExist(liveVideoUUID, false, HttpStatusCode.NOT_FOUND_404)
560 await checkLiveCleanup({ server: servers[0], videoUUID: liveVideoUUID, permanent: false })
561 })
448 }) 562 })
449 }) 563 })
450 564