]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/live/live-save-replay.ts
Introduce blacklist command
[github/Chocobozzz/PeerTube.git] / server / tests / api / live / live-save-replay.ts
index 3ffa0c093ccb721cab69aa589c380d505acc8129..363fb561c502b21210ab397e5d68a7d0c5f82170 100644 (file)
@@ -4,26 +4,24 @@ import 'mocha'
 import * as chai from 'chai'
 import { FfmpegCommand } from 'fluent-ffmpeg'
 import { LiveVideoCreate, VideoDetails, VideoPrivacy, VideoState } from '@shared/models'
+import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
 import {
-  addVideoToBlacklist,
   checkLiveCleanup,
   cleanupTests,
-  createLive,
+  ConfigCommand,
   doubleFollow,
   flushAndRunMultipleServers,
   getVideo,
   getVideosList,
   removeVideo,
-  sendRTMPStreamInVideo,
   ServerInfo,
   setAccessTokensToServers,
   setDefaultVideoChannel,
   stopFfmpeg,
   testFfmpegStreamError,
-  updateCustomSubConfig,
   updateVideo,
-  waitJobs,
-  waitUntilLiveStarts
+  wait,
+  waitJobs
 } from '../../../../shared/extra-utils'
 
 const expect = chai.expect
@@ -48,8 +46,8 @@ describe('Save replay setting', function () {
       saveReplay
     }
 
-    const res = await createLive(servers[0].url, servers[0].accessToken, attributes)
-    return res.body.video.uuid
+    const { uuid } = await servers[0].liveCommand.create({ fields: attributes })
+    return uuid
   }
 
   async function checkVideosExist (videoId: string, existsInList: boolean, getStatus?: number) {
@@ -73,6 +71,18 @@ describe('Save replay setting', function () {
     }
   }
 
+  async function waitUntilLivePublishedOnAllServers (videoId: string) {
+    for (const server of servers) {
+      await server.liveCommand.waitUntilPublished({ videoId })
+    }
+  }
+
+  async function waitUntilLiveSavedOnAllServers (videoId: string) {
+    for (const server of servers) {
+      await server.liveCommand.waitUntilSaved({ videoId })
+    }
+  }
+
   before(async function () {
     this.timeout(120000)
 
@@ -85,20 +95,15 @@ describe('Save replay setting', function () {
     // Server 1 and server 2 follow each other
     await doubleFollow(servers[0], servers[1])
 
-    await updateCustomSubConfig(servers[0].url, servers[0].accessToken, {
-      live: {
-        enabled: true,
-        allowReplay: true,
-        maxDuration: null,
-        transcoding: {
-          enabled: false,
-          resolutions: {
-            '240p': true,
-            '360p': true,
-            '480p': true,
-            '720p': true,
-            '1080p': true,
-            '2160p': true
+    await servers[0].configCommand.updateCustomSubConfig({
+      newConfig: {
+        live: {
+          enabled: true,
+          allowReplay: true,
+          maxDuration: -1,
+          transcoding: {
+            enabled: false,
+            resolutions: ConfigCommand.getCustomConfigResolutions(true)
           }
         }
       }
@@ -118,31 +123,35 @@ describe('Save replay setting', function () {
 
       await waitJobs(servers)
 
-      await checkVideosExist(liveVideoUUID, false, 200)
+      await checkVideosExist(liveVideoUUID, false, HttpStatusCode.OK_200)
       await checkVideoState(liveVideoUUID, VideoState.WAITING_FOR_LIVE)
     })
 
     it('Should correctly have updated the live and federated it when streaming in the live', async function () {
-      this.timeout(20000)
+      this.timeout(30000)
 
-      ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID)
-      await waitUntilLiveStarts(servers[0].url, servers[0].accessToken, liveVideoUUID)
+      ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoUUID })
+
+      await waitUntilLivePublishedOnAllServers(liveVideoUUID)
 
       await waitJobs(servers)
 
-      await checkVideosExist(liveVideoUUID, true, 200)
+      await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200)
       await checkVideoState(liveVideoUUID, VideoState.PUBLISHED)
     })
 
     it('Should correctly delete the video files after the stream ended', async function () {
-      this.timeout(30000)
+      this.timeout(40000)
 
       await stopFfmpeg(ffmpegCommand)
 
+      for (const server of servers) {
+        await server.liveCommand.waitUntilEnded({ videoId: liveVideoUUID })
+      }
       await waitJobs(servers)
 
       // Live still exist, but cannot be played anymore
-      await checkVideosExist(liveVideoUUID, false, 200)
+      await checkVideosExist(liveVideoUUID, false, HttpStatusCode.OK_200)
       await checkVideoState(liveVideoUUID, VideoState.LIVE_ENDED)
 
       // No resolutions saved since we did not save replay
@@ -154,14 +163,15 @@ describe('Save replay setting', function () {
 
       liveVideoUUID = await createLiveWrapper(false)
 
-      ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID)
-      await waitUntilLiveStarts(servers[0].url, servers[0].accessToken, liveVideoUUID)
+      ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoUUID })
+
+      await waitUntilLivePublishedOnAllServers(liveVideoUUID)
 
       await waitJobs(servers)
-      await checkVideosExist(liveVideoUUID, true, 200)
+      await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200)
 
       await Promise.all([
-        addVideoToBlacklist(servers[0].url, servers[0].accessToken, liveVideoUUID, 'bad live', true),
+        servers[0].blacklistCommand.add({ videoId: liveVideoUUID, reason: 'bad live', unfederate: true }),
         testFfmpegStreamError(ffmpegCommand, true)
       ])
 
@@ -169,9 +179,11 @@ describe('Save replay setting', function () {
 
       await checkVideosExist(liveVideoUUID, false)
 
-      await getVideo(servers[0].url, liveVideoUUID, 401)
-      await getVideo(servers[1].url, liveVideoUUID, 404)
+      await getVideo(servers[0].url, liveVideoUUID, HttpStatusCode.UNAUTHORIZED_401)
+      await getVideo(servers[1].url, liveVideoUUID, HttpStatusCode.NOT_FOUND_404)
 
+      await wait(5000)
+      await waitJobs(servers)
       await checkLiveCleanup(servers[0], liveVideoUUID, [])
     })
 
@@ -180,20 +192,22 @@ describe('Save replay setting', function () {
 
       liveVideoUUID = await createLiveWrapper(false)
 
-      ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID)
-      await waitUntilLiveStarts(servers[0].url, servers[0].accessToken, liveVideoUUID)
+      ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoUUID })
+
+      await waitUntilLivePublishedOnAllServers(liveVideoUUID)
 
       await waitJobs(servers)
-      await checkVideosExist(liveVideoUUID, true, 200)
+      await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200)
 
       await Promise.all([
         testFfmpegStreamError(ffmpegCommand, true),
         removeVideo(servers[0].url, servers[0].accessToken, liveVideoUUID)
       ])
 
+      await wait(5000)
       await waitJobs(servers)
 
-      await checkVideosExist(liveVideoUUID, false, 404)
+      await checkVideosExist(liveVideoUUID, false, HttpStatusCode.NOT_FOUND_404)
       await checkLiveCleanup(servers[0], liveVideoUUID, [])
     })
   })
@@ -207,19 +221,19 @@ describe('Save replay setting', function () {
 
       await waitJobs(servers)
 
-      await checkVideosExist(liveVideoUUID, false, 200)
+      await checkVideosExist(liveVideoUUID, false, HttpStatusCode.OK_200)
       await checkVideoState(liveVideoUUID, VideoState.WAITING_FOR_LIVE)
     })
 
     it('Should correctly have updated the live and federated it when streaming in the live', async function () {
       this.timeout(20000)
 
-      ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID)
-      await waitUntilLiveStarts(servers[0].url, servers[0].accessToken, liveVideoUUID)
+      ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoUUID })
+      await waitUntilLivePublishedOnAllServers(liveVideoUUID)
 
       await waitJobs(servers)
 
-      await checkVideosExist(liveVideoUUID, true, 200)
+      await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200)
       await checkVideoState(liveVideoUUID, VideoState.PUBLISHED)
     })
 
