+async function check0PlaylistRedundancies (videoUUID?: string) {
+ if (!videoUUID) videoUUID = video1Server2UUID
+
+ for (const server of servers) {
+ // With token to avoid issues with video follow constraints
+ const res = await getVideoWithToken(server.url, server.accessToken, videoUUID)
+ const video: VideoDetails = res.body
+
+ expect(video.streamingPlaylists).to.be.an('array')
+ expect(video.streamingPlaylists).to.have.lengthOf(1)
+ expect(video.streamingPlaylists[0].redundancies).to.have.lengthOf(0)
+ }
+}
+
+async function check1PlaylistRedundancies (videoUUID?: string) {
+ if (!videoUUID) videoUUID = video1Server2UUID
+
+ for (const server of servers) {
+ const res = await getVideo(server.url, videoUUID)
+ const video: VideoDetails = res.body
+
+ expect(video.streamingPlaylists).to.have.lengthOf(1)
+ expect(video.streamingPlaylists[0].redundancies).to.have.lengthOf(1)
+
+ const redundancy = video.streamingPlaylists[0].redundancies[0]
+
+ expect(redundancy.baseUrl).to.equal(servers[0].url + '/static/redundancy/hls/' + videoUUID)
+ }
+
+ const baseUrlPlaylist = servers[1].url + '/static/streaming-playlists/hls'
+ const baseUrlSegment = servers[0].url + '/static/redundancy/hls'
+
+ const res = await getVideo(servers[0].url, videoUUID)
+ const hlsPlaylist = (res.body as VideoDetails).streamingPlaylists[0]
+
+ for (const resolution of [ 240, 360, 480, 720 ]) {
+ await checkSegmentHash(baseUrlPlaylist, baseUrlSegment, videoUUID, resolution, hlsPlaylist)
+ }
+
+ const directories = [
+ 'test' + servers[0].internalServerNumber + '/redundancy/hls',
+ 'test' + servers[1].internalServerNumber + '/streaming-playlists/hls'
+ ]
+
+ for (const directory of directories) {
+ const files = await readdir(join(root(), directory, videoUUID))
+ expect(files).to.have.length.at.least(4)
+
+ for (const resolution of [ 240, 360, 480, 720 ]) {
+ const filename = `${videoUUID}-${resolution}-fragmented.mp4`
+
+ expect(files.find(f => f === filename)).to.not.be.undefined
+ }
+ }
+}
+
+async function checkStatsGlobal (strategy: VideoRedundancyStrategyWithManual) {
+ let totalSize: number = null
+ let statsLength = 1
+
+ if (strategy !== 'manual') {
+ totalSize = 409600
+ statsLength = 2
+ }
+
+ const res = await getStats(servers[0].url)
+ const data: ServerStats = res.body
+
+ expect(data.videosRedundancy).to.have.lengthOf(statsLength)
+
+ const stat = data.videosRedundancy[0]
+ expect(stat.strategy).to.equal(strategy)
+ expect(stat.totalSize).to.equal(totalSize)
+
+ return stat
+}
+
+async function checkStatsWith2Webseed (strategy: VideoRedundancyStrategyWithManual) {
+ const stat = await checkStatsGlobal(strategy)
+
+ expect(stat.totalUsed).to.be.at.least(1).and.below(409601)
+ expect(stat.totalVideoFiles).to.equal(4)
+ expect(stat.totalVideos).to.equal(1)
+}
+
+async function checkStatsWith1Webseed (strategy: VideoRedundancyStrategyWithManual) {
+ const stat = await checkStatsGlobal(strategy)
+
+ expect(stat.totalUsed).to.equal(0)
+ expect(stat.totalVideoFiles).to.equal(0)
+ expect(stat.totalVideos).to.equal(0)
+}
+