]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Fix redundancy totalVideos stats
authorChocobozzz <me@florianbigard.com>
Tue, 25 Sep 2018 14:22:48 +0000 (16:22 +0200)
committerChocobozzz <me@florianbigard.com>
Tue, 25 Sep 2018 15:49:48 +0000 (17:49 +0200)
server/lib/schedulers/videos-redundancy-scheduler.ts
server/models/redundancy/video-redundancy.ts
server/tests/api/server/redundancy.ts
server/tests/utils/requests/requests.ts

index 97df3e4f5d2fd1d9e1ee3115000edc005a862ebf..06cfa1101d744132133f6a9cf67974f5950a6265 100644 (file)
@@ -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 {
index 970d2fe06b80d3b1349299b697fddbc6f5871938..58c4f354c311b2cac4a301350b7ef03c83831ade 100644 (file)
@@ -286,8 +286,8 @@ export class VideoRedundancyModel extends Model<VideoRedundancyModel> {
       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,
index a773e3de405c927fdab6e4e16fcf9f2af098ab5c..f4ae4c06532653f875d72799bf5038860510c703 100644 (file)
@@ -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
+    }
   }
 }
 
index fc7b38b8c3047f654d9be5763d547065ad3ea217..27a529edaf36b178ffc7f5d03ce7992cd4e00357 100644 (file)
@@ -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: {