@@ -228,10 +242,11 @@ describe('Save replay setting', function () {
 
       await stopFfmpeg(ffmpegCommand)
 
+      await waitUntilLiveSavedOnAllServers(liveVideoUUID)
       await waitJobs(servers)
 
       // Live has been transcoded
-      await checkVideosExist(liveVideoUUID, true, 200)
+      await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200)
       await checkVideoState(liveVideoUUID, VideoState.PUBLISHED)
     })
 
@@ -257,14 +272,14 @@ describe('Save replay setting', function () {
 
       liveVideoUUID = await createLiveWrapper(true)
 
-      ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID)
-      await waitUntilLiveStarts(servers[0].url, servers[0].accessToken, liveVideoUUID)
+      ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoUUID })
+      await waitUntilLivePublishedOnAllServers(liveVideoUUID)
 
       await waitJobs(servers)
-      await checkVideosExist(liveVideoUUID, true, 200)
+      await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200)
 
       await Promise.all([
-        addVideoToBlacklist(servers[0].url, servers[0].accessToken, liveVideoUUID, 'bad live', true),
+        servers[0].blacklistCommand.add({ videoId: liveVideoUUID, reason: 'bad live', unfederate: true }),
         testFfmpegStreamError(ffmpegCommand, true)
       ])
 
@@ -272,9 +287,11 @@ describe('Save replay setting', function () {
 
       await checkVideosExist(liveVideoUUID, false)
 
-      await getVideo(servers[0].url, liveVideoUUID, 401)
-      await getVideo(servers[1].url, liveVideoUUID, 404)
+      await getVideo(servers[0].url, liveVideoUUID, HttpStatusCode.UNAUTHORIZED_401)
+      await getVideo(servers[1].url, liveVideoUUID, HttpStatusCode.NOT_FOUND_404)
 
+      await wait(5000)
+      await waitJobs(servers)
       await checkLiveCleanup(servers[0], liveVideoUUID, [ 720 ])
     })
 
@@ -283,20 +300,21 @@ describe('Save replay setting', function () {
 
       liveVideoUUID = await createLiveWrapper(true)
 
-      ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID)
-      await waitUntilLiveStarts(servers[0].url, servers[0].accessToken, liveVideoUUID)
+      ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoUUID })
+      await waitUntilLivePublishedOnAllServers(liveVideoUUID)
 
       await waitJobs(servers)
-      await checkVideosExist(liveVideoUUID, true, 200)
+      await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200)
 
       await Promise.all([
         removeVideo(servers[0].url, servers[0].accessToken, liveVideoUUID),
         testFfmpegStreamError(ffmpegCommand, true)
       ])
 
+      await wait(5000)
       await waitJobs(servers)
 
-      await checkVideosExist(liveVideoUUID, false, 404)
+      await checkVideosExist(liveVideoUUID, false, HttpStatusCode.NOT_FOUND_404)
       await checkLiveCleanup(servers[0], liveVideoUUID, [])
     })
   })