]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/live/live-socket-messages.ts
Also retry when fetching master m3u8 playlist
[github/Chocobozzz/PeerTube.git] / server / tests / api / live / live-socket-messages.ts
index 73a300384f4b4a85174fc8b78a2f2d99be1002f4..62b7a6d222d1564fabb40e960be4f9023bb5973c 100644 (file)
@@ -1,38 +1,33 @@
 /* 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 { VideoPrivacy, VideoState } from '@shared/models'
 import {
   cleanupTests,
+  createMultipleServers,
   doubleFollow,
-  flushAndRunMultipleServers,
-  getVideoIdFromUUID,
-  ServerInfo,
+  PeerTubeServer,
   setAccessTokensToServers,
   setDefaultVideoChannel,
   stopFfmpeg,
-  viewVideo,
-  wait,
   waitJobs,
   waitUntilLivePublishedOnAllServers
-} from '../../../../shared/extra-utils'
+} from '@shared/server-commands'
 
-const expect = chai.expect
-
-describe('Test live', function () {
-  let servers: ServerInfo[] = []
+describe('Test live socket messages', function () {
+  let servers: PeerTubeServer[] = []
 
   before(async function () {
     this.timeout(120000)
 
-    servers = await flushAndRunMultipleServers(2)
+    servers = await createMultipleServers(2)
 
     // Get the access tokens
     await setAccessTokensToServers(servers)
     await setDefaultVideoChannel(servers)
 
-    await servers[0].configCommand.updateCustomSubConfig({
+    await servers[0].config.updateCustomSubConfig({
       newConfig: {
         live: {
           enabled: true,
@@ -53,11 +48,11 @@ describe('Test live', function () {
     async function createLiveWrapper () {
       const liveAttributes = {
         name: 'live video',
-        channelId: servers[0].videoChannel.id,
+        channelId: servers[0].store.channel.id,
         privacy: VideoPrivacy.PUBLIC
       }
 
-      const { uuid } = await servers[0].liveCommand.createLive({ fields: liveAttributes })
+      const { uuid } = await servers[0].live.create({ fields: liveAttributes })
       return uuid
     }
 
@@ -71,22 +66,22 @@ describe('Test live', function () {
       await waitJobs(servers)
 
       {
-        const videoId = await getVideoIdFromUUID(servers[0].url, liveVideoUUID)
+        const videoId = await servers[0].videos.getId({ uuid: liveVideoUUID })
 
-        const localSocket = servers[0].socketIOCommand.getLiveNotificationSocket()
+        const localSocket = servers[0].socketIO.getLiveNotificationSocket()
         localSocket.on('state-change', data => localStateChanges.push(data.state))
         localSocket.emit('subscribe', { videoId })
       }
 
       {
-        const videoId = await getVideoIdFromUUID(servers[1].url, liveVideoUUID)
+        const videoId = await servers[1].videos.getId({ uuid: liveVideoUUID })
 
-        const remoteSocket = servers[1].socketIOCommand.getLiveNotificationSocket()
+        const remoteSocket = servers[1].socketIO.getLiveNotificationSocket()
         remoteSocket.on('state-change', data => remoteStateChanges.push(data.state))
         remoteSocket.emit('subscribe', { videoId })
       }
 
-      const ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoUUID })
+      const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID })
 
       await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID)
       await waitJobs(servers)
@@ -99,7 +94,7 @@ describe('Test live', function () {
       await stopFfmpeg(ffmpegCommand)
 
       for (const server of servers) {
-        await server.liveCommand.waitUntilLiveEnded({ videoId: liveVideoUUID })
+        await server.live.waitUntilEnded({ videoId: liveVideoUUID })
       }
       await waitJobs(servers)
 
@@ -119,22 +114,22 @@ describe('Test live', function () {
       await waitJobs(servers)
 
       {
-        const videoId = await getVideoIdFromUUID(servers[0].url, liveVideoUUID)
+        const videoId = await servers[0].videos.getId({ uuid: liveVideoUUID })
 
-        const localSocket = servers[0].socketIOCommand.getLiveNotificationSocket()
+        const localSocket = servers[0].socketIO.getLiveNotificationSocket()
         localSocket.on('views-change', data => { localLastVideoViews = data.views })
         localSocket.emit('subscribe', { videoId })
       }
 
       {
-        const videoId = await getVideoIdFromUUID(servers[1].url, liveVideoUUID)
+        const videoId = await servers[1].videos.getId({ uuid: liveVideoUUID })
 
-        const remoteSocket = servers[1].socketIOCommand.getLiveNotificationSocket()
+        const remoteSocket = servers[1].socketIO.getLiveNotificationSocket()
         remoteSocket.on('views-change', data => { remoteLastVideoViews = data.views })
         remoteSocket.emit('subscribe', { videoId })
       }
 
-      const ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoUUID })
+      const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID })
 
       await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID)
       await waitJobs(servers)
@@ -142,11 +137,9 @@ describe('Test live', function () {
       expect(localLastVideoViews).to.equal(0)
       expect(remoteLastVideoViews).to.equal(0)
 
-      await viewVideo(servers[0].url, liveVideoUUID)
-      await viewVideo(servers[1].url, liveVideoUUID)
+      await servers[0].views.simulateView({ id: liveVideoUUID })
+      await servers[1].views.simulateView({ id: liveVideoUUID })
 
-      await waitJobs(servers)
-      await wait(5000)
       await waitJobs(servers)
 
       expect(localLastVideoViews).to.equal(2)
@@ -163,13 +156,13 @@ describe('Test live', function () {
       const liveVideoUUID = await createLiveWrapper()
       await waitJobs(servers)
 
-      const videoId = await getVideoIdFromUUID(servers[0].url, liveVideoUUID)
+      const videoId = await servers[0].videos.getId({ uuid: liveVideoUUID })
 
-      const socket = servers[0].socketIOCommand.getLiveNotificationSocket()
+      const socket = servers[0].socketIO.getLiveNotificationSocket()
       socket.on('state-change', data => stateChanges.push(data.state))
       socket.emit('subscribe', { videoId })
 
-      const command = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoUUID })
+      const command = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID })
 
       await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID)
       await waitJobs(servers)