]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/live/live-permanent.ts
Increase timeout
[github/Chocobozzz/PeerTube.git] / server / tests / api / live / live-permanent.ts
index 707f2edf8f16afa53c04362cfb9f88f8133781dd..4203b1bfcf5b9eeb21fa83cca48a5da9a3abbadb 100644 (file)
@@ -1,43 +1,41 @@
 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
-import 'mocha'
-import * as chai from 'chai'
+import { expect } from 'chai'
+import { checkLiveCleanup } from '@server/tests/shared'
+import { wait } from '@shared/core-utils'
 import { LiveVideoCreate, VideoPrivacy, VideoState } from '@shared/models'
 import {
   cleanupTests,
   ConfigCommand,
+  createMultipleServers,
   doubleFollow,
-  flushAndRunMultipleServers,
-  ServerInfo,
+  PeerTubeServer,
   setAccessTokensToServers,
   setDefaultVideoChannel,
   stopFfmpeg,
-  wait,
   waitJobs
-} from '../../../../shared/extra-utils'
-
-const expect = chai.expect
+} from '@shared/server-commands'
 
 describe('Permanent live', function () {
-  let servers: ServerInfo[] = []
+  let servers: PeerTubeServer[] = []
   let videoUUID: string
 
   async function createLiveWrapper (permanentLive: boolean) {
     const attributes: LiveVideoCreate = {
-      channelId: servers[0].videoChannel.id,
+      channelId: servers[0].store.channel.id,
       privacy: VideoPrivacy.PUBLIC,
       name: 'my super live',
       saveReplay: false,
       permanentLive
     }
 
-    const { uuid } = await servers[0].liveCommand.create({ fields: attributes })
+    const { uuid } = await servers[0].live.create({ fields: attributes })
     return uuid
   }
 
   async function checkVideoState (videoId: string, state: VideoState) {
     for (const server of servers) {
-      const video = await server.videosCommand.get({ id: videoId })
+      const video = await server.videos.get({ id: videoId })
       expect(video.state.id).to.equal(state)
     }
   }
@@ -45,7 +43,7 @@ describe('Permanent live', function () {
   before(async function () {
     this.timeout(120000)
 
-    servers = await flushAndRunMultipleServers(2)
+    servers = await createMultipleServers(2)
 
     // Get the access tokens
     await setAccessTokensToServers(servers)
@@ -54,7 +52,7 @@ describe('Permanent live', function () {
     // Server 1 and server 2 follow each other
     await doubleFollow(servers[0], servers[1])
 
-    await servers[0].configCommand.updateCustomSubConfig({
+    await servers[0].config.updateCustomSubConfig({
       newConfig: {
         live: {
           enabled: true,
@@ -75,14 +73,14 @@ describe('Permanent live', function () {
     const videoUUID = await createLiveWrapper(false)
 
     {
-      const live = await servers[0].liveCommand.get({ videoId: videoUUID })
+      const live = await servers[0].live.get({ videoId: videoUUID })
       expect(live.permanentLive).to.be.false
     }
 
-    await servers[0].liveCommand.update({ videoId: videoUUID, fields: { permanentLive: true } })
+    await servers[0].live.update({ videoId: videoUUID, fields: { permanentLive: true } })
 
     {
-      const live = await servers[0].liveCommand.get({ videoId: videoUUID })
+      const live = await servers[0].live.get({ videoId: videoUUID })
       expect(live.permanentLive).to.be.true
     }
   })
@@ -92,39 +90,48 @@ describe('Permanent live', function () {
 
     videoUUID = await createLiveWrapper(true)
 
-    const live = await servers[0].liveCommand.get({ videoId: videoUUID })
+    const live = await servers[0].live.get({ videoId: videoUUID })
     expect(live.permanentLive).to.be.true
 
     await waitJobs(servers)
   })
 
   it('Should stream into this permanent live', async function () {
-    this.timeout(120000)
+    this.timeout(240_000)
 
-    const ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: videoUUID })
+    const beforePublication = new Date()
+    const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: videoUUID })
 
     for (const server of servers) {
-      await server.liveCommand.waitUntilPublished({ videoId: videoUUID })
+      await server.live.waitUntilPublished({ videoId: videoUUID })
     }
 
     await checkVideoState(videoUUID, VideoState.PUBLISHED)
 
+    for (const server of servers) {
+      const video = await server.videos.get({ id: videoUUID })
+      expect(new Date(video.publishedAt)).greaterThan(beforePublication)
+    }
+
     await stopFfmpeg(ffmpegCommand)
-    await servers[0].liveCommand.waitUntilWaiting({ videoId: videoUUID })
+    await servers[0].live.waitUntilWaiting({ videoId: videoUUID })
 
     await waitJobs(servers)
   })
 
-  it('Should not have cleaned up this live', async function () {
+  it('Should have cleaned up this live', async function () {
     this.timeout(40000)
 
     await wait(5000)
     await waitJobs(servers)
 
     for (const server of servers) {
-      const videoDetails = await server.videosCommand.get({ id: videoUUID })
-      expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
+      const videoDetails = await server.videos.get({ id: videoUUID })
+
+      expect(videoDetails.streamingPlaylists).to.have.lengthOf(0)
     }
+
+    await checkLiveCleanup({ server: servers[0], permanent: true, videoUUID })
   })
 
   it('Should have set this live to waiting for live state', async function () {
@@ -134,9 +141,9 @@ describe('Permanent live', function () {
   })
 
   it('Should be able to stream again in the permanent live', async function () {
-    this.timeout(20000)
+    this.timeout(60000)
 
-    await servers[0].configCommand.updateCustomSubConfig({
+    await servers[0].config.updateCustomSubConfig({
       newConfig: {
         live: {
           enabled: true,
@@ -150,21 +157,47 @@ describe('Permanent live', function () {
       }
     })
 
-    const ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: videoUUID })
+    const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: videoUUID })
 
     for (const server of servers) {
-      await server.liveCommand.waitUntilPublished({ videoId: videoUUID })
+      await server.live.waitUntilPublished({ videoId: videoUUID })
     }
 
     await checkVideoState(videoUUID, VideoState.PUBLISHED)
 
-    const count = await servers[0].liveCommand.countPlaylists({ videoUUID })
+    const count = await servers[0].live.countPlaylists({ videoUUID })
     // master playlist and 720p playlist
     expect(count).to.equal(2)
 
     await stopFfmpeg(ffmpegCommand)
   })
 
+  it('Should have appropriate sessions', async function () {
+    this.timeout(60000)
+
+    await servers[0].live.waitUntilWaiting({ videoId: videoUUID })
+
+    const { data, total } = await servers[0].live.listSessions({ videoId: videoUUID })
+    expect(total).to.equal(2)
+    expect(data).to.have.lengthOf(2)
+
+    for (const session of data) {
+      expect(session.startDate).to.exist
+      expect(session.endDate).to.exist
+
+      expect(session.error).to.not.exist
+    }
+  })
+
+  it('Should remove the live and have cleaned up the directory', async function () {
+    this.timeout(60000)
+
+    await servers[0].videos.remove({ id: videoUUID })
+    await waitJobs(servers)
+
+    await checkLiveCleanup({ server: servers[0], permanent: true, videoUUID })
+  })
+
   after(async function () {
     await cleanupTests(servers)
   })