aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/object-storage/live.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/object-storage/live.ts')
-rw-r--r--server/tests/api/object-storage/live.ts91
1 files changed, 59 insertions, 32 deletions
diff --git a/server/tests/api/object-storage/live.ts b/server/tests/api/object-storage/live.ts
index 0cb0a6e34..5d6281dec 100644
--- a/server/tests/api/object-storage/live.ts
+++ b/server/tests/api/object-storage/live.ts
@@ -2,13 +2,13 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { FfmpegCommand } from 'fluent-ffmpeg'
6import { expectStartWith } from '@server/tests/shared' 5import { expectStartWith } from '@server/tests/shared'
7import { areObjectStorageTestsDisabled } from '@shared/core-utils' 6import { areObjectStorageTestsDisabled } from '@shared/core-utils'
8import { HttpStatusCode, LiveVideoCreate, VideoFile, VideoPrivacy } from '@shared/models' 7import { HttpStatusCode, LiveVideoCreate, VideoFile, VideoPrivacy } from '@shared/models'
9import { 8import {
10 createMultipleServers, 9 createMultipleServers,
11 doubleFollow, 10 doubleFollow,
11 findExternalSavedVideo,
12 killallServers, 12 killallServers,
13 makeRawRequest, 13 makeRawRequest,
14 ObjectStorageCommand, 14 ObjectStorageCommand,
@@ -18,17 +18,19 @@ import {
18 stopFfmpeg, 18 stopFfmpeg,
19 waitJobs, 19 waitJobs,
20 waitUntilLivePublishedOnAllServers, 20 waitUntilLivePublishedOnAllServers,
21 waitUntilLiveSavedOnAllServers 21 waitUntilLiveReplacedByReplayOnAllServers,
22 waitUntilLiveWaitingOnAllServers
22} from '@shared/server-commands' 23} from '@shared/server-commands'
23 24
24const expect = chai.expect 25const expect = chai.expect
25 26
26async function createLive (server: PeerTubeServer) { 27async function createLive (server: PeerTubeServer, permanent: boolean) {
27 const attributes: LiveVideoCreate = { 28 const attributes: LiveVideoCreate = {
28 channelId: server.store.channel.id, 29 channelId: server.store.channel.id,
29 privacy: VideoPrivacy.PUBLIC, 30 privacy: VideoPrivacy.PUBLIC,
30 name: 'my super live', 31 name: 'my super live',
31 saveReplay: true 32 saveReplay: true,
33 permanentLive: permanent
32 } 34 }
33 35
34 const { uuid } = await server.live.create({ fields: attributes }) 36 const { uuid } = await server.live.create({ fields: attributes })
@@ -44,12 +46,39 @@ async function checkFiles (files: VideoFile[]) {
44 } 46 }
45} 47}
46 48
49async function getFiles (server: PeerTubeServer, videoUUID: string) {
50 const video = await server.videos.get({ id: videoUUID })
51
52 expect(video.files).to.have.lengthOf(0)
53 expect(video.streamingPlaylists).to.have.lengthOf(1)
54
55 return video.streamingPlaylists[0].files
56}
57
58async function streamAndEnd (servers: PeerTubeServer[], liveUUID: string) {
59 const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveUUID })
60 await waitUntilLivePublishedOnAllServers(servers, liveUUID)
61
62 const videoLiveDetails = await servers[0].videos.get({ id: liveUUID })
63 const liveDetails = await servers[0].live.get({ videoId: liveUUID })
64
65 await stopFfmpeg(ffmpegCommand)
66
67 if (liveDetails.permanentLive) {
68 await waitUntilLiveWaitingOnAllServers(servers, liveUUID)
69 } else {
70 await waitUntilLiveReplacedByReplayOnAllServers(servers, liveUUID)
71 }
72
73 await waitJobs(servers)
74
75 return { videoLiveDetails, liveDetails }
76}
77
47describe('Object storage for lives', function () { 78describe('Object storage for lives', function () {
48 if (areObjectStorageTestsDisabled()) return 79 if (areObjectStorageTestsDisabled()) return
49 80
50 let ffmpegCommand: FfmpegCommand
51 let servers: PeerTubeServer[] 81 let servers: PeerTubeServer[]
52 let videoUUID: string
53 82
54 before(async function () { 83 before(async function () {
55 this.timeout(120000) 84 this.timeout(120000)
@@ -66,31 +95,22 @@ describe('Object storage for lives', function () {
66 }) 95 })
67 96
68 describe('Without live transcoding', async function () { 97 describe('Without live transcoding', async function () {
98 let videoUUID: string
69 99
70 before(async function () { 100 before(async function () {
71 await servers[0].config.enableLive({ transcoding: false }) 101 await servers[0].config.enableLive({ transcoding: false })
72 102
73 videoUUID = await createLive(servers[0]) 103 videoUUID = await createLive(servers[0], false)
74 }) 104 })
75 105
76 it('Should create a live and save the replay on object storage', async function () { 106 it('Should create a live and save the replay on object storage', async function () {
77 this.timeout(220000) 107 this.timeout(220000)
78 108
79 ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: videoUUID }) 109 await streamAndEnd(servers, videoUUID)
80 await waitUntilLivePublishedOnAllServers(servers, videoUUID)
81
82 await stopFfmpeg(ffmpegCommand)
83
84 await waitUntilLiveSavedOnAllServers(servers, videoUUID)
85 await waitJobs(servers)
86 110
87 for (const server of servers) { 111 for (const server of servers) {
88 const video = await server.videos.get({ id: videoUUID }) 112 const files = await getFiles(server, videoUUID)
89 113 expect(files).to.have.lengthOf(1)
90 expect(video.files).to.have.lengthOf(0)
91 expect(video.streamingPlaylists).to.have.lengthOf(1)
92
93 const files = video.streamingPlaylists[0].files
94 114
95 await checkFiles(files) 115 await checkFiles(files)
96 } 116 }
@@ -98,31 +118,38 @@ describe('Object storage for lives', function () {
98 }) 118 })
99 119
100 describe('With live transcoding', async function () { 120 describe('With live transcoding', async function () {
121 let videoUUIDPermanent: string
122 let videoUUIDNonPermanent: string
101 123
102 before(async function () { 124 before(async function () {
103 await servers[0].config.enableLive({ transcoding: true }) 125 await servers[0].config.enableLive({ transcoding: true })
104 126
105 videoUUID = await createLive(servers[0]) 127 videoUUIDPermanent = await createLive(servers[0], true)
128 videoUUIDNonPermanent = await createLive(servers[0], false)
106 }) 129 })
107 130
108 it('Should import a video and have sent it to object storage', async function () { 131 it('Should create a live and save the replay on object storage', async function () {
109 this.timeout(240000) 132 this.timeout(240000)
110 133
111 ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: videoUUID }) 134 await streamAndEnd(servers, videoUUIDNonPermanent)
112 await waitUntilLivePublishedOnAllServers(servers, videoUUID)
113 135
114 await stopFfmpeg(ffmpegCommand) 136 for (const server of servers) {
137 const files = await getFiles(server, videoUUIDNonPermanent)
138 expect(files).to.have.lengthOf(5)
115 139
116 await waitUntilLiveSavedOnAllServers(servers, videoUUID) 140 await checkFiles(files)
117 await waitJobs(servers) 141 }
142 })
118 143
119 for (const server of servers) { 144 it('Should create a live and save the replay of permanent live on object storage', async function () {
120 const video = await server.videos.get({ id: videoUUID }) 145 this.timeout(240000)
146
147 const { videoLiveDetails } = await streamAndEnd(servers, videoUUIDPermanent)
121 148
122 expect(video.files).to.have.lengthOf(0) 149 const replay = await findExternalSavedVideo(servers[0], videoLiveDetails)
123 expect(video.streamingPlaylists).to.have.lengthOf(1)
124 150
125 const files = video.streamingPlaylists[0].files 151 for (const server of servers) {
152 const files = await getFiles(server, replay.uuid)
126 expect(files).to.have.lengthOf(5) 153 expect(files).to.have.lengthOf(5)
127 154
128 await checkFiles(files) 155 await checkFiles(files)