X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Freal-world%2Freal-world.js;h=9a63860adca7c47c869ff2a9c64712014dfdef3b;hb=d8cc063e9775688a1631eda9203411a2dba0333c;hp=b28796852911087a16c5c725df67e28511ca88c3;hpb=1a42c9e2c0fb64cdbebd81b311736e752f591e0a;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/real-world/real-world.js b/server/tests/real-world/real-world.js index b28796852..9a63860ad 100644 --- a/server/tests/real-world/real-world.js +++ b/server/tests/real-world/real-world.js @@ -1,14 +1,18 @@ 'use strict' -const each = require('each') +const each = require('async/each') const isEqual = require('lodash/isEqual') +const differenceWith = require('lodash/differenceWith') const program = require('commander') const series = require('async/series') process.env.NODE_ENV = 'test' const constants = require('../../initializers/constants') -const utils = require('../api/utils') +const loginUtils = require('../utils/login') +const podsUtils = require('../utils/pods') +const serversUtils = require('../utils/servers') +const videosUtils = require('../utils/videos') program .option('-c, --create [weight]', 'Weight for creating videos') @@ -17,21 +21,23 @@ program .option('-a, --action [interval]', 'Interval in ms for an action') .option('-i, --integrity [interval]', 'Interval in ms for an integrity check') .option('-f, --flush', 'Flush datas on exit') + .option('-d, --difference', 'Display difference if integrity is not okay') .parse(process.argv) -const createWeight = parseInt(program.create) || 5 -const removeWeight = parseInt(program.remove) || 4 +const createWeight = program.create !== undefined ? parseInt(program.create) : 5 +const removeWeight = program.remove !== undefined ? parseInt(program.remove) : 4 const flushAtExit = program.flush || false -const actionInterval = parseInt(program.action) || 500 -let integrityInterval = parseInt(program.integrity) || 60000 +const actionInterval = program.action !== undefined ? parseInt(program.action) : 500 +let integrityInterval = program.integrity !== undefined ? parseInt(program.integrity) : 60000 +const displayDiffOnFail = program.integrity || false const numberOfPods = 6 -// Wait requests between pods -const requestsMaxPerInterval = constants.INTERVAL / actionInterval -const intervalsToMakeAllRequests = Math.ceil(requestsMaxPerInterval / constants.REQUESTS_LIMIT) -const waitForBeforeIntegrityCheck = (intervalsToMakeAllRequests * constants.INTERVAL) + 1000 -integrityInterval += waitForBeforeIntegrityCheck +// Wait requests between pods +const baseRequestInterval = integrityInterval < constants.REQUESTS_INTERVAL ? integrityInterval : constants.REQUESTS_INTERVAL +const requestsMaxPerInterval = baseRequestInterval / actionInterval +const intervalsToMakeAllRequests = Math.ceil(requestsMaxPerInterval / (constants.REQUESTS_LIMIT_PER_POD * numberOfPods)) +const waitForBeforeIntegrityCheck = (intervalsToMakeAllRequests * constants.REQUESTS_INTERVAL) + 1000 console.log('Create weight: %d, remove weight: %d.', createWeight, removeWeight) if (flushAtExit) { @@ -39,6 +45,11 @@ if (flushAtExit) { } else { console.log('Program will not flush data on exit.') } +if (displayDiffOnFail) { + console.log('Program will display diff on failure.') +} else { + console.log('Program will not display diff on failure') +} console.log('Interval in ms for each action: %d.', actionInterval) console.log('Interval in ms for each integrity check: %d.', integrityInterval) console.log('Will wait %d ms before an integrity check.', waitForBeforeIntegrityCheck) @@ -70,6 +81,8 @@ runServers(numberOfPods, function (err, servers) { }, actionInterval) setInterval(function () { + if (checking === true) return + console.log('Checking integrity...') checking = true @@ -97,7 +110,7 @@ function runServers (numberOfPods, callback) { series([ // Run servers function (next) { - utils.flushAndRunMultipleServers(numberOfPods, function (serversRun) { + serversUtils.flushAndRunMultipleServers(numberOfPods, function (serversRun) { servers = serversRun next() }) @@ -105,7 +118,7 @@ function runServers (numberOfPods, callback) { // Get the access tokens function (next) { each(servers, function (server, callbackEach) { - utils.loginAndGetAccessToken(server, function (err, accessToken) { + loginUtils.loginAndGetAccessToken(server, function (err, accessToken) { if (err) return callbackEach(err) server.accessToken = accessToken @@ -115,26 +128,26 @@ function runServers (numberOfPods, callback) { }, function (next) { const server = servers[1] - utils.makeFriends(server.url, server.accessToken, next) + podsUtils.makeFriends(server.url, server.accessToken, next) }, function (next) { const server = servers[0] - utils.makeFriends(server.url, server.accessToken, next) + podsUtils.makeFriends(server.url, server.accessToken, next) }, function (next) { setTimeout(next, 1000) }, function (next) { const server = servers[3] - utils.makeFriends(server.url, server.accessToken, next) + podsUtils.makeFriends(server.url, server.accessToken, next) }, function (next) { const server = servers[5] - utils.makeFriends(server.url, server.accessToken, next) + podsUtils.makeFriends(server.url, server.accessToken, next) }, function (next) { const server = servers[4] - utils.makeFriends(server.url, server.accessToken, next) + podsUtils.makeFriends(server.url, server.accessToken, next) }, function (next) { setTimeout(next, 1000) @@ -151,26 +164,26 @@ function exitServers (servers, callback) { if (server.app) process.kill(-server.app.pid) }) - if (flushAtExit) utils.flushTests(callback) + if (flushAtExit) serversUtils.flushTests(callback) } function upload (servers, numServer, callback) { if (!callback) callback = function () {} - const name = 'my super name for pod 1' - const description = 'my super description for pod 1' - const tags = [ 'tag1p1', 'tag2p1' ] + const name = Date.now() + ' name' + const description = Date.now() + ' description' + const tags = [ Date.now().toString().substring(0, 5) + 't1', Date.now().toString().substring(0, 5) + 't2' ] const file = 'video_short1.webm' console.log('Upload video to server ' + numServer) - utils.uploadVideo(servers[numServer].url, servers[numServer].accessToken, name, description, tags, file, callback) + videosUtils.uploadVideo(servers[numServer].url, servers[numServer].accessToken, name, description, tags, file, callback) } function remove (servers, numServer, callback) { if (!callback) callback = function () {} - utils.getVideosList(servers[numServer].url, function (err, res) { + videosUtils.getVideosList(servers[numServer].url, function (err, res) { if (err) throw err const videos = res.body.data @@ -179,20 +192,21 @@ function remove (servers, numServer, callback) { const toRemove = videos[getRandomInt(0, videos.length)].id console.log('Removing video from server ' + numServer) - utils.removeVideo(servers[numServer].url, servers[numServer].accessToken, toRemove, callback) + videosUtils.removeVideo(servers[numServer].url, servers[numServer].accessToken, toRemove, callback) }) } function checkIntegrity (servers, callback) { const videos = [] each(servers, function (server, callback) { - utils.getAllVideosListBy(server.url, function (err, res) { + videosUtils.getAllVideosListBy(server.url, function (err, res) { if (err) throw err const serverVideos = res.body.data for (const serverVideo of serverVideos) { delete serverVideo.id delete serverVideo.isLocal delete serverVideo.thumbnailPath + delete serverVideo.updatedAt } videos.push(serverVideos) @@ -202,6 +216,11 @@ function checkIntegrity (servers, callback) { for (const video of videos) { if (!isEqual(video, videos[0])) { console.error('Integrity not ok!') + + if (displayDiffOnFail) { + console.log(differenceWith(videos[0], video, isEqual)) + } + process.exit(-1) } }