]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/live/live.ts
Fix live replay duration glitch
[github/Chocobozzz/PeerTube.git] / server / tests / api / live / live.ts
index e685be08ee1daf8d081e1c1ef89518195ed7c4d0..23f8d2be1ccc1fea394e1d584479211050eaac88 100644 (file)
@@ -39,6 +39,8 @@ import {
   viewVideo,
   wait,
   waitJobs,
+  waitUntilLiveEnded,
+  waitUntilLivePublished,
   waitUntilLiveStarts,
   waitUntilLog
 } from '../../../../shared/extra-utils'
@@ -396,7 +398,7 @@ describe('Test live', function () {
     })
 
     it('Should enable transcoding with some resolutions and correctly save them', async function () {
-      this.timeout(60000)
+      this.timeout(120000)
 
       const resolutions = [ 240, 360, 720 ]
 
@@ -410,13 +412,14 @@ describe('Test live', function () {
       await testVideoResolutions(liveVideoId, resolutions)
 
       await stopFfmpeg(command)
+      await waitUntilLivePublished(servers[0].url, servers[0].accessToken, liveVideoId)
 
       await waitJobs(servers)
 
       const bitrateLimits = {
-        720: 2800 * 1000,
-        360: 780 * 1000,
-        240: 320 * 1000
+        720: 4000 * 1000, // 60FPS
+        360: 1100 * 1000,
+        240: 600 * 1000
       }
 
       for (const server of servers) {
@@ -427,6 +430,8 @@ describe('Test live', function () {
         expect(video.files).to.have.lengthOf(0)
 
         const hlsPlaylist = video.streamingPlaylists.find(s => s.type === VideoStreamingPlaylistType.HLS)
+        await makeRawRequest(hlsPlaylist.playlistUrl, 200)
+        await makeRawRequest(hlsPlaylist.segmentsSha256Url, 200)
 
         expect(hlsPlaylist.files).to.have.lengthOf(resolutions.length)
 
@@ -434,15 +439,20 @@ describe('Test live', function () {
           const file = hlsPlaylist.files.find(f => f.resolution.id === resolution)
 
           expect(file).to.exist
-          expect(file.fps).to.be.approximately(30, 5)
           expect(file.size).to.be.greaterThan(1)
 
+          if (resolution >= 720) {
+            expect(file.fps).to.be.approximately(60, 2)
+          } else {
+            expect(file.fps).to.be.approximately(30, 2)
+          }
+
           const filename = `${video.uuid}-${resolution}-fragmented.mp4`
           const segmentPath = buildServerDirectory(servers[0], join('streaming-playlists', 'hls', video.uuid, filename))
 
           const probe = await ffprobePromise(segmentPath)
           const videoStream = await getVideoStreamFromFile(segmentPath, probe)
-          console.log(videoStream)
+
           expect(probe.format.bit_rate).to.be.below(bitrateLimits[videoStream.height])
 
           await makeRawRequest(file.torrentUrl, 200)
@@ -571,20 +581,29 @@ describe('Test live', function () {
       }
 
       const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID)
-      await waitUntilLiveStarts(servers[0].url, servers[0].accessToken, liveVideoUUID)
+
+      for (const server of servers) {
+        await waitUntilLiveStarts(server.url, server.accessToken, liveVideoUUID)
+      }
+
       await waitJobs(servers)
 
       for (const stateChanges of [ localStateChanges, remoteStateChanges ]) {
-        expect(stateChanges).to.have.lengthOf(1)
-        expect(stateChanges[0]).to.equal(VideoState.PUBLISHED)
+        expect(stateChanges).to.have.length.at.least(1)
+        expect(stateChanges[stateChanges.length - 1]).to.equal(VideoState.PUBLISHED)
       }
 
       await stopFfmpeg(command)
+
+      for (const server of servers) {
+        await waitUntilLiveEnded(server.url, server.accessToken, liveVideoUUID)
+      }
+
       await waitJobs(servers)
 
       for (const stateChanges of [ localStateChanges, remoteStateChanges ]) {
-        expect(stateChanges).to.have.lengthOf(2)
-        expect(stateChanges[1]).to.equal(VideoState.LIVE_ENDED)
+        expect(stateChanges).to.have.length.at.least(2)
+        expect(stateChanges[stateChanges.length - 1]).to.equal(VideoState.LIVE_ENDED)
       }
     })