]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/live/live-fast-restream.ts
Fix reset sequelize instance
[github/Chocobozzz/PeerTube.git] / server / tests / api / live / live-fast-restream.ts
index b524cbe7f3ef092a6f7e60e8d4addddd27d60570..2169393c27fc0931caf8229d7726bd0af2e37083 100644 (file)
@@ -1,13 +1,11 @@
 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
-import 'mocha'
-import * as chai from 'chai'
+import { expect } from 'chai'
 import { wait } from '@shared/core-utils'
-import { HttpStatusCode, LiveVideoCreate, VideoPrivacy } from '@shared/models'
+import { LiveVideoCreate, VideoPrivacy } from '@shared/models'
 import {
   cleanupTests,
   createSingleServer,
-  makeRawRequest,
   PeerTubeServer,
   setAccessTokensToServers,
   setDefaultVideoChannel,
@@ -15,8 +13,6 @@ import {
   waitJobs
 } from '@shared/server-commands'
 
-const expect = chai.expect
-
 describe('Fast restream in live', function () {
   let server: PeerTubeServer
 
@@ -26,6 +22,7 @@ describe('Fast restream in live', function () {
       privacy: VideoPrivacy.PUBLIC,
       name: 'my super live',
       saveReplay: options.replay,
+      replaySettings: options.replay ? { privacy: VideoPrivacy.PUBLIC } : undefined,
       permanentLive: options.permanent
     }
 
@@ -46,12 +43,31 @@ describe('Fast restream in live', function () {
     // Streaming session #1
     let ffmpegCommand = await server.live.sendRTMPStreamInVideo(rtmpOptions)
     await server.live.waitUntilPublished({ videoId: liveVideoUUID })
+
+    const video = await server.videos.get({ id: liveVideoUUID })
+    const session1PlaylistId = video.streamingPlaylists[0].id
+
     await stopFfmpeg(ffmpegCommand)
     await server.live.waitUntilWaiting({ videoId: liveVideoUUID })
 
     // Streaming session #2
     ffmpegCommand = await server.live.sendRTMPStreamInVideo(rtmpOptions)
-    await server.live.waitUntilSegmentGeneration({ videoUUID: liveVideoUUID, segment: 0, playlistNumber: 0, totalSessions: 2 })
+
+    let hasNewPlaylist = false
+    do {
+      const video = await server.videos.get({ id: liveVideoUUID })
+      hasNewPlaylist = video.streamingPlaylists.length === 1 && video.streamingPlaylists[0].id !== session1PlaylistId
+
+      await wait(100)
+    } while (!hasNewPlaylist)
+
+    await server.live.waitUntilSegmentGeneration({
+      server,
+      videoUUID: liveVideoUUID,
+      segment: 1,
+      playlistNumber: 0,
+      objectStorage: false
+    })
 
     return { ffmpegCommand, liveVideoUUID }
   }
@@ -62,9 +78,15 @@ describe('Fast restream in live', function () {
       const video = await server.videos.get({ id: liveId })
       expect(video.streamingPlaylists).to.have.lengthOf(1)
 
-      await server.live.getSegment({ videoUUID: liveId, segment: 0, playlistNumber: 0 })
-      await makeRawRequest(video.streamingPlaylists[0].playlistUrl, HttpStatusCode.OK_200)
-      await makeRawRequest(video.streamingPlaylists[0].segmentsSha256Url, HttpStatusCode.OK_200)
+      try {
+        await server.live.getSegmentFile({ videoUUID: liveId, segment: 0, playlistNumber: 0 })
+        await server.streamingPlaylists.get({ url: video.streamingPlaylists[0].playlistUrl })
+        await server.streamingPlaylists.getSegmentSha256({ url: video.streamingPlaylists[0].segmentsSha256Url })
+      } catch (err) {
+        // FIXME: try to debug error in CI "Unexpected end of JSON input"
+        console.error(err)
+        throw err
+      }
 
       await wait(100)
     }
@@ -73,6 +95,9 @@ describe('Fast restream in live', function () {
   async function runTest (replay: boolean) {
     const { ffmpegCommand, liveVideoUUID } = await fastRestreamWrapper({ replay })
 
+    // TODO: remove, we try to debug a test timeout failure here
+    console.log('Ensuring last live works')
+
     await ensureLastLiveWorks(liveVideoUUID)
 
     await stopFfmpeg(ffmpegCommand)
@@ -102,7 +127,7 @@ describe('Fast restream in live', function () {
   before(async function () {
     this.timeout(120000)
 
-    const env = { 'PEERTUBE_TEST_CONSTANTS_VIDEO_LIVE_CLEANUP_DELAY': '10000' }
+    const env = { PEERTUBE_TEST_CONSTANTS_VIDEO_LIVE_CLEANUP_DELAY: '10000' }
     server = await createSingleServer(1, {}, { env })
 
     // Get the access tokens
@@ -113,8 +138,8 @@ describe('Fast restream in live', function () {
     await server.config.enableLive({ allowReplay: true, transcoding: true, resolutions: 'min' })
   })
 
-  it('Should correctly fast reastream in a permanent live with and without save replay', async function () {
-    this.timeout(240000)
+  it('Should correctly fast restream in a permanent live with and without save replay', async function () {
+    this.timeout(480000)
 
     // A test can take a long time, so prefer to run them in parallel
     await Promise.all([