aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/shared
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/shared')
-rw-r--r--server/tests/shared/actors.ts8
-rw-r--r--server/tests/shared/directories.ts8
-rw-r--r--server/tests/shared/live.ts119
-rw-r--r--server/tests/shared/playlists.ts9
-rw-r--r--server/tests/shared/streaming-playlists.ts13
5 files changed, 112 insertions, 45 deletions
diff --git a/server/tests/shared/actors.ts b/server/tests/shared/actors.ts
index f8f4a5137..41fd72e89 100644
--- a/server/tests/shared/actors.ts
+++ b/server/tests/shared/actors.ts
@@ -2,8 +2,6 @@
2 2
3import { expect } from 'chai' 3import { expect } from 'chai'
4import { pathExists, readdir } from 'fs-extra' 4import { pathExists, readdir } from 'fs-extra'
5import { join } from 'path'
6import { root } from '@shared/core-utils'
7import { Account, VideoChannel } from '@shared/models' 5import { Account, VideoChannel } from '@shared/models'
8import { PeerTubeServer } from '@shared/server-commands' 6import { PeerTubeServer } from '@shared/server-commands'
9 7
@@ -31,11 +29,9 @@ async function expectAccountFollows (options: {
31 return expectActorFollow({ ...options, data }) 29 return expectActorFollow({ ...options, data })
32} 30}
33 31
34async function checkActorFilesWereRemoved (filename: string, serverNumber: number) { 32async function checkActorFilesWereRemoved (filename: string, server: PeerTubeServer) {
35 const testDirectory = 'test' + serverNumber
36
37 for (const directory of [ 'avatars' ]) { 33 for (const directory of [ 'avatars' ]) {
38 const directoryPath = join(root(), testDirectory, directory) 34 const directoryPath = server.getDirectoryPath(directory)
39 35
40 const directoryExists = await pathExists(directoryPath) 36 const directoryExists = await pathExists(directoryPath)
41 expect(directoryExists).to.be.true 37 expect(directoryExists).to.be.true
diff --git a/server/tests/shared/directories.ts b/server/tests/shared/directories.ts
index c7065a767..90d534a06 100644
--- a/server/tests/shared/directories.ts
+++ b/server/tests/shared/directories.ts
@@ -2,22 +2,18 @@
2 2
3import { expect } from 'chai' 3import { expect } from 'chai'
4import { pathExists, readdir } from 'fs-extra' 4import { pathExists, readdir } from 'fs-extra'
5import { join } from 'path'
6import { root } from '@shared/core-utils'
7import { PeerTubeServer } from '@shared/server-commands' 5import { PeerTubeServer } from '@shared/server-commands'
8 6
9async function checkTmpIsEmpty (server: PeerTubeServer) { 7async function checkTmpIsEmpty (server: PeerTubeServer) {
10 await checkDirectoryIsEmpty(server, 'tmp', [ 'plugins-global.css', 'hls', 'resumable-uploads' ]) 8 await checkDirectoryIsEmpty(server, 'tmp', [ 'plugins-global.css', 'hls', 'resumable-uploads' ])
11 9
12 if (await pathExists(join('test' + server.internalServerNumber, 'tmp', 'hls'))) { 10 if (await pathExists(server.getDirectoryPath('tmp/hls'))) {
13 await checkDirectoryIsEmpty(server, 'tmp/hls') 11 await checkDirectoryIsEmpty(server, 'tmp/hls')
14 } 12 }
15} 13}
16 14
17async function checkDirectoryIsEmpty (server: PeerTubeServer, directory: string, exceptions: string[] = []) { 15async function checkDirectoryIsEmpty (server: PeerTubeServer, directory: string, exceptions: string[] = []) {
18 const testDirectory = 'test' + server.internalServerNumber 16 const directoryPath = server.getDirectoryPath(directory)
19
20 const directoryPath = join(root(), testDirectory, directory)
21 17
22 const directoryExists = await pathExists(directoryPath) 18 const directoryExists = await pathExists(directoryPath)
23 expect(directoryExists).to.be.true 19 expect(directoryExists).to.be.true
diff --git a/server/tests/shared/live.ts b/server/tests/shared/live.ts
index 4bd4786fc..f165832fe 100644
--- a/server/tests/shared/live.ts
+++ b/server/tests/shared/live.ts
@@ -3,39 +3,95 @@
3import { expect } from 'chai' 3import { expect } from 'chai'
4import { pathExists, readdir } from 'fs-extra' 4import { pathExists, readdir } from 'fs-extra'
5import { join } from 'path' 5import { join } from 'path'
6import { LiveVideo } from '@shared/models' 6import { wait } from '@shared/core-utils'
7import { PeerTubeServer } from '@shared/server-commands' 7import { LiveVideo, VideoStreamingPlaylistType } from '@shared/models'
8import { ObjectStorageCommand, PeerTubeServer } from '@shared/server-commands'
9import { checkLiveSegmentHash, checkResolutionsInMasterPlaylist } from './streaming-playlists'
8 10
9async function checkLiveCleanup (server: PeerTubeServer, videoUUID: string, savedResolutions: number[] = []) { 11async 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) { 24async 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 await originServer.live.waitUntilSegmentUpload({ playlistNumber: i, segment: segmentNum })
62 await wait(1000)
63
64 expect(hlsPlaylist.segmentsSha256Url).to.contain(ObjectStorageCommand.getPlaylistBaseUrl())
65 }
66
67 const subPlaylist = await originServer.streamingPlaylists.get({
68 url: `${baseUrl}/${video.uuid}/${i}.m3u8`,
69 withRetry: objectStorage // With object storage, the request may fail because of inconsistent data in S3
70 })
71
72 expect(subPlaylist).to.contain(segmentName)
73
74 await checkLiveSegmentHash({
75 server,
76 baseUrlSegment: baseUrl,
77 videoUUID: video.uuid,
78 segmentName,
79 hlsPlaylist
80 })
81 }
37 } 82 }
83}
84
85// ---------------------------------------------------------------------------
86
87export {
88 checkLiveCleanup,
89 testVideoResolutions
90}
38 91
92// ---------------------------------------------------------------------------
93
94async function checkSavedLiveCleanup (hlsPath: string, savedResolutions: number[] = []) {
39 const files = await readdir(hlsPath) 95 const files = await readdir(hlsPath)
40 96
41 // fragmented file and playlist per resolution + master playlist + segments sha256 json file 97 // fragmented file and playlist per resolution + master playlist + segments sha256 json file
@@ -56,6 +112,27 @@ async function checkLiveCleanup (server: PeerTubeServer, videoUUID: string, save
56 expect(shaFile).to.exist 112 expect(shaFile).to.exist
57} 113}
58 114
59export { 115async function checkUnsavedLiveCleanup (server: PeerTubeServer, videoUUID: string, hlsPath: string) {
60 checkLiveCleanup 116 let live: LiveVideo
117
118 try {
119 live = await server.live.get({ videoId: videoUUID })
120 } catch {}
121
122 if (live?.permanentLive) {
123 expect(await pathExists(hlsPath)).to.be.true
124
125 const hlsFiles = await readdir(hlsPath)
126 expect(hlsFiles).to.have.lengthOf(1) // Only replays directory
127
128 const replayDir = join(hlsPath, 'replay')
129 expect(await pathExists(replayDir)).to.be.true
130
131 const replayFiles = await readdir(join(hlsPath, 'replay'))
132 expect(replayFiles).to.have.lengthOf(0)
133
134 return
135 }
136
137 expect(await pathExists(hlsPath)).to.be.false
61} 138}
diff --git a/server/tests/shared/playlists.ts b/server/tests/shared/playlists.ts
index fdd541d20..8db303fd8 100644
--- a/server/tests/shared/playlists.ts
+++ b/server/tests/shared/playlists.ts
@@ -1,17 +1,14 @@
1import { expect } from 'chai' 1import { expect } from 'chai'
2import { readdir } from 'fs-extra' 2import { readdir } from 'fs-extra'
3import { join } from 'path' 3import { PeerTubeServer } from '@shared/server-commands'
4import { root } from '@shared/core-utils'
5 4
6async function checkPlaylistFilesWereRemoved ( 5async function checkPlaylistFilesWereRemoved (
7 playlistUUID: string, 6 playlistUUID: string,
8 internalServerNumber: number, 7 server: PeerTubeServer,
9 directories = [ 'thumbnails' ] 8 directories = [ 'thumbnails' ]
10) { 9) {
11 const testDirectory = 'test' + internalServerNumber
12
13 for (const directory of directories) { 10 for (const directory of directories) {
14 const directoryPath = join(root(), testDirectory, directory) 11 const directoryPath = server.getDirectoryPath(directory)
15 12
16 const files = await readdir(directoryPath) 13 const files = await readdir(directoryPath)
17 for (const file of files) { 14 for (const file of files) {
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 }