From ebdb612458877465717bc669b40612fa833ff0c9 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 25 Sep 2018 16:22:48 +0200 Subject: Fix redundancy totalVideos stats --- .../lib/schedulers/videos-redundancy-scheduler.ts | 1 - server/models/redundancy/video-redundancy.ts | 4 ++-- server/tests/api/server/redundancy.ts | 21 ++++++++++++++++----- server/tests/utils/requests/requests.ts | 10 +++++----- 4 files changed, 23 insertions(+), 13 deletions(-) (limited to 'server') diff --git a/server/lib/schedulers/videos-redundancy-scheduler.ts b/server/lib/schedulers/videos-redundancy-scheduler.ts index 97df3e4f5..06cfa1101 100644 --- a/server/lib/schedulers/videos-redundancy-scheduler.ts +++ b/server/lib/schedulers/videos-redundancy-scheduler.ts @@ -11,7 +11,6 @@ import { getServerActor } from '../../helpers/utils' import { sendCreateCacheFile, sendUpdateCacheFile } from '../activitypub/send' import { VideoModel } from '../../models/video/video' import { getVideoCacheFileActivityPubUrl } from '../activitypub/url' -import { isTestInstance } from '../../helpers/core-utils' import { removeVideoRedundancy } from '../redundancy' export class VideosRedundancyScheduler extends AbstractScheduler { diff --git a/server/models/redundancy/video-redundancy.ts b/server/models/redundancy/video-redundancy.ts index 970d2fe06..58c4f354c 100644 --- a/server/models/redundancy/video-redundancy.ts +++ b/server/models/redundancy/video-redundancy.ts @@ -286,8 +286,8 @@ export class VideoRedundancyModel extends Model { raw: true, attributes: [ [ Sequelize.fn('COALESCE', Sequelize.fn('SUM', Sequelize.col('VideoFile.size')), '0'), 'totalUsed' ], - [ Sequelize.fn('COUNT', Sequelize.fn('DISTINCT', 'videoId')), 'totalVideos' ], - [ Sequelize.fn('COUNT', 'videoFileId'), 'totalVideoFiles' ] + [ Sequelize.fn('COUNT', Sequelize.fn('DISTINCT', Sequelize.col('videoId'))), 'totalVideos' ], + [ Sequelize.fn('COUNT', Sequelize.col('videoFileId')), 'totalVideoFiles' ] ], where: { strategy, diff --git a/server/tests/api/server/redundancy.ts b/server/tests/api/server/redundancy.ts index a773e3de4..f4ae4c065 100644 --- a/server/tests/api/server/redundancy.ts +++ b/server/tests/api/server/redundancy.ts @@ -9,7 +9,7 @@ import { getFollowingListPaginationAndSort, getVideo, immutableAssign, - killallServers, + killallServers, makeGetRequest, root, ServerInfo, setAccessTokensToServers, @@ -147,11 +147,22 @@ async function check2Webseeds (strategy: VideoRedundancyStrategy, videoUUID?: st } } - const files = await readdir(join(root(), 'test1', 'videos')) - expect(files).to.have.lengthOf(4) + for (const url of [ 'http://localhost:9001', 'http://localhost:9002' ]) { + await makeGetRequest({ + url, + statusCodeExpected: 200, + path: '/static/webseed/' + videoUUID, + contentType: null + }) + } - for (const resolution of [ 240, 360, 480, 720 ]) { - expect(files.find(f => f === `${videoUUID}-${resolution}.mp4`)).to.not.be.undefined + for (const directory of [ 'test1', 'test2' ]) { + const files = await readdir(join(root(), directory, 'videos')) + expect(files).to.have.length.at.least(4) + + for (const resolution of [ 240, 360, 480, 720 ]) { + expect(files.find(f => f === `${videoUUID}-${resolution}.mp4`)).to.not.be.undefined + } } } diff --git a/server/tests/utils/requests/requests.ts b/server/tests/utils/requests/requests.ts index fc7b38b8c..27a529eda 100644 --- a/server/tests/utils/requests/requests.ts +++ b/server/tests/utils/requests/requests.ts @@ -7,20 +7,20 @@ function makeGetRequest (options: { path: string, query?: any, token?: string, - statusCodeExpected?: number + statusCodeExpected?: number, + contentType?: string }) { if (!options.statusCodeExpected) options.statusCodeExpected = 400 + if (options.contentType === undefined) options.contentType = 'application/json' const req = request(options.url) .get(options.path) - .set('Accept', 'application/json') + if (options.contentType) req.set('Accept', options.contentType) if (options.token) req.set('Authorization', 'Bearer ' + options.token) if (options.query) req.query(options.query) - return req - .expect('Content-Type', /json/) - .expect(options.statusCodeExpected) + return req.expect(options.statusCodeExpected) } function makeDeleteRequest (options: { -- cgit v1.2.3