diff options
Diffstat (limited to 'server/tests')
-rw-r--r-- | server/tests/api/live/live-fast-restream.ts | 2 | ||||
-rw-r--r-- | server/tests/api/live/live.ts | 87 | ||||
-rw-r--r-- | server/tests/api/object-storage/live.ts | 183 | ||||
-rw-r--r-- | server/tests/shared/live.ts | 116 | ||||
-rw-r--r-- | server/tests/shared/streaming-playlists.ts | 13 |
5 files changed, 270 insertions, 131 deletions
diff --git a/server/tests/api/live/live-fast-restream.ts b/server/tests/api/live/live-fast-restream.ts index 502959258..3ea6be9ff 100644 --- a/server/tests/api/live/live-fast-restream.ts +++ b/server/tests/api/live/live-fast-restream.ts | |||
@@ -59,7 +59,7 @@ describe('Fast restream in live', function () { | |||
59 | const video = await server.videos.get({ id: liveId }) | 59 | const video = await server.videos.get({ id: liveId }) |
60 | expect(video.streamingPlaylists).to.have.lengthOf(1) | 60 | expect(video.streamingPlaylists).to.have.lengthOf(1) |
61 | 61 | ||
62 | await server.live.getSegment({ videoUUID: liveId, segment: 0, playlistNumber: 0 }) | 62 | await server.live.getSegmentFile({ videoUUID: liveId, segment: 0, playlistNumber: 0 }) |
63 | await makeRawRequest(video.streamingPlaylists[0].playlistUrl, HttpStatusCode.OK_200) | 63 | await makeRawRequest(video.streamingPlaylists[0].playlistUrl, HttpStatusCode.OK_200) |
64 | await makeRawRequest(video.streamingPlaylists[0].segmentsSha256Url, HttpStatusCode.OK_200) | 64 | await makeRawRequest(video.streamingPlaylists[0].segmentsSha256Url, HttpStatusCode.OK_200) |
65 | 65 | ||
diff --git a/server/tests/api/live/live.ts b/server/tests/api/live/live.ts index 4e070832d..5dd2bd9ab 100644 --- a/server/tests/api/live/live.ts +++ b/server/tests/api/live/live.ts | |||
@@ -3,7 +3,7 @@ | |||
3 | import { expect } from 'chai' | 3 | import { expect } from 'chai' |
4 | import { basename, join } from 'path' | 4 | import { basename, join } from 'path' |
5 | import { ffprobePromise, getVideoStream } from '@server/helpers/ffmpeg' | 5 | import { ffprobePromise, getVideoStream } from '@server/helpers/ffmpeg' |
6 | import { checkLiveSegmentHash, checkResolutionsInMasterPlaylist, testImage } from '@server/tests/shared' | 6 | import { testImage, testVideoResolutions } from '@server/tests/shared' |
7 | import { getAllFiles, wait } from '@shared/core-utils' | 7 | import { getAllFiles, wait } from '@shared/core-utils' |
8 | import { | 8 | import { |
9 | HttpStatusCode, | 9 | HttpStatusCode, |
@@ -372,46 +372,6 @@ describe('Test live', function () { | |||
372 | return uuid | 372 | return uuid |
373 | } | 373 | } |
374 | 374 | ||
375 | async function testVideoResolutions (liveVideoId: string, resolutions: number[]) { | ||
376 | for (const server of servers) { | ||
377 | const { data } = await server.videos.list() | ||
378 | expect(data.find(v => v.uuid === liveVideoId)).to.exist | ||
379 | |||
380 | const video = await server.videos.get({ id: liveVideoId }) | ||
381 | |||
382 | expect(video.streamingPlaylists).to.have.lengthOf(1) | ||
383 | |||
384 | const hlsPlaylist = video.streamingPlaylists.find(s => s.type === VideoStreamingPlaylistType.HLS) | ||
385 | expect(hlsPlaylist).to.exist | ||
386 | |||
387 | // Only finite files are displayed | ||
388 | expect(hlsPlaylist.files).to.have.lengthOf(0) | ||
389 | |||
390 | await checkResolutionsInMasterPlaylist({ server, playlistUrl: hlsPlaylist.playlistUrl, resolutions }) | ||
391 | |||
392 | for (let i = 0; i < resolutions.length; i++) { | ||
393 | const segmentNum = 3 | ||
394 | const segmentName = `${i}-00000${segmentNum}.ts` | ||
395 | await commands[0].waitUntilSegmentGeneration({ videoUUID: video.uuid, playlistNumber: i, segment: segmentNum }) | ||
396 | |||
397 | const subPlaylist = await servers[0].streamingPlaylists.get({ | ||
398 | url: `${servers[0].url}/static/streaming-playlists/hls/${video.uuid}/${i}.m3u8` | ||
399 | }) | ||
400 | |||
401 | expect(subPlaylist).to.contain(segmentName) | ||
402 | |||
403 | const baseUrlAndPath = servers[0].url + '/static/streaming-playlists/hls' | ||
404 | await checkLiveSegmentHash({ | ||
405 | server, | ||
406 | baseUrlSegment: baseUrlAndPath, | ||
407 | videoUUID: video.uuid, | ||
408 | segmentName, | ||
409 | hlsPlaylist | ||
410 | }) | ||
411 | } | ||
412 | } | ||
413 | } | ||
414 | |||
415 | function updateConf (resolutions: number[]) { | 375 | function updateConf (resolutions: number[]) { |
416 | return servers[0].config.updateCustomSubConfig({ | 376 | return servers[0].config.updateCustomSubConfig({ |
417 | newConfig: { | 377 | newConfig: { |
@@ -449,7 +409,14 @@ describe('Test live', function () { | |||
449 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) | 409 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) |
450 | await waitJobs(servers) | 410 | await waitJobs(servers) |
451 | 411 | ||
452 | await testVideoResolutions(liveVideoId, [ 720 ]) | 412 | await testVideoResolutions({ |
413 | originServer: servers[0], | ||
414 | servers, | ||
415 | liveVideoId, | ||
416 | resolutions: [ 720 ], | ||
417 | objectStorage: false, | ||
418 | transcoded: true | ||
419 | }) | ||
453 | 420 | ||
454 | await stopFfmpeg(ffmpegCommand) | 421 | await stopFfmpeg(ffmpegCommand) |
455 | }) | 422 | }) |
@@ -477,7 +444,14 @@ describe('Test live', function () { | |||
477 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) | 444 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) |
478 | await waitJobs(servers) | 445 | await waitJobs(servers) |
479 | 446 | ||
480 | await testVideoResolutions(liveVideoId, resolutions.concat([ 720 ])) | 447 | await testVideoResolutions({ |
448 | originServer: servers[0], | ||
449 | servers, | ||
450 | liveVideoId, | ||
451 | resolutions: resolutions.concat([ 720 ]), | ||
452 | objectStorage: false, | ||
453 | transcoded: true | ||
454 | }) | ||
481 | 455 | ||
482 | await stopFfmpeg(ffmpegCommand) | 456 | await stopFfmpeg(ffmpegCommand) |
483 | }) | 457 | }) |
@@ -522,7 +496,14 @@ describe('Test live', function () { | |||
522 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) | 496 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) |
523 | await waitJobs(servers) | 497 | await waitJobs(servers) |
524 | 498 | ||
525 | await testVideoResolutions(liveVideoId, resolutions) | 499 | await testVideoResolutions({ |
500 | originServer: servers[0], | ||
501 | servers, | ||
502 | liveVideoId, | ||
503 | resolutions, | ||
504 | objectStorage: false, | ||
505 | transcoded: true | ||
506 | }) | ||
526 | 507 | ||
527 | await stopFfmpeg(ffmpegCommand) | 508 | await stopFfmpeg(ffmpegCommand) |
528 | await commands[0].waitUntilEnded({ videoId: liveVideoId }) | 509 | await commands[0].waitUntilEnded({ videoId: liveVideoId }) |
@@ -611,7 +592,14 @@ describe('Test live', function () { | |||
611 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) | 592 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) |
612 | await waitJobs(servers) | 593 | await waitJobs(servers) |
613 | 594 | ||
614 | await testVideoResolutions(liveVideoId, resolutions) | 595 | await testVideoResolutions({ |
596 | originServer: servers[0], | ||
597 | servers, | ||
598 | liveVideoId, | ||
599 | resolutions, | ||
600 | objectStorage: false, | ||
601 | transcoded: true | ||
602 | }) | ||
615 | 603 | ||
616 | await stopFfmpeg(ffmpegCommand) | 604 | await stopFfmpeg(ffmpegCommand) |
617 | await commands[0].waitUntilEnded({ videoId: liveVideoId }) | 605 | await commands[0].waitUntilEnded({ videoId: liveVideoId }) |
@@ -640,7 +628,14 @@ describe('Test live', function () { | |||
640 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) | 628 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) |
641 | await waitJobs(servers) | 629 | await waitJobs(servers) |
642 | 630 | ||
643 | await testVideoResolutions(liveVideoId, [ 720 ]) | 631 | await testVideoResolutions({ |
632 | originServer: servers[0], | ||
633 | servers, | ||
634 | liveVideoId, | ||
635 | resolutions: [ 720 ], | ||
636 | objectStorage: false, | ||
637 | transcoded: true | ||
638 | }) | ||
644 | 639 | ||
645 | await stopFfmpeg(ffmpegCommand) | 640 | await stopFfmpeg(ffmpegCommand) |
646 | await commands[0].waitUntilEnded({ videoId: liveVideoId }) | 641 | await commands[0].waitUntilEnded({ videoId: liveVideoId }) |
diff --git a/server/tests/api/object-storage/live.ts b/server/tests/api/object-storage/live.ts index 0958ffe0f..7e16b4c89 100644 --- a/server/tests/api/object-storage/live.ts +++ b/server/tests/api/object-storage/live.ts | |||
@@ -1,9 +1,9 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | 2 | ||
3 | import { expect } from 'chai' | 3 | import { expect } from 'chai' |
4 | import { expectStartWith } from '@server/tests/shared' | 4 | import { expectStartWith, testVideoResolutions } from '@server/tests/shared' |
5 | import { areObjectStorageTestsDisabled } from '@shared/core-utils' | 5 | import { areObjectStorageTestsDisabled } from '@shared/core-utils' |
6 | import { HttpStatusCode, LiveVideoCreate, VideoFile, VideoPrivacy } from '@shared/models' | 6 | import { HttpStatusCode, LiveVideoCreate, VideoPrivacy } from '@shared/models' |
7 | import { | 7 | import { |
8 | createMultipleServers, | 8 | createMultipleServers, |
9 | doubleFollow, | 9 | doubleFollow, |
@@ -35,41 +35,43 @@ async function createLive (server: PeerTubeServer, permanent: boolean) { | |||
35 | return uuid | 35 | return uuid |
36 | } | 36 | } |
37 | 37 | ||
38 | async function checkFiles (files: VideoFile[]) { | 38 | async function checkFilesExist (servers: PeerTubeServer[], videoUUID: string, numberOfFiles: number) { |
39 | for (const file of files) { | 39 | for (const server of servers) { |
40 | expectStartWith(file.fileUrl, ObjectStorageCommand.getPlaylistBaseUrl()) | 40 | const video = await server.videos.get({ id: videoUUID }) |
41 | 41 | ||
42 | await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200) | 42 | expect(video.files).to.have.lengthOf(0) |
43 | } | 43 | expect(video.streamingPlaylists).to.have.lengthOf(1) |
44 | } | ||
45 | 44 | ||
46 | async function getFiles (server: PeerTubeServer, videoUUID: string) { | 45 | const files = video.streamingPlaylists[0].files |
47 | const video = await server.videos.get({ id: videoUUID }) | 46 | expect(files).to.have.lengthOf(numberOfFiles) |
48 | 47 | ||
49 | expect(video.files).to.have.lengthOf(0) | 48 | for (const file of files) { |
50 | expect(video.streamingPlaylists).to.have.lengthOf(1) | 49 | expectStartWith(file.fileUrl, ObjectStorageCommand.getPlaylistBaseUrl()) |
51 | 50 | ||
52 | return video.streamingPlaylists[0].files | 51 | await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200) |
52 | } | ||
53 | } | ||
53 | } | 54 | } |
54 | 55 | ||
55 | async function streamAndEnd (servers: PeerTubeServer[], liveUUID: string) { | 56 | async function checkFilesCleanup (server: PeerTubeServer, videoUUID: string, resolutions: number[]) { |
56 | const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveUUID }) | 57 | const resolutionFiles = resolutions.map((_value, i) => `${i}.m3u8`) |
57 | await waitUntilLivePublishedOnAllServers(servers, liveUUID) | ||
58 | |||
59 | const videoLiveDetails = await servers[0].videos.get({ id: liveUUID }) | ||
60 | const liveDetails = await servers[0].live.get({ videoId: liveUUID }) | ||
61 | 58 | ||
62 | await stopFfmpeg(ffmpegCommand) | 59 | for (const playlistName of [ 'master.m3u8' ].concat(resolutionFiles)) { |
63 | 60 | await server.live.getPlaylistFile({ | |
64 | if (liveDetails.permanentLive) { | 61 | videoUUID, |
65 | await waitUntilLiveWaitingOnAllServers(servers, liveUUID) | 62 | playlistName, |
66 | } else { | 63 | expectedStatus: HttpStatusCode.NOT_FOUND_404, |
67 | await waitUntilLiveReplacedByReplayOnAllServers(servers, liveUUID) | 64 | objectStorage: true |
65 | }) | ||
68 | } | 66 | } |
69 | 67 | ||
70 | await waitJobs(servers) | 68 | await server.live.getSegmentFile({ |
71 | 69 | videoUUID, | |
72 | return { videoLiveDetails, liveDetails } | 70 | playlistNumber: 0, |
71 | segment: 0, | ||
72 | objectStorage: true, | ||
73 | expectedStatus: HttpStatusCode.NOT_FOUND_404 | ||
74 | }) | ||
73 | } | 75 | } |
74 | 76 | ||
75 | describe('Object storage for lives', function () { | 77 | describe('Object storage for lives', function () { |
@@ -100,57 +102,124 @@ describe('Object storage for lives', function () { | |||
100 | videoUUID = await createLive(servers[0], false) | 102 | videoUUID = await createLive(servers[0], false) |
101 | }) | 103 | }) |
102 | 104 | ||
103 | it('Should create a live and save the replay on object storage', async function () { | 105 | it('Should create a live and publish it on object storage', async function () { |
106 | this.timeout(220000) | ||
107 | |||
108 | const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: videoUUID }) | ||
109 | await waitUntilLivePublishedOnAllServers(servers, videoUUID) | ||
110 | |||
111 | await testVideoResolutions({ | ||
112 | originServer: servers[0], | ||
113 | servers, | ||
114 | liveVideoId: videoUUID, | ||
115 | resolutions: [ 720 ], | ||
116 | transcoded: false, | ||
117 | objectStorage: true | ||
118 | }) | ||
119 | |||
120 | await stopFfmpeg(ffmpegCommand) | ||
121 | }) | ||
122 | |||
123 | it('Should have saved the replay on object storage', async function () { | ||
104 | this.timeout(220000) | 124 | this.timeout(220000) |
105 | 125 | ||
106 | await streamAndEnd(servers, videoUUID) | 126 | await waitUntilLiveReplacedByReplayOnAllServers(servers, videoUUID) |
127 | await waitJobs(servers) | ||
107 | 128 | ||
108 | for (const server of servers) { | 129 | await checkFilesExist(servers, videoUUID, 1) |
109 | const files = await getFiles(server, videoUUID) | 130 | }) |
110 | expect(files).to.have.lengthOf(1) | ||
111 | 131 | ||
112 | await checkFiles(files) | 132 | it('Should have cleaned up live files from object storage', async function () { |
113 | } | 133 | await checkFilesCleanup(servers[0], videoUUID, [ 720 ]) |
114 | }) | 134 | }) |
115 | }) | 135 | }) |
116 | 136 | ||
117 | describe('With live transcoding', async function () { | 137 | describe('With live transcoding', async function () { |
118 | let videoUUIDPermanent: string | 138 | const resolutions = [ 720, 480, 360, 240, 144 ] |
119 | let videoUUIDNonPermanent: string | ||
120 | 139 | ||
121 | before(async function () { | 140 | before(async function () { |
122 | await servers[0].config.enableLive({ transcoding: true }) | 141 | await servers[0].config.enableLive({ transcoding: true }) |
123 | |||
124 | videoUUIDPermanent = await createLive(servers[0], true) | ||
125 | videoUUIDNonPermanent = await createLive(servers[0], false) | ||
126 | }) | 142 | }) |
127 | 143 | ||
128 | it('Should create a live and save the replay on object storage', async function () { | 144 | describe('Normal replay', function () { |
129 | this.timeout(240000) | 145 | let videoUUIDNonPermanent: string |
146 | |||
147 | before(async function () { | ||
148 | videoUUIDNonPermanent = await createLive(servers[0], false) | ||
149 | }) | ||
150 | |||
151 | it('Should create a live and publish it on object storage', async function () { | ||
152 | this.timeout(240000) | ||
153 | |||
154 | const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: videoUUIDNonPermanent }) | ||
155 | await waitUntilLivePublishedOnAllServers(servers, videoUUIDNonPermanent) | ||
156 | |||
157 | await testVideoResolutions({ | ||
158 | originServer: servers[0], | ||
159 | servers, | ||
160 | liveVideoId: videoUUIDNonPermanent, | ||
161 | resolutions, | ||
162 | transcoded: true, | ||
163 | objectStorage: true | ||
164 | }) | ||
165 | |||
166 | await stopFfmpeg(ffmpegCommand) | ||
167 | }) | ||
130 | 168 | ||
131 | await streamAndEnd(servers, videoUUIDNonPermanent) | 169 | it('Should have saved the replay on object storage', async function () { |
170 | this.timeout(220000) | ||
132 | 171 | ||
133 | for (const server of servers) { | 172 | await waitUntilLiveReplacedByReplayOnAllServers(servers, videoUUIDNonPermanent) |
134 | const files = await getFiles(server, videoUUIDNonPermanent) | 173 | await waitJobs(servers) |
135 | expect(files).to.have.lengthOf(5) | ||
136 | 174 | ||
137 | await checkFiles(files) | 175 | await checkFilesExist(servers, videoUUIDNonPermanent, 5) |
138 | } | 176 | }) |
177 | |||
178 | it('Should have cleaned up live files from object storage', async function () { | ||
179 | await checkFilesCleanup(servers[0], videoUUIDNonPermanent, resolutions) | ||
180 | }) | ||
139 | }) | 181 | }) |
140 | 182 | ||
141 | it('Should create a live and save the replay of permanent live on object storage', async function () { | 183 | describe('Permanent replay', function () { |
142 | this.timeout(240000) | 184 | let videoUUIDPermanent: string |
185 | |||
186 | before(async function () { | ||
187 | videoUUIDPermanent = await createLive(servers[0], true) | ||
188 | }) | ||
189 | |||
190 | it('Should create a live and publish it on object storage', async function () { | ||
191 | this.timeout(240000) | ||
192 | |||
193 | const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: videoUUIDPermanent }) | ||
194 | await waitUntilLivePublishedOnAllServers(servers, videoUUIDPermanent) | ||
195 | |||
196 | await testVideoResolutions({ | ||
197 | originServer: servers[0], | ||
198 | servers, | ||
199 | liveVideoId: videoUUIDPermanent, | ||
200 | resolutions, | ||
201 | transcoded: true, | ||
202 | objectStorage: true | ||
203 | }) | ||
204 | |||
205 | await stopFfmpeg(ffmpegCommand) | ||
206 | }) | ||
207 | |||
208 | it('Should have saved the replay on object storage', async function () { | ||
209 | this.timeout(220000) | ||
143 | 210 | ||
144 | const { videoLiveDetails } = await streamAndEnd(servers, videoUUIDPermanent) | 211 | await waitUntilLiveWaitingOnAllServers(servers, videoUUIDPermanent) |
212 | await waitJobs(servers) | ||
145 | 213 | ||
146 | const replay = await findExternalSavedVideo(servers[0], videoLiveDetails) | 214 | const videoLiveDetails = await servers[0].videos.get({ id: videoUUIDPermanent }) |
215 | const replay = await findExternalSavedVideo(servers[0], videoLiveDetails) | ||
147 | 216 | ||
148 | for (const server of servers) { | 217 | await checkFilesExist(servers, replay.uuid, 5) |
149 | const files = await getFiles(server, replay.uuid) | 218 | }) |
150 | expect(files).to.have.lengthOf(5) | ||
151 | 219 | ||
152 | await checkFiles(files) | 220 | it('Should have cleaned up live files from object storage', async function () { |
153 | } | 221 | await checkFilesCleanup(servers[0], videoUUIDPermanent, resolutions) |
222 | }) | ||
154 | }) | 223 | }) |
155 | }) | 224 | }) |
156 | 225 | ||
diff --git a/server/tests/shared/live.ts b/server/tests/shared/live.ts index 4bd4786fc..aa79622cb 100644 --- a/server/tests/shared/live.ts +++ b/server/tests/shared/live.ts | |||
@@ -3,39 +3,92 @@ | |||
3 | import { expect } from 'chai' | 3 | import { expect } from 'chai' |
4 | import { pathExists, readdir } from 'fs-extra' | 4 | import { pathExists, readdir } from 'fs-extra' |
5 | import { join } from 'path' | 5 | import { join } from 'path' |
6 | import { LiveVideo } from '@shared/models' | 6 | import { wait } from '@shared/core-utils' |
7 | import { PeerTubeServer } from '@shared/server-commands' | 7 | import { LiveVideo, VideoStreamingPlaylistType } from '@shared/models' |
8 | import { ObjectStorageCommand, PeerTubeServer } from '@shared/server-commands' | ||
9 | import { checkLiveSegmentHash, checkResolutionsInMasterPlaylist } from './streaming-playlists' | ||
8 | 10 | ||
9 | async function checkLiveCleanup (server: PeerTubeServer, videoUUID: string, savedResolutions: number[] = []) { | 11 | async function checkLiveCleanup (server: PeerTubeServer, videoUUID: string, savedResolutions: number[] = []) { |
10 | let live: LiveVideo | ||
11 | |||
12 | try { | ||
13 | live = await server.live.get({ videoId: videoUUID }) | ||
14 | } catch {} | ||
15 | |||
16 | const basePath = server.servers.buildDirectory('streaming-playlists') | 12 | const basePath = server.servers.buildDirectory('streaming-playlists') |
17 | const hlsPath = join(basePath, 'hls', videoUUID) | 13 | const hlsPath = join(basePath, 'hls', videoUUID) |
18 | 14 | ||
19 | if (savedResolutions.length === 0) { | 15 | if (savedResolutions.length === 0) { |
16 | return checkUnsavedLiveCleanup(server, videoUUID, hlsPath) | ||
17 | } | ||
18 | |||
19 | return checkSavedLiveCleanup(hlsPath, savedResolutions) | ||
20 | } | ||
21 | |||
22 | // --------------------------------------------------------------------------- | ||
20 | 23 | ||
21 | if (live?.permanentLive) { | 24 | async function testVideoResolutions (options: { |
22 | expect(await pathExists(hlsPath)).to.be.true | 25 | originServer: PeerTubeServer |
26 | servers: PeerTubeServer[] | ||
27 | liveVideoId: string | ||
28 | resolutions: number[] | ||
29 | transcoded: boolean | ||
30 | objectStorage: boolean | ||
31 | }) { | ||
32 | const { originServer, servers, liveVideoId, resolutions, transcoded, objectStorage } = options | ||
23 | 33 | ||
24 | const hlsFiles = await readdir(hlsPath) | 34 | for (const server of servers) { |
25 | expect(hlsFiles).to.have.lengthOf(1) // Only replays directory | 35 | const { data } = await server.videos.list() |
36 | expect(data.find(v => v.uuid === liveVideoId)).to.exist | ||
26 | 37 | ||
27 | const replayDir = join(hlsPath, 'replay') | 38 | const video = await server.videos.get({ id: liveVideoId }) |
28 | expect(await pathExists(replayDir)).to.be.true | 39 | expect(video.streamingPlaylists).to.have.lengthOf(1) |
29 | 40 | ||
30 | const replayFiles = await readdir(join(hlsPath, 'replay')) | 41 | const hlsPlaylist = video.streamingPlaylists.find(s => s.type === VideoStreamingPlaylistType.HLS) |
31 | expect(replayFiles).to.have.lengthOf(0) | 42 | expect(hlsPlaylist).to.exist |
32 | } else { | 43 | expect(hlsPlaylist.files).to.have.lengthOf(0) // Only fragmented mp4 files are displayed |
33 | expect(await pathExists(hlsPath)).to.be.false | 44 | |
45 | await checkResolutionsInMasterPlaylist({ server, playlistUrl: hlsPlaylist.playlistUrl, resolutions, transcoded }) | ||
46 | |||
47 | if (objectStorage) { | ||
48 | expect(hlsPlaylist.playlistUrl).to.contain(ObjectStorageCommand.getPlaylistBaseUrl()) | ||
34 | } | 49 | } |
35 | 50 | ||
36 | return | 51 | for (let i = 0; i < resolutions.length; i++) { |
52 | const segmentNum = 3 | ||
53 | const segmentName = `${i}-00000${segmentNum}.ts` | ||
54 | await originServer.live.waitUntilSegmentGeneration({ videoUUID: video.uuid, playlistNumber: i, segment: segmentNum }) | ||
55 | |||
56 | const baseUrl = objectStorage | ||
57 | ? ObjectStorageCommand.getPlaylistBaseUrl() + 'hls' | ||
58 | : originServer.url + '/static/streaming-playlists/hls' | ||
59 | |||
60 | if (objectStorage) { | ||
61 | // Playlist file upload | ||
62 | await wait(500) | ||
63 | |||
64 | expect(hlsPlaylist.segmentsSha256Url).to.contain(ObjectStorageCommand.getPlaylistBaseUrl()) | ||
65 | } | ||
66 | |||
67 | const subPlaylist = await originServer.streamingPlaylists.get({ url: `${baseUrl}/${video.uuid}/${i}.m3u8` }) | ||
68 | |||
69 | expect(subPlaylist).to.contain(segmentName) | ||
70 | |||
71 | await checkLiveSegmentHash({ | ||
72 | server, | ||
73 | baseUrlSegment: baseUrl, | ||
74 | videoUUID: video.uuid, | ||
75 | segmentName, | ||
76 | hlsPlaylist | ||
77 | }) | ||
78 | } | ||
37 | } | 79 | } |
80 | } | ||
81 | |||
82 | // --------------------------------------------------------------------------- | ||
83 | |||
84 | export { | ||
85 | checkLiveCleanup, | ||
86 | testVideoResolutions | ||
87 | } | ||
38 | 88 | ||
89 | // --------------------------------------------------------------------------- | ||
90 | |||
91 | async function checkSavedLiveCleanup (hlsPath: string, savedResolutions: number[] = []) { | ||
39 | const files = await readdir(hlsPath) | 92 | const files = await readdir(hlsPath) |
40 | 93 | ||
41 | // fragmented file and playlist per resolution + master playlist + segments sha256 json file | 94 | // fragmented file and playlist per resolution + master playlist + segments sha256 json file |
@@ -56,6 +109,27 @@ async function checkLiveCleanup (server: PeerTubeServer, videoUUID: string, save | |||
56 | expect(shaFile).to.exist | 109 | expect(shaFile).to.exist |
57 | } | 110 | } |
58 | 111 | ||
59 | export { | 112 | async function checkUnsavedLiveCleanup (server: PeerTubeServer, videoUUID: string, hlsPath: string) { |
60 | checkLiveCleanup | 113 | let live: LiveVideo |
114 | |||
115 | try { | ||
116 | live = await server.live.get({ videoId: videoUUID }) | ||
117 | } catch {} | ||
118 | |||
119 | if (live?.permanentLive) { | ||
120 | expect(await pathExists(hlsPath)).to.be.true | ||
121 | |||
122 | const hlsFiles = await readdir(hlsPath) | ||
123 | expect(hlsFiles).to.have.lengthOf(1) // Only replays directory | ||
124 | |||
125 | const replayDir = join(hlsPath, 'replay') | ||
126 | expect(await pathExists(replayDir)).to.be.true | ||
127 | |||
128 | const replayFiles = await readdir(join(hlsPath, 'replay')) | ||
129 | expect(replayFiles).to.have.lengthOf(0) | ||
130 | |||
131 | return | ||
132 | } | ||
133 | |||
134 | expect(await pathExists(hlsPath)).to.be.false | ||
61 | } | 135 | } |
diff --git a/server/tests/shared/streaming-playlists.ts b/server/tests/shared/streaming-playlists.ts index 4d82b3654..eff34944b 100644 --- a/server/tests/shared/streaming-playlists.ts +++ b/server/tests/shared/streaming-playlists.ts | |||
@@ -26,7 +26,7 @@ async function checkSegmentHash (options: { | |||
26 | const offset = parseInt(matches[2], 10) | 26 | const offset = parseInt(matches[2], 10) |
27 | const range = `${offset}-${offset + length - 1}` | 27 | const range = `${offset}-${offset + length - 1}` |
28 | 28 | ||
29 | const segmentBody = await command.getSegment({ | 29 | const segmentBody = await command.getFragmentedSegment({ |
30 | url: `${baseUrlSegment}/${videoName}`, | 30 | url: `${baseUrlSegment}/${videoName}`, |
31 | expectedStatus: HttpStatusCode.PARTIAL_CONTENT_206, | 31 | expectedStatus: HttpStatusCode.PARTIAL_CONTENT_206, |
32 | range: `bytes=${range}` | 32 | range: `bytes=${range}` |
@@ -46,7 +46,7 @@ async function checkLiveSegmentHash (options: { | |||
46 | const { server, baseUrlSegment, videoUUID, segmentName, hlsPlaylist } = options | 46 | const { server, baseUrlSegment, videoUUID, segmentName, hlsPlaylist } = options |
47 | const command = server.streamingPlaylists | 47 | const command = server.streamingPlaylists |
48 | 48 | ||
49 | const segmentBody = await command.getSegment({ url: `${baseUrlSegment}/${videoUUID}/${segmentName}` }) | 49 | const segmentBody = await command.getFragmentedSegment({ url: `${baseUrlSegment}/${videoUUID}/${segmentName}` }) |
50 | const shaBody = await command.getSegmentSha256({ url: hlsPlaylist.segmentsSha256Url }) | 50 | const shaBody = await command.getSegmentSha256({ url: hlsPlaylist.segmentsSha256Url }) |
51 | 51 | ||
52 | expect(sha256(segmentBody)).to.equal(shaBody[segmentName]) | 52 | expect(sha256(segmentBody)).to.equal(shaBody[segmentName]) |
@@ -56,15 +56,16 @@ async function checkResolutionsInMasterPlaylist (options: { | |||
56 | server: PeerTubeServer | 56 | server: PeerTubeServer |
57 | playlistUrl: string | 57 | playlistUrl: string |
58 | resolutions: number[] | 58 | resolutions: number[] |
59 | transcoded?: boolean // default true | ||
59 | }) { | 60 | }) { |
60 | const { server, playlistUrl, resolutions } = options | 61 | const { server, playlistUrl, resolutions, transcoded = true } = options |
61 | 62 | ||
62 | const masterPlaylist = await server.streamingPlaylists.get({ url: playlistUrl }) | 63 | const masterPlaylist = await server.streamingPlaylists.get({ url: playlistUrl }) |
63 | 64 | ||
64 | for (const resolution of resolutions) { | 65 | for (const resolution of resolutions) { |
65 | const reg = new RegExp( | 66 | const reg = transcoded |
66 | '#EXT-X-STREAM-INF:BANDWIDTH=\\d+,RESOLUTION=\\d+x' + resolution + ',(FRAME-RATE=\\d+,)?CODECS="avc1.64001f,mp4a.40.2"' | 67 | ? new RegExp('#EXT-X-STREAM-INF:BANDWIDTH=\\d+,RESOLUTION=\\d+x' + resolution + ',(FRAME-RATE=\\d+,)?CODECS="avc1.64001f,mp4a.40.2"') |
67 | ) | 68 | : new RegExp('#EXT-X-STREAM-INF:BANDWIDTH=\\d+,RESOLUTION=\\d+x' + resolution + '') |
68 | 69 | ||
69 | expect(masterPlaylist).to.match(reg) | 70 | expect(masterPlaylist).to.match(reg) |
70 | } | 71 | } |