diff options
Diffstat (limited to 'server/tests')
-rw-r--r-- | server/tests/api/live/index.ts | 1 | ||||
-rw-r--r-- | server/tests/api/live/live-fast-restream.ts | 128 | ||||
-rw-r--r-- | server/tests/api/live/live-save-replay.ts | 41 | ||||
-rw-r--r-- | server/tests/api/live/live.ts | 8 |
4 files changed, 133 insertions, 45 deletions
diff --git a/server/tests/api/live/index.ts b/server/tests/api/live/index.ts index 71bc150d8..c88943f65 100644 --- a/server/tests/api/live/index.ts +++ b/server/tests/api/live/index.ts | |||
@@ -1,4 +1,5 @@ | |||
1 | import './live-constraints' | 1 | import './live-constraints' |
2 | import './live-fast-restream' | ||
2 | import './live-socket-messages' | 3 | import './live-socket-messages' |
3 | import './live-permanent' | 4 | import './live-permanent' |
4 | import './live-rtmps' | 5 | import './live-rtmps' |
diff --git a/server/tests/api/live/live-fast-restream.ts b/server/tests/api/live/live-fast-restream.ts new file mode 100644 index 000000000..4b5d041ec --- /dev/null +++ b/server/tests/api/live/live-fast-restream.ts | |||
@@ -0,0 +1,128 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import 'mocha' | ||
4 | import * as chai from 'chai' | ||
5 | import { wait } from '@shared/core-utils' | ||
6 | import { HttpStatusCode, LiveVideoCreate, VideoPrivacy } from '@shared/models' | ||
7 | import { | ||
8 | cleanupTests, | ||
9 | createSingleServer, | ||
10 | makeRawRequest, | ||
11 | PeerTubeServer, | ||
12 | setAccessTokensToServers, | ||
13 | setDefaultVideoChannel, | ||
14 | stopFfmpeg, | ||
15 | waitJobs | ||
16 | } from '@shared/server-commands' | ||
17 | |||
18 | const expect = chai.expect | ||
19 | |||
20 | describe('Fast restream in live', function () { | ||
21 | let server: PeerTubeServer | ||
22 | |||
23 | async function createLiveWrapper (options: { permanent: boolean, replay: boolean }) { | ||
24 | const attributes: LiveVideoCreate = { | ||
25 | channelId: server.store.channel.id, | ||
26 | privacy: VideoPrivacy.PUBLIC, | ||
27 | name: 'my super live', | ||
28 | saveReplay: options.replay, | ||
29 | permanentLive: options.permanent | ||
30 | } | ||
31 | |||
32 | const { uuid } = await server.live.create({ fields: attributes }) | ||
33 | return uuid | ||
34 | } | ||
35 | |||
36 | async function fastRestreamWrapper ({ replay }: { replay: boolean }) { | ||
37 | const liveVideoUUID = await createLiveWrapper({ permanent: true, replay }) | ||
38 | await waitJobs([ server ]) | ||
39 | |||
40 | const rtmpOptions = { | ||
41 | videoId: liveVideoUUID, | ||
42 | copyCodecs: true, | ||
43 | fixtureName: 'video_short.mp4' | ||
44 | } | ||
45 | |||
46 | // Streaming session #1 | ||
47 | let ffmpegCommand = await server.live.sendRTMPStreamInVideo(rtmpOptions) | ||
48 | await server.live.waitUntilPublished({ videoId: liveVideoUUID }) | ||
49 | await stopFfmpeg(ffmpegCommand) | ||
50 | await server.live.waitUntilWaiting({ videoId: liveVideoUUID }) | ||
51 | |||
52 | // Streaming session #2 | ||
53 | ffmpegCommand = await server.live.sendRTMPStreamInVideo(rtmpOptions) | ||
54 | await server.live.waitUntilSegmentGeneration({ videoUUID: liveVideoUUID, segment: 0, playlistNumber: 0, totalSessions: 2 }) | ||
55 | |||
56 | return { ffmpegCommand, liveVideoUUID } | ||
57 | } | ||
58 | |||
59 | async function ensureLastLiveWorks (liveId: string) { | ||
60 | // Equivalent to PEERTUBE_TEST_CONSTANTS.VIDEO_LIVE.CLEANUP_DELAY | ||
61 | for (let i = 0; i < 100; i++) { | ||
62 | const video = await server.videos.get({ id: liveId }) | ||
63 | expect(video.streamingPlaylists).to.have.lengthOf(1) | ||
64 | |||
65 | await server.live.getSegment({ videoUUID: liveId, segment: 0, playlistNumber: 0 }) | ||
66 | await makeRawRequest(video.streamingPlaylists[0].playlistUrl, HttpStatusCode.OK_200) | ||
67 | |||
68 | await wait(100) | ||
69 | } | ||
70 | } | ||
71 | |||
72 | async function runTest (replay: boolean) { | ||
73 | const { ffmpegCommand, liveVideoUUID } = await fastRestreamWrapper({ replay }) | ||
74 | |||
75 | await ensureLastLiveWorks(liveVideoUUID) | ||
76 | |||
77 | await stopFfmpeg(ffmpegCommand) | ||
78 | await server.live.waitUntilWaiting({ videoId: liveVideoUUID }) | ||
79 | |||
80 | // Wait for replays | ||
81 | await waitJobs([ server ]) | ||
82 | |||
83 | const { total, data: sessions } = await server.live.listSessions({ videoId: liveVideoUUID }) | ||
84 | |||
85 | expect(total).to.equal(2) | ||
86 | expect(sessions).to.have.lengthOf(2) | ||
87 | |||
88 | for (const session of sessions) { | ||
89 | expect(session.error).to.be.null | ||
90 | |||
91 | if (replay) { | ||
92 | expect(session.replayVideo).to.exist | ||
93 | |||
94 | await server.videos.get({ id: session.replayVideo.uuid }) | ||
95 | } else { | ||
96 | expect(session.replayVideo).to.not.exist | ||
97 | } | ||
98 | } | ||
99 | } | ||
100 | |||
101 | before(async function () { | ||
102 | this.timeout(120000) | ||
103 | |||
104 | const env = { 'PEERTUBE_TEST_CONSTANTS.VIDEO_LIVE.CLEANUP_DELAY': '10000' } | ||
105 | server = await createSingleServer(1, {}, { env }) | ||
106 | |||
107 | // Get the access tokens | ||
108 | await setAccessTokensToServers([ server ]) | ||
109 | await setDefaultVideoChannel([ server ]) | ||
110 | |||
111 | await server.config.enableMinimumTranscoding(false, true) | ||
112 | await server.config.enableLive({ allowReplay: true, transcoding: true, resolutions: 'min' }) | ||
113 | }) | ||
114 | |||
115 | it('Should correctly fast reastream in a permanent live with and without save replay', async function () { | ||
116 | this.timeout(240000) | ||
117 | |||
118 | // A test can take a long time, so prefer to run them in parallel | ||
119 | await Promise.all([ | ||
120 | runTest(true), | ||
121 | runTest(false) | ||
122 | ]) | ||
123 | }) | ||
124 | |||
125 | after(async function () { | ||
126 | await cleanupTests([ server ]) | ||
127 | }) | ||
128 | }) | ||
diff --git a/server/tests/api/live/live-save-replay.ts b/server/tests/api/live/live-save-replay.ts index 99d500711..7ddcb04ef 100644 --- a/server/tests/api/live/live-save-replay.ts +++ b/server/tests/api/live/live-save-replay.ts | |||
@@ -12,7 +12,6 @@ import { | |||
12 | createMultipleServers, | 12 | createMultipleServers, |
13 | doubleFollow, | 13 | doubleFollow, |
14 | findExternalSavedVideo, | 14 | findExternalSavedVideo, |
15 | makeRawRequest, | ||
16 | PeerTubeServer, | 15 | PeerTubeServer, |
17 | setAccessTokensToServers, | 16 | setAccessTokensToServers, |
18 | setDefaultVideoChannel, | 17 | setDefaultVideoChannel, |
@@ -442,46 +441,6 @@ describe('Save replay setting', function () { | |||
442 | await checkVideosExist(liveVideoUUID, false, HttpStatusCode.NOT_FOUND_404) | 441 | await checkVideosExist(liveVideoUUID, false, HttpStatusCode.NOT_FOUND_404) |
443 | await checkLiveCleanup(servers[0], liveVideoUUID, []) | 442 | await checkLiveCleanup(servers[0], liveVideoUUID, []) |
444 | }) | 443 | }) |
445 | |||
446 | it('Should correctly save replays with multiple sessions', async function () { | ||
447 | this.timeout(120000) | ||
448 | |||
449 | liveVideoUUID = await createLiveWrapper({ permanent: true, replay: true }) | ||
450 | await waitJobs(servers) | ||
451 | |||
452 | // Streaming session #1 | ||
453 | ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) | ||
454 | await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID) | ||
455 | await stopFfmpeg(ffmpegCommand) | ||
456 | await servers[0].live.waitUntilWaiting({ videoId: liveVideoUUID }) | ||
457 | |||
458 | // Streaming session #2 | ||
459 | ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) | ||
460 | await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID) | ||
461 | |||
462 | await wait(5000) | ||
463 | const video = await servers[0].videos.get({ id: liveVideoUUID }) | ||
464 | expect(video.streamingPlaylists).to.have.lengthOf(1) | ||
465 | await makeRawRequest(video.streamingPlaylists[0].playlistUrl) | ||
466 | |||
467 | await stopFfmpeg(ffmpegCommand) | ||
468 | await waitUntilLiveWaitingOnAllServers(servers, liveVideoUUID) | ||
469 | |||
470 | // Wait for replays | ||
471 | await waitJobs(servers) | ||
472 | |||
473 | const { total, data: sessions } = await servers[0].live.listSessions({ videoId: liveVideoUUID }) | ||
474 | |||
475 | expect(total).to.equal(2) | ||
476 | expect(sessions).to.have.lengthOf(2) | ||
477 | |||
478 | for (const session of sessions) { | ||
479 | expect(session.error).to.be.null | ||
480 | expect(session.replayVideo).to.exist | ||
481 | |||
482 | await servers[0].videos.get({ id: session.replayVideo.uuid }) | ||
483 | } | ||
484 | }) | ||
485 | }) | 444 | }) |
486 | 445 | ||
487 | after(async function () { | 446 | after(async function () { |
diff --git a/server/tests/api/live/live.ts b/server/tests/api/live/live.ts index b9caf394d..2d47c131b 100644 --- a/server/tests/api/live/live.ts +++ b/server/tests/api/live/live.ts | |||
@@ -395,7 +395,7 @@ describe('Test live', function () { | |||
395 | for (let i = 0; i < resolutions.length; i++) { | 395 | for (let i = 0; i < resolutions.length; i++) { |
396 | const segmentNum = 3 | 396 | const segmentNum = 3 |
397 | const segmentName = `${i}-00000${segmentNum}.ts` | 397 | const segmentName = `${i}-00000${segmentNum}.ts` |
398 | await commands[0].waitUntilSegmentGeneration({ videoUUID: video.uuid, resolution: i, segment: segmentNum }) | 398 | await commands[0].waitUntilSegmentGeneration({ videoUUID: video.uuid, playlistNumber: i, segment: segmentNum }) |
399 | 399 | ||
400 | const subPlaylist = await servers[0].streamingPlaylists.get({ | 400 | const subPlaylist = await servers[0].streamingPlaylists.get({ |
401 | url: `${servers[0].url}/static/streaming-playlists/hls/${video.uuid}/${i}.m3u8` | 401 | url: `${servers[0].url}/static/streaming-playlists/hls/${video.uuid}/${i}.m3u8` |
@@ -628,9 +628,9 @@ describe('Test live', function () { | |||
628 | commands[0].waitUntilPublished({ videoId: liveVideoReplayId }) | 628 | commands[0].waitUntilPublished({ videoId: liveVideoReplayId }) |
629 | ]) | 629 | ]) |
630 | 630 | ||
631 | await commands[0].waitUntilSegmentGeneration({ videoUUID: liveVideoId, resolution: 0, segment: 2 }) | 631 | await commands[0].waitUntilSegmentGeneration({ videoUUID: liveVideoId, playlistNumber: 0, segment: 2 }) |
632 | await commands[0].waitUntilSegmentGeneration({ videoUUID: liveVideoReplayId, resolution: 0, segment: 2 }) | 632 | await commands[0].waitUntilSegmentGeneration({ videoUUID: liveVideoReplayId, playlistNumber: 0, segment: 2 }) |
633 | await commands[0].waitUntilSegmentGeneration({ videoUUID: permanentLiveVideoReplayId, resolution: 0, segment: 2 }) | 633 | await commands[0].waitUntilSegmentGeneration({ videoUUID: permanentLiveVideoReplayId, playlistNumber: 0, segment: 2 }) |
634 | 634 | ||
635 | { | 635 | { |
636 | const video = await servers[0].videos.get({ id: permanentLiveVideoReplayId }) | 636 | const video = await servers[0].videos.get({ id: permanentLiveVideoReplayId }) |