]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/live/live.ts
Increase timeouts
[github/Chocobozzz/PeerTube.git] / server / tests / api / live / live.ts
index 7ea0ec198e4388bd0fd9b726d315c62545218505..0831f91f0f542f3a36fdea3a0c8f02d0041cf050 100644 (file)
@@ -42,8 +42,7 @@ import {
   waitJobs,
   waitUntilLiveEnded,
   waitUntilLivePublished,
-  waitUntilLiveSegmentGeneration,
-  waitUntilLog
+  waitUntilLiveSegmentGeneration
 } from '../../../../shared/extra-utils'
 
 const expect = chai.expect
@@ -51,6 +50,12 @@ const expect = chai.expect
 describe('Test live', function () {
   let servers: ServerInfo[] = []
 
+  async function waitUntilLivePublishedOnAllServers (videoId: string) {
+    for (const server of servers) {
+      await waitUntilLivePublished(server.url, server.accessToken, videoId)
+    }
+  }
+
   before(async function () {
     this.timeout(120000)
 
@@ -117,6 +122,8 @@ describe('Test live', function () {
         expect(video.channel.name).to.equal(servers[0].videoChannel.name)
         expect(video.channel.host).to.equal(servers[0].videoChannel.host)
 
+        expect(video.isLive).to.be.true
+
         expect(video.nsfw).to.be.false
         expect(video.waitTranscoding).to.be.false
         expect(video.name).to.equal('my super live')
@@ -270,6 +277,20 @@ describe('Test live', function () {
       await testFfmpegStreamError(command, false)
     })
 
+    it('Should list this live now someone stream into it', async function () {
+      for (const server of servers) {
+        const res = await getVideosList(server.url)
+
+        expect(res.body.total).to.equal(1)
+        expect(res.body.data).to.have.lengthOf(1)
+
+        const video: Video = res.body.data[0]
+
+        expect(video.name).to.equal('user live')
+        expect(video.isLive).to.be.true
+      }
+    })
+
     it('Should not allow a stream on a live that was blacklisted', async function () {
       this.timeout(30000)
 
@@ -329,7 +350,7 @@ describe('Test live', function () {
         await checkResolutionsInMasterPlaylist(hlsPlaylist.playlistUrl, resolutions)
 
         for (let i = 0; i < resolutions.length; i++) {
-          const segmentNum = 1
+          const segmentNum = 3
           const segmentName = `${i}-00000${segmentNum}.ts`
           await waitUntilLiveSegmentGeneration(servers[0], video.uuid, i, segmentNum)
 
@@ -349,7 +370,7 @@ describe('Test live', function () {
         live: {
           enabled: true,
           allowReplay: true,
-          maxDuration: null,
+          maxDuration: -1,
           transcoding: {
             enabled: true,
             resolutions: {
@@ -370,12 +391,12 @@ describe('Test live', function () {
     })
 
     it('Should enable transcoding without additional resolutions', async function () {
-      this.timeout(30000)
+      this.timeout(60000)
 
       liveVideoId = await createLiveWrapper(false)
 
       const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoId)
-      await waitUntilLivePublished(servers[0].url, servers[0].accessToken, liveVideoId)
+      await waitUntilLivePublishedOnAllServers(liveVideoId)
       await waitJobs(servers)
 
       await testVideoResolutions(liveVideoId, [ 720 ])
@@ -384,14 +405,14 @@ describe('Test live', function () {
     })
 
     it('Should enable transcoding with some resolutions', async function () {
-      this.timeout(30000)
+      this.timeout(60000)
 
       const resolutions = [ 240, 480 ]
       await updateConf(resolutions)
       liveVideoId = await createLiveWrapper(false)
 
       const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoId)
-      await waitUntilLivePublished(servers[0].url, servers[0].accessToken, liveVideoId)
+      await waitUntilLivePublishedOnAllServers(liveVideoId)
       await waitJobs(servers)
 
       await testVideoResolutions(liveVideoId, resolutions)
@@ -400,7 +421,7 @@ describe('Test live', function () {
     })
 
     it('Should enable transcoding with some resolutions and correctly save them', async function () {
-      this.timeout(120000)
+      this.timeout(200000)
 
       const resolutions = [ 240, 360, 720 ]
 
@@ -408,16 +429,18 @@ describe('Test live', function () {
       liveVideoId = await createLiveWrapper(true)
 
       const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoId, 'video_short2.webm')
-      await waitUntilLivePublished(servers[0].url, servers[0].accessToken, liveVideoId)
+      await waitUntilLivePublishedOnAllServers(liveVideoId)
       await waitJobs(servers)
 
       await testVideoResolutions(liveVideoId, resolutions)
 
       await stopFfmpeg(command)
-      await waitUntilLivePublished(servers[0].url, servers[0].accessToken, liveVideoId)
+      await waitUntilLiveEnded(servers[0].url, servers[0].accessToken, liveVideoId)
 
       await waitJobs(servers)
 
+      await waitUntilLivePublishedOnAllServers(liveVideoId)
+
       const bitrateLimits = {
         720: 5000 * 1000, // 60FPS
         360: 1100 * 1000,
@@ -428,6 +451,7 @@ describe('Test live', function () {
         const resVideo = await getVideo(server.url, liveVideoId)
         const video: VideoDetails = resVideo.body
 
+        expect(video.state.id).to.equal(VideoState.PUBLISHED)
         expect(video.duration).to.be.greaterThan(1)
         expect(video.files).to.have.lengthOf(0)
 
@@ -496,7 +520,7 @@ describe('Test live', function () {
       liveVideoId = res.body.video.uuid
 
       command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoId)
-      await waitUntilLivePublished(servers[0].url, servers[0].accessToken, liveVideoId)
+      await waitUntilLivePublishedOnAllServers(liveVideoId)
       await waitJobs(servers)
     })
 
@@ -584,10 +608,7 @@ describe('Test live', function () {
 
       const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID)
 
-      for (const server of servers) {
-        await waitUntilLivePublished(server.url, server.accessToken, liveVideoUUID)
-      }
-
+      await waitUntilLivePublishedOnAllServers(liveVideoUUID)
       await waitJobs(servers)
 
       for (const stateChanges of [ localStateChanges, remoteStateChanges ]) {
@@ -600,7 +621,6 @@ describe('Test live', function () {
       for (const server of servers) {
         await waitUntilLiveEnded(server.url, server.accessToken, liveVideoUUID)
       }
-
       await waitJobs(servers)
 
       for (const stateChanges of [ localStateChanges, remoteStateChanges ]) {
@@ -609,6 +629,52 @@ describe('Test live', function () {
       }
     })
 
+    it('Should correctly send views change notification', async function () {
+      this.timeout(60000)
+
+      let localLastVideoViews = 0
+      let remoteLastVideoViews = 0
+
+      const liveVideoUUID = await createLiveWrapper()
+      await waitJobs(servers)
+
+      {
+        const videoId = await getVideoIdFromUUID(servers[0].url, liveVideoUUID)
+
+        const localSocket = getLiveNotificationSocket(servers[0].url)
+        localSocket.on('views-change', data => { localLastVideoViews = data.views })
+        localSocket.emit('subscribe', { videoId })
+      }
+
+      {
+        const videoId = await getVideoIdFromUUID(servers[1].url, liveVideoUUID)
+
+        const remoteSocket = getLiveNotificationSocket(servers[1].url)
+        remoteSocket.on('views-change', data => { remoteLastVideoViews = data.views })
+        remoteSocket.emit('subscribe', { videoId })
+      }
+
+      const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID)
+
+      await waitUntilLivePublishedOnAllServers(liveVideoUUID)
+      await waitJobs(servers)
+
+      expect(localLastVideoViews).to.equal(0)
+      expect(remoteLastVideoViews).to.equal(0)
+
+      await viewVideo(servers[0].url, liveVideoUUID)
+      await viewVideo(servers[1].url, liveVideoUUID)
+
+      await waitJobs(servers)
+      await wait(5000)
+      await waitJobs(servers)
+
+      expect(localLastVideoViews).to.equal(2)
+      expect(remoteLastVideoViews).to.equal(2)
+
+      await stopFfmpeg(command)
+    })
+
     it('Should not receive a notification after unsubscribe', async function () {
       this.timeout(60000)
 
@@ -624,7 +690,8 @@ describe('Test live', function () {
       socket.emit('subscribe', { videoId })
 
       const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID)
-      await waitUntilLivePublished(servers[0].url, servers[0].accessToken, liveVideoUUID)
+
+      await waitUntilLivePublishedOnAllServers(liveVideoUUID)
       await waitJobs(servers)
 
       expect(stateChanges).to.have.lengthOf(1)