aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/live/live-constraints.ts4
-rw-r--r--server/tests/api/live/live-save-replay.ts14
-rw-r--r--server/tests/api/live/live.ts14
-rw-r--r--server/tests/api/users/users-multiple-servers.ts4
-rw-r--r--server/tests/api/videos/resumable-upload.ts7
-rw-r--r--server/tests/api/videos/video-hls.ts11
-rw-r--r--server/tests/cli/optimize-old-videos.ts3
-rw-r--r--server/tests/cli/prune-storage.ts41
-rw-r--r--server/tests/cli/update-host.ts11
-rw-r--r--server/tests/plugins/plugin-transcoding.ts5
10 files changed, 80 insertions, 34 deletions
diff --git a/server/tests/api/live/live-constraints.ts b/server/tests/api/live/live-constraints.ts
index 20346113d..4acde3cc5 100644
--- a/server/tests/api/live/live-constraints.ts
+++ b/server/tests/api/live/live-constraints.ts
@@ -4,7 +4,7 @@ import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { VideoPrivacy } from '@shared/models' 5import { VideoPrivacy } from '@shared/models'
6import { 6import {
7 checkLiveCleanup, 7 checkLiveCleanupAfterSave,
8 cleanupTests, 8 cleanupTests,
9 ConfigCommand, 9 ConfigCommand,
10 createMultipleServers, 10 createMultipleServers,
@@ -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 checkLiveCleanup(servers[0], videoId, resolutions) 46 await checkLiveCleanupAfterSave(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-save-replay.ts b/server/tests/api/live/live-save-replay.ts
index bd15396ec..8f1fb78a5 100644
--- a/server/tests/api/live/live-save-replay.ts
+++ b/server/tests/api/live/live-save-replay.ts
@@ -4,7 +4,7 @@ import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { FfmpegCommand } from 'fluent-ffmpeg' 5import { FfmpegCommand } from 'fluent-ffmpeg'
6import { 6import {
7 checkLiveCleanup, 7 checkLiveCleanupAfterSave,
8 cleanupTests, 8 cleanupTests,
9 ConfigCommand, 9 ConfigCommand,
10 createMultipleServers, 10 createMultipleServers,
@@ -150,7 +150,7 @@ describe('Save replay setting', function () {
150 await checkVideoState(liveVideoUUID, VideoState.LIVE_ENDED) 150 await checkVideoState(liveVideoUUID, VideoState.LIVE_ENDED)
151 151
152 // No resolutions saved since we did not save replay 152 // No resolutions saved since we did not save replay
153 await checkLiveCleanup(servers[0], liveVideoUUID, []) 153 await checkLiveCleanupAfterSave(servers[0], liveVideoUUID, [])
154 }) 154 })
155 155
156 it('Should correctly terminate the stream on blacklist and delete the live', async function () { 156 it('Should correctly terminate the stream on blacklist and delete the live', async function () {
@@ -179,7 +179,7 @@ describe('Save replay setting', function () {
179 179
180 await wait(5000) 180 await wait(5000)
181 await waitJobs(servers) 181 await waitJobs(servers)
182 await checkLiveCleanup(servers[0], liveVideoUUID, []) 182 await checkLiveCleanupAfterSave(servers[0], liveVideoUUID, [])
183 }) 183 })
184 184
185 it('Should correctly terminate the stream on delete and delete the video', async function () { 185 it('Should correctly terminate the stream on delete and delete the video', async function () {
@@ -203,7 +203,7 @@ describe('Save replay setting', function () {
203 await waitJobs(servers) 203 await waitJobs(servers)
204 204
205 await checkVideosExist(liveVideoUUID, false, HttpStatusCode.NOT_FOUND_404) 205 await checkVideosExist(liveVideoUUID, false, HttpStatusCode.NOT_FOUND_404)
206 await checkLiveCleanup(servers[0], liveVideoUUID, []) 206 await checkLiveCleanupAfterSave(servers[0], liveVideoUUID, [])
207 }) 207 })
208 }) 208 })
209 209
@@ -259,7 +259,7 @@ describe('Save replay setting', function () {
259 }) 259 })
260 260
261 it('Should have cleaned up the live files', async function () { 261 it('Should have cleaned up the live files', async function () {
262 await checkLiveCleanup(servers[0], liveVideoUUID, [ 720 ]) 262 await checkLiveCleanupAfterSave(servers[0], liveVideoUUID, [ 720 ])
263 }) 263 })
264 264
265 it('Should correctly terminate the stream on blacklist and blacklist the saved replay video', async function () { 265 it('Should correctly terminate the stream on blacklist and blacklist the saved replay video', async function () {
@@ -287,7 +287,7 @@ describe('Save replay setting', function () {
287 287
288 await wait(5000) 288 await wait(5000)
289 await waitJobs(servers) 289 await waitJobs(servers)
290 await checkLiveCleanup(servers[0], liveVideoUUID, [ 720 ]) 290 await checkLiveCleanupAfterSave(servers[0], liveVideoUUID, [ 720 ])
291 }) 291 })
292 292
293 it('Should correctly terminate the stream on delete and delete the video', async function () { 293 it('Should correctly terminate the stream on delete and delete the video', async function () {
@@ -310,7 +310,7 @@ describe('Save replay setting', function () {
310 await waitJobs(servers) 310 await waitJobs(servers)
311 311
312 await checkVideosExist(liveVideoUUID, false, HttpStatusCode.NOT_FOUND_404) 312 await checkVideosExist(liveVideoUUID, false, HttpStatusCode.NOT_FOUND_404)
313 await checkLiveCleanup(servers[0], liveVideoUUID, []) 313 await checkLiveCleanupAfterSave(servers[0], liveVideoUUID, [])
314 }) 314 })
315 }) 315 })
316 316
diff --git a/server/tests/api/live/live.ts b/server/tests/api/live/live.ts
index 4676a840a..d555cff19 100644
--- a/server/tests/api/live/live.ts
+++ b/server/tests/api/live/live.ts
@@ -2,10 +2,10 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { join } from 'path' 5import { basename, join } from 'path'
6import { ffprobePromise, getVideoStreamFromFile } from '@server/helpers/ffprobe-utils' 6import { ffprobePromise, getVideoStreamFromFile } from '@server/helpers/ffprobe-utils'
7import { 7import {
8 checkLiveCleanup, 8 checkLiveCleanupAfterSave,
9 checkLiveSegmentHash, 9 checkLiveSegmentHash,
10 checkResolutionsInMasterPlaylist, 10 checkResolutionsInMasterPlaylist,
11 cleanupTests, 11 cleanupTests,
@@ -506,6 +506,10 @@ describe('Test live', function () {
506 await makeRawRequest(hlsPlaylist.playlistUrl, HttpStatusCode.OK_200) 506 await makeRawRequest(hlsPlaylist.playlistUrl, HttpStatusCode.OK_200)
507 await makeRawRequest(hlsPlaylist.segmentsSha256Url, HttpStatusCode.OK_200) 507 await makeRawRequest(hlsPlaylist.segmentsSha256Url, HttpStatusCode.OK_200)
508 508
509 // We should have generated random filenames
510 expect(basename(hlsPlaylist.playlistUrl)).to.not.equal('master.m3u8')
511 expect(basename(hlsPlaylist.segmentsSha256Url)).to.not.equal('segments-sha256.json')
512
509 expect(hlsPlaylist.files).to.have.lengthOf(resolutions.length) 513 expect(hlsPlaylist.files).to.have.lengthOf(resolutions.length)
510 514
511 for (const resolution of resolutions) { 515 for (const resolution of resolutions) {
@@ -520,7 +524,9 @@ describe('Test live', function () {
520 expect(file.fps).to.be.approximately(30, 2) 524 expect(file.fps).to.be.approximately(30, 2)
521 } 525 }
522 526
523 const filename = `${video.uuid}-${resolution}-fragmented.mp4` 527 const filename = basename(file.fileUrl)
528 expect(filename).to.not.contain(video.uuid)
529
524 const segmentPath = servers[0].servers.buildDirectory(join('streaming-playlists', 'hls', video.uuid, filename)) 530 const segmentPath = servers[0].servers.buildDirectory(join('streaming-playlists', 'hls', video.uuid, filename))
525 531
526 const probe = await ffprobePromise(segmentPath) 532 const probe = await ffprobePromise(segmentPath)
@@ -537,7 +543,7 @@ describe('Test live', function () {
537 it('Should correctly have cleaned up the live files', async function () { 543 it('Should correctly have cleaned up the live files', async function () {
538 this.timeout(30000) 544 this.timeout(30000)
539 545
540 await checkLiveCleanup(servers[0], liveVideoId, [ 240, 360, 720 ]) 546 await checkLiveCleanupAfterSave(servers[0], liveVideoId, [ 240, 360, 720 ])
541 }) 547 })
542 }) 548 })
543 549
diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.ts
index 16372b039..d0ca82b07 100644
--- a/server/tests/api/users/users-multiple-servers.ts
+++ b/server/tests/api/users/users-multiple-servers.ts
@@ -58,10 +58,10 @@ describe('Test users with multiple servers', function () {
58 const { uuid } = await servers[0].videos.upload({ token: userAccessToken }) 58 const { uuid } = await servers[0].videos.upload({ token: userAccessToken })
59 videoUUID = uuid 59 videoUUID = uuid
60 60
61 await waitJobs(servers)
62
61 await saveVideoInServers(servers, videoUUID) 63 await saveVideoInServers(servers, videoUUID)
62 } 64 }
63
64 await waitJobs(servers)
65 }) 65 })
66 66
67 it('Should be able to update my display name', async function () { 67 it('Should be able to update my display name', async function () {
diff --git a/server/tests/api/videos/resumable-upload.ts b/server/tests/api/videos/resumable-upload.ts
index c94d92cf2..857859fd3 100644
--- a/server/tests/api/videos/resumable-upload.ts
+++ b/server/tests/api/videos/resumable-upload.ts
@@ -170,8 +170,13 @@ describe('Test resumable upload', function () {
170 170
171 const size = 1000 171 const size = 1000
172 172
173 // Content length check seems to have changed in v16
174 const expectedStatus = process.version.startsWith('v16')
175 ? HttpStatusCode.CONFLICT_409
176 : HttpStatusCode.BAD_REQUEST_400
177
173 const contentRangeBuilder = (start: number) => `bytes ${start}-${start + size - 1}/${size}` 178 const contentRangeBuilder = (start: number) => `bytes ${start}-${start + size - 1}/${size}`
174 await sendChunks({ pathUploadId: uploadId, expectedStatus: HttpStatusCode.CONFLICT_409, contentRangeBuilder, contentLength: size }) 179 await sendChunks({ pathUploadId: uploadId, expectedStatus, contentRangeBuilder, contentLength: size })
175 await checkFileSize(uploadId, 0) 180 await checkFileSize(uploadId, 0)
176 }) 181 })
177 }) 182 })
diff --git a/server/tests/api/videos/video-hls.ts b/server/tests/api/videos/video-hls.ts
index 921d7ce64..961f0e617 100644
--- a/server/tests/api/videos/video-hls.ts
+++ b/server/tests/api/videos/video-hls.ts
@@ -2,7 +2,8 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { join } from 'path' 5import { basename, join } from 'path'
6import { removeFragmentedMP4Ext, uuidRegex } from '@shared/core-utils'
6import { 7import {
7 checkDirectoryIsEmpty, 8 checkDirectoryIsEmpty,
8 checkResolutionsInMasterPlaylist, 9 checkResolutionsInMasterPlaylist,
@@ -19,8 +20,6 @@ import {
19} from '@shared/extra-utils' 20} from '@shared/extra-utils'
20import { HttpStatusCode, VideoStreamingPlaylistType } from '@shared/models' 21import { HttpStatusCode, VideoStreamingPlaylistType } from '@shared/models'
21import { DEFAULT_AUDIO_RESOLUTION } from '../../../initializers/constants' 22import { DEFAULT_AUDIO_RESOLUTION } from '../../../initializers/constants'
22import { uuidRegex } from '@shared/core-utils'
23import { basename } from 'path/posix'
24 23
25const expect = chai.expect 24const expect = chai.expect
26 25
@@ -78,11 +77,13 @@ async function checkHlsPlaylist (servers: PeerTubeServer[], videoUUID: string, h
78 // Check resolution playlists 77 // Check resolution playlists
79 { 78 {
80 for (const resolution of resolutions) { 79 for (const resolution of resolutions) {
80 const file = hlsFiles.find(f => f.resolution.id === resolution)
81 const playlistName = removeFragmentedMP4Ext(basename(file.fileUrl)) + '.m3u8'
82
81 const subPlaylist = await server.streamingPlaylists.get({ 83 const subPlaylist = await server.streamingPlaylists.get({
82 url: `${baseUrl}/static/streaming-playlists/hls/${videoUUID}/${resolution}.m3u8` 84 url: `${baseUrl}/static/streaming-playlists/hls/${videoUUID}/${playlistName}`
83 }) 85 })
84 86
85 const file = hlsFiles.find(f => f.resolution.id === resolution)
86 expect(subPlaylist).to.match(new RegExp(`${uuidRegex}-${resolution}-fragmented.mp4`)) 87 expect(subPlaylist).to.match(new RegExp(`${uuidRegex}-${resolution}-fragmented.mp4`))
87 expect(subPlaylist).to.contain(basename(file.fileUrl)) 88 expect(subPlaylist).to.contain(basename(file.fileUrl))
88 } 89 }
diff --git a/server/tests/cli/optimize-old-videos.ts b/server/tests/cli/optimize-old-videos.ts
index 685b3b7b8..579b2e7d8 100644
--- a/server/tests/cli/optimize-old-videos.ts
+++ b/server/tests/cli/optimize-old-videos.ts
@@ -2,7 +2,6 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { join } from 'path'
6import { 5import {
7 cleanupTests, 6 cleanupTests,
8 createMultipleServers, 7 createMultipleServers,
@@ -86,7 +85,7 @@ describe('Test optimize old videos', function () {
86 85
87 expect(file.size).to.be.below(8000000) 86 expect(file.size).to.be.below(8000000)
88 87
89 const path = servers[0].servers.buildDirectory(join('videos', video.uuid + '-' + file.resolution.id + '.mp4')) 88 const path = servers[0].servers.buildWebTorrentFilePath(file.fileUrl)
90 const bitrate = await getVideoFileBitrate(path) 89 const bitrate = await getVideoFileBitrate(path)
91 const fps = await getVideoFileFPS(path) 90 const fps = await getVideoFileFPS(path)
92 const resolution = await getVideoFileResolution(path) 91 const resolution = await getVideoFileResolution(path)
diff --git a/server/tests/cli/prune-storage.ts b/server/tests/cli/prune-storage.ts
index 954a87833..2d4c02da7 100644
--- a/server/tests/cli/prune-storage.ts
+++ b/server/tests/cli/prune-storage.ts
@@ -36,7 +36,7 @@ async function assertNotExists (server: PeerTubeServer, directory: string, subst
36 } 36 }
37} 37}
38 38
39async function assertCountAreOkay (servers: PeerTubeServer[]) { 39async function assertCountAreOkay (servers: PeerTubeServer[], videoServer2UUID: string) {
40 for (const server of servers) { 40 for (const server of servers) {
41 const videosCount = await countFiles(server, 'videos') 41 const videosCount = await countFiles(server, 'videos')
42 expect(videosCount).to.equal(8) 42 expect(videosCount).to.equal(8)
@@ -53,12 +53,21 @@ async function assertCountAreOkay (servers: PeerTubeServer[]) {
53 const avatarsCount = await countFiles(server, 'avatars') 53 const avatarsCount = await countFiles(server, 'avatars')
54 expect(avatarsCount).to.equal(2) 54 expect(avatarsCount).to.equal(2)
55 } 55 }
56
57 // When we'll prune HLS directories too
58 // const hlsRootCount = await countFiles(servers[1], 'streaming-playlists/hls/')
59 // expect(hlsRootCount).to.equal(2)
60
61 // const hlsCount = await countFiles(servers[1], 'streaming-playlists/hls/' + videoServer2UUID)
62 // expect(hlsCount).to.equal(10)
56} 63}
57 64
58describe('Test prune storage scripts', function () { 65describe('Test prune storage scripts', function () {
59 let servers: PeerTubeServer[] 66 let servers: PeerTubeServer[]
60 const badNames: { [directory: string]: string[] } = {} 67 const badNames: { [directory: string]: string[] } = {}
61 68
69 let videoServer2UUID: string
70
62 before(async function () { 71 before(async function () {
63 this.timeout(120000) 72 this.timeout(120000)
64 73
@@ -68,7 +77,9 @@ describe('Test prune storage scripts', function () {
68 77
69 for (const server of servers) { 78 for (const server of servers) {
70 await server.videos.upload({ attributes: { name: 'video 1' } }) 79 await server.videos.upload({ attributes: { name: 'video 1' } })
71 await server.videos.upload({ attributes: { name: 'video 2' } }) 80
81 const { uuid } = await server.videos.upload({ attributes: { name: 'video 2' } })
82 if (server.serverNumber === 2) videoServer2UUID = uuid
72 83
73 await server.users.updateMyAvatar({ fixture: 'avatar.png' }) 84 await server.users.updateMyAvatar({ fixture: 'avatar.png' })
74 85
@@ -112,7 +123,7 @@ describe('Test prune storage scripts', function () {
112 }) 123 })
113 124
114 it('Should have the files on the disk', async function () { 125 it('Should have the files on the disk', async function () {
115 await assertCountAreOkay(servers) 126 await assertCountAreOkay(servers, videoServer2UUID)
116 }) 127 })
117 128
118 it('Should create some dirty files', async function () { 129 it('Should create some dirty files', async function () {
@@ -176,6 +187,28 @@ describe('Test prune storage scripts', function () {
176 187
177 badNames['avatars'] = [ n1, n2 ] 188 badNames['avatars'] = [ n1, n2 ]
178 } 189 }
190
191 // When we'll prune HLS directories too
192 // {
193 // const directory = join('streaming-playlists', 'hls')
194 // const base = servers[1].servers.buildDirectory(directory)
195
196 // const n1 = buildUUID()
197 // await createFile(join(base, n1))
198 // badNames[directory] = [ n1 ]
199 // }
200
201 // {
202 // const directory = join('streaming-playlists', 'hls', videoServer2UUID)
203 // const base = servers[1].servers.buildDirectory(directory)
204 // const n1 = buildUUID() + '-240-fragmented-.mp4'
205 // const n2 = buildUUID() + '-master.m3u8'
206
207 // await createFile(join(base, n1))
208 // await createFile(join(base, n2))
209
210 // badNames[directory] = [ n1, n2 ]
211 // }
179 } 212 }
180 }) 213 })
181 214
@@ -187,7 +220,7 @@ describe('Test prune storage scripts', function () {
187 }) 220 })
188 221
189 it('Should have removed files', async function () { 222 it('Should have removed files', async function () {
190 await assertCountAreOkay(servers) 223 await assertCountAreOkay(servers, videoServer2UUID)
191 224
192 for (const directory of Object.keys(badNames)) { 225 for (const directory of Object.keys(badNames)) {
193 for (const name of badNames[directory]) { 226 for (const name of badNames[directory]) {
diff --git a/server/tests/cli/update-host.ts b/server/tests/cli/update-host.ts
index fcbcb55ba..43fbaec30 100644
--- a/server/tests/cli/update-host.ts
+++ b/server/tests/cli/update-host.ts
@@ -108,21 +108,22 @@ describe('Test update host scripts', function () {
108 108
109 for (const video of data) { 109 for (const video of data) {
110 const videoDetails = await server.videos.get({ id: video.id }) 110 const videoDetails = await server.videos.get({ id: video.id })
111 const files = videoDetails.files.concat(videoDetails.streamingPlaylists[0].files)
111 112
112 expect(videoDetails.files).to.have.lengthOf(4) 113 expect(files).to.have.lengthOf(8)
113 114
114 for (const file of videoDetails.files) { 115 for (const file of files) {
115 expect(file.magnetUri).to.contain('localhost%3A9002%2Ftracker%2Fsocket') 116 expect(file.magnetUri).to.contain('localhost%3A9002%2Ftracker%2Fsocket')
116 expect(file.magnetUri).to.contain('localhost%3A9002%2Fstatic%2Fwebseed%2F') 117 expect(file.magnetUri).to.contain('localhost%3A9002%2Fstatic%2F')
117 118
118 const torrent = await parseTorrentVideo(server, videoDetails.uuid, file.resolution.id) 119 const torrent = await parseTorrentVideo(server, file)
119 const announceWS = torrent.announce.find(a => a === 'ws://localhost:9002/tracker/socket') 120 const announceWS = torrent.announce.find(a => a === 'ws://localhost:9002/tracker/socket')
120 expect(announceWS).to.not.be.undefined 121 expect(announceWS).to.not.be.undefined
121 122
122 const announceHttp = torrent.announce.find(a => a === 'http://localhost:9002/tracker/announce') 123 const announceHttp = torrent.announce.find(a => a === 'http://localhost:9002/tracker/announce')
123 expect(announceHttp).to.not.be.undefined 124 expect(announceHttp).to.not.be.undefined
124 125
125 expect(torrent.urlList[0]).to.contain('http://localhost:9002/static/webseed') 126 expect(torrent.urlList[0]).to.contain('http://localhost:9002/static/')
126 } 127 }
127 } 128 }
128 }) 129 })
diff --git a/server/tests/plugins/plugin-transcoding.ts b/server/tests/plugins/plugin-transcoding.ts
index c14c34c7e..93637e3ce 100644
--- a/server/tests/plugins/plugin-transcoding.ts
+++ b/server/tests/plugins/plugin-transcoding.ts
@@ -2,7 +2,6 @@
2 2
3import 'mocha' 3import 'mocha'
4import { expect } from 'chai' 4import { expect } from 'chai'
5import { join } from 'path'
6import { getAudioStream, getVideoFileFPS, getVideoStreamFromFile } from '@server/helpers/ffprobe-utils' 5import { getAudioStream, getVideoFileFPS, getVideoStreamFromFile } from '@server/helpers/ffprobe-utils'
7import { 6import {
8 cleanupTests, 7 cleanupTests,
@@ -247,7 +246,9 @@ describe('Test transcoding plugins', function () {
247 const videoUUID = (await server.videos.quickUpload({ name: 'video', fixture: 'video_very_short_240p.mp4' })).uuid 246 const videoUUID = (await server.videos.quickUpload({ name: 'video', fixture: 'video_very_short_240p.mp4' })).uuid
248 await waitJobs([ server ]) 247 await waitJobs([ server ])
249 248
250 const path = server.servers.buildDirectory(join('videos', videoUUID + '-240.mp4')) 249 const video = await server.videos.get({ id: videoUUID })
250
251 const path = server.servers.buildWebTorrentFilePath(video.files[0].fileUrl)
251 const audioProbe = await getAudioStream(path) 252 const audioProbe = await getAudioStream(path)
252 expect(audioProbe.audioStream.codec_name).to.equal('opus') 253 expect(audioProbe.audioStream.codec_name).to.equal('opus')
253 254