diff options
Diffstat (limited to 'server/tests/api')
-rw-r--r-- | server/tests/api/check-params/live.ts | 6 | ||||
-rw-r--r-- | server/tests/api/live/live-constraints.ts | 4 | ||||
-rw-r--r-- | server/tests/api/live/live-permanent.ts | 5 | ||||
-rw-r--r-- | server/tests/api/live/live-save-replay.ts | 155 | ||||
-rw-r--r-- | server/tests/api/live/live.ts | 4 | ||||
-rw-r--r-- | server/tests/api/object-storage/live.ts | 91 |
6 files changed, 203 insertions, 62 deletions
diff --git a/server/tests/api/check-params/live.ts b/server/tests/api/check-params/live.ts index b253f5e20..2f1c1257e 100644 --- a/server/tests/api/check-params/live.ts +++ b/server/tests/api/check-params/live.ts | |||
@@ -212,12 +212,6 @@ describe('Test video lives API validator', function () { | |||
212 | await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) | 212 | await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) |
213 | }) | 213 | }) |
214 | 214 | ||
215 | it('Should fail with save replay and permanent live set to true', async function () { | ||
216 | const fields = { ...baseCorrectParams, saveReplay: true, permanentLive: true } | ||
217 | |||
218 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | ||
219 | }) | ||
220 | |||
221 | it('Should fail with bad latency setting', async function () { | 215 | it('Should fail with bad latency setting', async function () { |
222 | const fields = { ...baseCorrectParams, latencyMode: 42 } | 216 | const fields = { ...baseCorrectParams, latencyMode: 42 } |
223 | 217 | ||
diff --git a/server/tests/api/live/live-constraints.ts b/server/tests/api/live/live-constraints.ts index 909399836..b92dc7b89 100644 --- a/server/tests/api/live/live-constraints.ts +++ b/server/tests/api/live/live-constraints.ts | |||
@@ -14,7 +14,7 @@ import { | |||
14 | setDefaultVideoChannel, | 14 | setDefaultVideoChannel, |
15 | waitJobs | 15 | waitJobs |
16 | } from '@shared/server-commands' | 16 | } from '@shared/server-commands' |
17 | import { checkLiveCleanupAfterSave } from '../../shared' | 17 | import { checkLiveCleanup } from '../../shared' |
18 | 18 | ||
19 | const expect = chai.expect | 19 | const expect = chai.expect |
20 | 20 | ||
@@ -43,7 +43,7 @@ describe('Test live constraints', function () { | |||
43 | expect(video.duration).to.be.greaterThan(0) | 43 | expect(video.duration).to.be.greaterThan(0) |
44 | } | 44 | } |
45 | 45 | ||
46 | await checkLiveCleanupAfterSave(servers[0], videoId, resolutions) | 46 | await checkLiveCleanup(servers[0], videoId, resolutions) |
47 | } | 47 | } |
48 | 48 | ||
49 | async function waitUntilLivePublishedOnAllServers (videoId: string) { | 49 | async function waitUntilLivePublishedOnAllServers (videoId: string) { |
diff --git a/server/tests/api/live/live-permanent.ts b/server/tests/api/live/live-permanent.ts index 3e6fec453..a88d71dd9 100644 --- a/server/tests/api/live/live-permanent.ts +++ b/server/tests/api/live/live-permanent.ts | |||
@@ -121,7 +121,7 @@ describe('Permanent live', function () { | |||
121 | await waitJobs(servers) | 121 | await waitJobs(servers) |
122 | }) | 122 | }) |
123 | 123 | ||
124 | it('Should not have cleaned up this live', async function () { | 124 | it('Should have cleaned up this live', async function () { |
125 | this.timeout(40000) | 125 | this.timeout(40000) |
126 | 126 | ||
127 | await wait(5000) | 127 | await wait(5000) |
@@ -129,7 +129,8 @@ describe('Permanent live', function () { | |||
129 | 129 | ||
130 | for (const server of servers) { | 130 | for (const server of servers) { |
131 | const videoDetails = await server.videos.get({ id: videoUUID }) | 131 | const videoDetails = await server.videos.get({ id: videoUUID }) |
132 | expect(videoDetails.streamingPlaylists).to.have.lengthOf(1) | 132 | |
133 | expect(videoDetails.streamingPlaylists).to.have.lengthOf(0) | ||
133 | } | 134 | } |
134 | }) | 135 | }) |
135 | 136 | ||
diff --git a/server/tests/api/live/live-save-replay.ts b/server/tests/api/live/live-save-replay.ts index 95a342b01..ba68a4287 100644 --- a/server/tests/api/live/live-save-replay.ts +++ b/server/tests/api/live/live-save-replay.ts | |||
@@ -3,7 +3,7 @@ | |||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | 4 | import * as chai from 'chai' |
5 | import { FfmpegCommand } from 'fluent-ffmpeg' | 5 | import { FfmpegCommand } from 'fluent-ffmpeg' |
6 | import { checkLiveCleanupAfterSave } from '@server/tests/shared' | 6 | import { checkLiveCleanup } from '@server/tests/shared' |
7 | import { wait } from '@shared/core-utils' | 7 | import { wait } from '@shared/core-utils' |
8 | import { HttpStatusCode, LiveVideoCreate, VideoPrivacy, VideoState } from '@shared/models' | 8 | import { HttpStatusCode, LiveVideoCreate, VideoPrivacy, VideoState } from '@shared/models' |
9 | import { | 9 | import { |
@@ -11,6 +11,7 @@ import { | |||
11 | ConfigCommand, | 11 | ConfigCommand, |
12 | createMultipleServers, | 12 | createMultipleServers, |
13 | doubleFollow, | 13 | doubleFollow, |
14 | findExternalSavedVideo, | ||
14 | PeerTubeServer, | 15 | PeerTubeServer, |
15 | setAccessTokensToServers, | 16 | setAccessTokensToServers, |
16 | setDefaultVideoChannel, | 17 | setDefaultVideoChannel, |
@@ -18,7 +19,8 @@ import { | |||
18 | testFfmpegStreamError, | 19 | testFfmpegStreamError, |
19 | waitJobs, | 20 | waitJobs, |
20 | waitUntilLivePublishedOnAllServers, | 21 | waitUntilLivePublishedOnAllServers, |
21 | waitUntilLiveSavedOnAllServers | 22 | waitUntilLiveReplacedByReplayOnAllServers, |
23 | waitUntilLiveWaitingOnAllServers | ||
22 | } from '@shared/server-commands' | 24 | } from '@shared/server-commands' |
23 | 25 | ||
24 | const expect = chai.expect | 26 | const expect = chai.expect |
@@ -28,7 +30,7 @@ describe('Save replay setting', function () { | |||
28 | let liveVideoUUID: string | 30 | let liveVideoUUID: string |
29 | let ffmpegCommand: FfmpegCommand | 31 | let ffmpegCommand: FfmpegCommand |
30 | 32 | ||
31 | async function createLiveWrapper (saveReplay: boolean) { | 33 | async function createLiveWrapper (options: { permanent: boolean, replay: boolean }) { |
32 | if (liveVideoUUID) { | 34 | if (liveVideoUUID) { |
33 | try { | 35 | try { |
34 | await servers[0].videos.remove({ id: liveVideoUUID }) | 36 | await servers[0].videos.remove({ id: liveVideoUUID }) |
@@ -40,7 +42,8 @@ describe('Save replay setting', function () { | |||
40 | channelId: servers[0].store.channel.id, | 42 | channelId: servers[0].store.channel.id, |
41 | privacy: VideoPrivacy.PUBLIC, | 43 | privacy: VideoPrivacy.PUBLIC, |
42 | name: 'my super live', | 44 | name: 'my super live', |
43 | saveReplay | 45 | saveReplay: options.replay, |
46 | permanentLive: options.permanent | ||
44 | } | 47 | } |
45 | 48 | ||
46 | const { uuid } = await servers[0].live.create({ fields: attributes }) | 49 | const { uuid } = await servers[0].live.create({ fields: attributes }) |
@@ -104,7 +107,7 @@ describe('Save replay setting', function () { | |||
104 | it('Should correctly create and federate the "waiting for stream" live', async function () { | 107 | it('Should correctly create and federate the "waiting for stream" live', async function () { |
105 | this.timeout(20000) | 108 | this.timeout(20000) |
106 | 109 | ||
107 | liveVideoUUID = await createLiveWrapper(false) | 110 | liveVideoUUID = await createLiveWrapper({ permanent: false, replay: false }) |
108 | 111 | ||
109 | await waitJobs(servers) | 112 | await waitJobs(servers) |
110 | 113 | ||
@@ -140,13 +143,13 @@ describe('Save replay setting', function () { | |||
140 | await checkVideoState(liveVideoUUID, VideoState.LIVE_ENDED) | 143 | await checkVideoState(liveVideoUUID, VideoState.LIVE_ENDED) |
141 | 144 | ||
142 | // No resolutions saved since we did not save replay | 145 | // No resolutions saved since we did not save replay |
143 | await checkLiveCleanupAfterSave(servers[0], liveVideoUUID, []) | 146 | await checkLiveCleanup(servers[0], liveVideoUUID, []) |
144 | }) | 147 | }) |
145 | 148 | ||
146 | it('Should correctly terminate the stream on blacklist and delete the live', async function () { | 149 | it('Should correctly terminate the stream on blacklist and delete the live', async function () { |
147 | this.timeout(40000) | 150 | this.timeout(40000) |
148 | 151 | ||
149 | liveVideoUUID = await createLiveWrapper(false) | 152 | liveVideoUUID = await createLiveWrapper({ permanent: false, replay: false }) |
150 | 153 | ||
151 | ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) | 154 | ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) |
152 | 155 | ||
@@ -169,13 +172,13 @@ describe('Save replay setting', function () { | |||
169 | 172 | ||
170 | await wait(5000) | 173 | await wait(5000) |
171 | await waitJobs(servers) | 174 | await waitJobs(servers) |
172 | await checkLiveCleanupAfterSave(servers[0], liveVideoUUID, []) | 175 | await checkLiveCleanup(servers[0], liveVideoUUID, []) |
173 | }) | 176 | }) |
174 | 177 | ||
175 | it('Should correctly terminate the stream on delete and delete the video', async function () { | 178 | it('Should correctly terminate the stream on delete and delete the video', async function () { |
176 | this.timeout(40000) | 179 | this.timeout(40000) |
177 | 180 | ||
178 | liveVideoUUID = await createLiveWrapper(false) | 181 | liveVideoUUID = await createLiveWrapper({ permanent: false, replay: false }) |
179 | 182 | ||
180 | ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) | 183 | ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) |
181 | 184 | ||
@@ -193,16 +196,16 @@ describe('Save replay setting', function () { | |||
193 | await waitJobs(servers) | 196 | await waitJobs(servers) |
194 | 197 | ||
195 | await checkVideosExist(liveVideoUUID, false, HttpStatusCode.NOT_FOUND_404) | 198 | await checkVideosExist(liveVideoUUID, false, HttpStatusCode.NOT_FOUND_404) |
196 | await checkLiveCleanupAfterSave(servers[0], liveVideoUUID, []) | 199 | await checkLiveCleanup(servers[0], liveVideoUUID, []) |
197 | }) | 200 | }) |
198 | }) | 201 | }) |
199 | 202 | ||
200 | describe('With save replay enabled', function () { | 203 | describe('With save replay enabled on non permanent live', function () { |
201 | 204 | ||
202 | it('Should correctly create and federate the "waiting for stream" live', async function () { | 205 | it('Should correctly create and federate the "waiting for stream" live', async function () { |
203 | this.timeout(20000) | 206 | this.timeout(20000) |
204 | 207 | ||
205 | liveVideoUUID = await createLiveWrapper(true) | 208 | liveVideoUUID = await createLiveWrapper({ permanent: false, replay: true }) |
206 | 209 | ||
207 | await waitJobs(servers) | 210 | await waitJobs(servers) |
208 | 211 | ||
@@ -227,7 +230,7 @@ describe('Save replay setting', function () { | |||
227 | 230 | ||
228 | await stopFfmpeg(ffmpegCommand) | 231 | await stopFfmpeg(ffmpegCommand) |
229 | 232 | ||
230 | await waitUntilLiveSavedOnAllServers(servers, liveVideoUUID) | 233 | await waitUntilLiveReplacedByReplayOnAllServers(servers, liveVideoUUID) |
231 | await waitJobs(servers) | 234 | await waitJobs(servers) |
232 | 235 | ||
233 | // Live has been transcoded | 236 | // Live has been transcoded |
@@ -249,13 +252,13 @@ describe('Save replay setting', function () { | |||
249 | }) | 252 | }) |
250 | 253 | ||
251 | it('Should have cleaned up the live files', async function () { | 254 | it('Should have cleaned up the live files', async function () { |
252 | await checkLiveCleanupAfterSave(servers[0], liveVideoUUID, [ 720 ]) | 255 | await checkLiveCleanup(servers[0], liveVideoUUID, [ 720 ]) |
253 | }) | 256 | }) |
254 | 257 | ||
255 | it('Should correctly terminate the stream on blacklist and blacklist the saved replay video', async function () { | 258 | it('Should correctly terminate the stream on blacklist and blacklist the saved replay video', async function () { |
256 | this.timeout(40000) | 259 | this.timeout(40000) |
257 | 260 | ||
258 | liveVideoUUID = await createLiveWrapper(true) | 261 | liveVideoUUID = await createLiveWrapper({ permanent: false, replay: true }) |
259 | 262 | ||
260 | ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) | 263 | ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) |
261 | await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID) | 264 | await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID) |
@@ -277,13 +280,13 @@ describe('Save replay setting', function () { | |||
277 | 280 | ||
278 | await wait(5000) | 281 | await wait(5000) |
279 | await waitJobs(servers) | 282 | await waitJobs(servers) |
280 | await checkLiveCleanupAfterSave(servers[0], liveVideoUUID, [ 720 ]) | 283 | await checkLiveCleanup(servers[0], liveVideoUUID, [ 720 ]) |
281 | }) | 284 | }) |
282 | 285 | ||
283 | it('Should correctly terminate the stream on delete and delete the video', async function () { | 286 | it('Should correctly terminate the stream on delete and delete the video', async function () { |
284 | this.timeout(40000) | 287 | this.timeout(40000) |
285 | 288 | ||
286 | liveVideoUUID = await createLiveWrapper(true) | 289 | liveVideoUUID = await createLiveWrapper({ permanent: false, replay: true }) |
287 | 290 | ||
288 | ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) | 291 | ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) |
289 | await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID) | 292 | await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID) |
@@ -300,7 +303,123 @@ describe('Save replay setting', function () { | |||
300 | await waitJobs(servers) | 303 | await waitJobs(servers) |
301 | 304 | ||
302 | await checkVideosExist(liveVideoUUID, false, HttpStatusCode.NOT_FOUND_404) | 305 | await checkVideosExist(liveVideoUUID, false, HttpStatusCode.NOT_FOUND_404) |
303 | await checkLiveCleanupAfterSave(servers[0], liveVideoUUID, []) | 306 | await checkLiveCleanup(servers[0], liveVideoUUID, []) |
307 | }) | ||
308 | }) | ||
309 | |||
310 | describe('With save replay enabled on permanent live', function () { | ||
311 | let lastReplayUUID: string | ||
312 | |||
313 | it('Should correctly create and federate the "waiting for stream" live', async function () { | ||
314 | this.timeout(20000) | ||
315 | |||
316 | liveVideoUUID = await createLiveWrapper({ permanent: true, replay: true }) | ||
317 | |||
318 | await waitJobs(servers) | ||
319 | |||
320 | await checkVideosExist(liveVideoUUID, false, HttpStatusCode.OK_200) | ||
321 | await checkVideoState(liveVideoUUID, VideoState.WAITING_FOR_LIVE) | ||
322 | }) | ||
323 | |||
324 | it('Should correctly have updated the live and federated it when streaming in the live', async function () { | ||
325 | this.timeout(20000) | ||
326 | |||
327 | ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) | ||
328 | await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID) | ||
329 | |||
330 | await waitJobs(servers) | ||
331 | |||
332 | await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) | ||
333 | await checkVideoState(liveVideoUUID, VideoState.PUBLISHED) | ||
334 | }) | ||
335 | |||
336 | it('Should correctly have saved the live and federated it after the streaming', async function () { | ||
337 | this.timeout(30000) | ||
338 | |||
339 | const liveDetails = await servers[0].videos.get({ id: liveVideoUUID }) | ||
340 | |||
341 | await stopFfmpeg(ffmpegCommand) | ||
342 | |||
343 | await waitUntilLiveWaitingOnAllServers(servers, liveVideoUUID) | ||
344 | await waitJobs(servers) | ||
345 | |||
346 | const video = await findExternalSavedVideo(servers[0], liveDetails) | ||
347 | expect(video).to.exist | ||
348 | |||
349 | for (const server of servers) { | ||
350 | await server.videos.get({ id: video.uuid }) | ||
351 | } | ||
352 | |||
353 | lastReplayUUID = video.uuid | ||
354 | }) | ||
355 | |||
356 | it('Should have cleaned up the live files', async function () { | ||
357 | await checkLiveCleanup(servers[0], liveVideoUUID, []) | ||
358 | }) | ||
359 | |||
360 | it('Should correctly terminate the stream on blacklist and blacklist the saved replay video', async function () { | ||
361 | this.timeout(60000) | ||
362 | |||
363 | await servers[0].videos.remove({ id: lastReplayUUID }) | ||
364 | |||
365 | liveVideoUUID = await createLiveWrapper({ permanent: true, replay: true }) | ||
366 | |||
367 | ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) | ||
368 | await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID) | ||
369 | |||
370 | const liveDetails = await servers[0].videos.get({ id: liveVideoUUID }) | ||
371 | |||
372 | await waitJobs(servers) | ||
373 | await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) | ||
374 | |||
375 | await Promise.all([ | ||
376 | servers[0].blacklist.add({ videoId: liveVideoUUID, reason: 'bad live', unfederate: true }), | ||
377 | testFfmpegStreamError(ffmpegCommand, true) | ||
378 | ]) | ||
379 | |||
380 | await waitJobs(servers) | ||
381 | await wait(5000) | ||
382 | await waitJobs(servers) | ||
383 | |||
384 | const replay = await findExternalSavedVideo(servers[0], liveDetails) | ||
385 | expect(replay).to.exist | ||
386 | |||
387 | for (const videoId of [ liveVideoUUID, replay.uuid ]) { | ||
388 | await checkVideosExist(videoId, false) | ||
389 | |||
390 | await servers[0].videos.get({ id: videoId, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) | ||
391 | await servers[1].videos.get({ id: videoId, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) | ||
392 | } | ||
393 | |||
394 | await checkLiveCleanup(servers[0], liveVideoUUID, []) | ||
395 | }) | ||
396 | |||
397 | it('Should correctly terminate the stream on delete and not save the video', async function () { | ||
398 | this.timeout(40000) | ||
399 | |||
400 | liveVideoUUID = await createLiveWrapper({ permanent: true, replay: true }) | ||
401 | |||
402 | ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) | ||
403 | await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID) | ||
404 | |||
405 | const liveDetails = await servers[0].videos.get({ id: liveVideoUUID }) | ||
406 | |||
407 | await waitJobs(servers) | ||
408 | await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) | ||
409 | |||
410 | await Promise.all([ | ||
411 | servers[0].videos.remove({ id: liveVideoUUID }), | ||
412 | testFfmpegStreamError(ffmpegCommand, true) | ||
413 | ]) | ||
414 | |||
415 | await wait(5000) | ||
416 | await waitJobs(servers) | ||
417 | |||
418 | const replay = await findExternalSavedVideo(servers[0], liveDetails) | ||
419 | expect(replay).to.not.exist | ||
420 | |||
421 | await checkVideosExist(liveVideoUUID, false, HttpStatusCode.NOT_FOUND_404) | ||
422 | await checkLiveCleanup(servers[0], liveVideoUUID, []) | ||
304 | }) | 423 | }) |
305 | }) | 424 | }) |
306 | 425 | ||
diff --git a/server/tests/api/live/live.ts b/server/tests/api/live/live.ts index aeb039696..6e7b77bce 100644 --- a/server/tests/api/live/live.ts +++ b/server/tests/api/live/live.ts | |||
@@ -4,7 +4,7 @@ import 'mocha' | |||
4 | import * as chai from 'chai' | 4 | import * as chai from 'chai' |
5 | import { basename, join } from 'path' | 5 | import { basename, join } from 'path' |
6 | import { ffprobePromise, getVideoStream } from '@server/helpers/ffmpeg' | 6 | import { ffprobePromise, getVideoStream } from '@server/helpers/ffmpeg' |
7 | import { checkLiveCleanupAfterSave, checkLiveSegmentHash, checkResolutionsInMasterPlaylist, testImage } from '@server/tests/shared' | 7 | import { checkLiveCleanup, checkLiveSegmentHash, checkResolutionsInMasterPlaylist, testImage } from '@server/tests/shared' |
8 | import { wait } from '@shared/core-utils' | 8 | import { wait } from '@shared/core-utils' |
9 | import { | 9 | import { |
10 | HttpStatusCode, | 10 | HttpStatusCode, |
@@ -583,7 +583,7 @@ describe('Test live', function () { | |||
583 | it('Should correctly have cleaned up the live files', async function () { | 583 | it('Should correctly have cleaned up the live files', async function () { |
584 | this.timeout(30000) | 584 | this.timeout(30000) |
585 | 585 | ||
586 | await checkLiveCleanupAfterSave(servers[0], liveVideoId, [ 240, 360, 720 ]) | 586 | await checkLiveCleanup(servers[0], liveVideoId, [ 240, 360, 720 ]) |
587 | }) | 587 | }) |
588 | }) | 588 | }) |
589 | 589 | ||
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 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | 4 | import * as chai from 'chai' |
5 | import { FfmpegCommand } from 'fluent-ffmpeg' | ||
6 | import { expectStartWith } from '@server/tests/shared' | 5 | import { expectStartWith } from '@server/tests/shared' |
7 | import { areObjectStorageTestsDisabled } from '@shared/core-utils' | 6 | import { areObjectStorageTestsDisabled } from '@shared/core-utils' |
8 | import { HttpStatusCode, LiveVideoCreate, VideoFile, VideoPrivacy } from '@shared/models' | 7 | import { HttpStatusCode, LiveVideoCreate, VideoFile, VideoPrivacy } from '@shared/models' |
9 | import { | 8 | import { |
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 | ||
24 | const expect = chai.expect | 25 | const expect = chai.expect |
25 | 26 | ||
26 | async function createLive (server: PeerTubeServer) { | 27 | async 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 | ||
49 | async 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 | |||
58 | async 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 | |||
47 | describe('Object storage for lives', function () { | 78 | describe('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) |