1
0
Fork 0

Fix real world script

This commit is contained in:
Chocobozzz 2017-12-29 10:04:15 +01:00
parent efed5d5ef6
commit a7ba16b62d
No known key found for this signature in database
GPG key ID: 583A612D890159BE
4 changed files with 436 additions and 567 deletions

View file

@ -40,36 +40,28 @@ describe('Test users', function () {
const client = { id: 'client', secret: server.client.secret } const client = { id: 'client', secret: server.client.secret }
const res = await login(server.url, client, server.user, 400) const res = await login(server.url, client, server.user, 400)
expect(res.body.error) expect(res.body.error).to.equal('Authentication failed.')
.to
.equal('Authentication failed.')
}) })
it('Should not login with an invalid client secret', async function () { it('Should not login with an invalid client secret', async function () {
const client = { id: server.client.id, secret: 'coucou' } const client = { id: server.client.id, secret: 'coucou' }
const res = await login(server.url, client, server.user, 400) const res = await login(server.url, client, server.user, 400)
expect(res.body.error) expect(res.body.error).to.equal('Authentication failed.')
.to
.equal('Authentication failed.')
}) })
it('Should not login with an invalid username', async function () { it('Should not login with an invalid username', async function () {
const user = { username: 'captain crochet', password: server.user.password } const user = { username: 'captain crochet', password: server.user.password }
const res = await login(server.url, server.client, user, 400) const res = await login(server.url, server.client, user, 400)
expect(res.body.error) expect(res.body.error).to.equal('Authentication failed.')
.to
.equal('Authentication failed.')
}) })
it('Should not login with an invalid password', async function () { it('Should not login with an invalid password', async function () {
const user = { username: server.user.username, password: 'mew_three' } const user = { username: server.user.username, password: 'mew_three' }
const res = await login(server.url, server.client, user, 400) const res = await login(server.url, server.client, user, 400)
expect(res.body.error) expect(res.body.error).to.equal('Authentication failed.')
.to
.equal('Authentication failed.')
}) })
it('Should not be able to upload a video', async function () { it('Should not be able to upload a video', async function () {
@ -98,9 +90,7 @@ describe('Test users', function () {
const res = await getVideosList(server.url) const res = await getVideosList(server.url)
const video = res.body.data[ 0 ] const video = res.body.data[ 0 ]
expect(video.accountName) expect(video.accountName).to.equal('root')
.to
.equal('root')
videoId = video.id videoId = video.id
}) })
@ -114,12 +104,8 @@ describe('Test users', function () {
const res = await getMyUserVideoRating(server.url, accessToken, videoId) const res = await getMyUserVideoRating(server.url, accessToken, videoId)
const rating = res.body const rating = res.body
expect(rating.videoId) expect(rating.videoId).to.equal(videoId)
.to expect(rating.rating).to.equal('like')
.equal(videoId)
expect(rating.rating)
.to
.equal('like')
}) })
it('Should not be able to remove the video with an incorrect token', async function () { it('Should not be able to remove the video with an incorrect token', async function () {
@ -181,23 +167,12 @@ describe('Test users', function () {
const res = await getMyUserInformation(server.url, accessTokenUser) const res = await getMyUserInformation(server.url, accessTokenUser)
const user = res.body const user = res.body
expect(user.username) expect(user.username).to.equal('user_1')
.to expect(user.email).to.equal('user_1@example.com')
.equal('user_1')
expect(user.email)
.to
.equal('user_1@example.com')
expect(user.displayNSFW).to.be.false expect(user.displayNSFW).to.be.false
expect(user.videoQuota) expect(user.videoQuota).to.equal(2 * 1024 * 1024)
.to expect(user.roleLabel).to.equal('User')
.equal(2 * 1024 * 1024) expect(user.id).to.be.a('number')
expect(user.roleLabel)
.to
.equal('User')
expect(user.id)
.to
.be
.a('number')
}) })
it('Should be able to upload a video with this user', async function () { it('Should be able to upload a video with this user', async function () {
@ -211,19 +186,12 @@ describe('Test users', function () {
it('Should be able to list my videos', async function () { it('Should be able to list my videos', async function () {
const res = await getMyVideos(server.url, accessTokenUser, 0, 5) const res = await getMyVideos(server.url, accessTokenUser, 0, 5)
expect(res.body.total) expect(res.body.total).to.equal(1)
.to
.equal(1)
const videos = res.body.data const videos = res.body.data
expect(videos) expect(videos).to.have.lengthOf(1)
.to
.have
.lengthOf(1)
expect(videos[ 0 ].name) expect(videos[ 0 ].name).to.equal('super user video')
.to
.equal('super user video')
}) })
it('Should list all the users', async function () { it('Should list all the users', async function () {
@ -232,33 +200,18 @@ describe('Test users', function () {
const total = result.total const total = result.total
const users = result.data const users = result.data
expect(total) expect(total).to.equal(2)
.to expect(users).to.be.an('array')
.equal(2) expect(users.length).to.equal(2)
expect(users)
.to
.be
.an('array')
expect(users.length)
.to
.equal(2)
const user = users[ 0 ] const user = users[ 0 ]
expect(user.username) expect(user.username).to.equal('user_1')
.to expect(user.email).to.equal('user_1@example.com')
.equal('user_1')
expect(user.email)
.to
.equal('user_1@example.com')
expect(user.displayNSFW).to.be.false expect(user.displayNSFW).to.be.false
const rootUser = users[ 1 ] const rootUser = users[ 1 ]
expect(rootUser.username) expect(rootUser.username).to.equal('root')
.to expect(rootUser.email).to.equal('admin1@example.com')
.equal('root')
expect(rootUser.email)
.to
.equal('admin1@example.com')
expect(rootUser.displayNSFW).to.be.false expect(rootUser.displayNSFW).to.be.false
userId = user.id userId = user.id
@ -271,23 +224,13 @@ describe('Test users', function () {
const total = result.total const total = result.total
const users = result.data const users = result.data
expect(total) expect(total).to.equal(2)
.to expect(users.length).to.equal(1)
.equal(2)
expect(users.length)
.to
.equal(1)
const user = users[ 0 ] const user = users[ 0 ]
expect(user.username) expect(user.username).to.equal('root')
.to expect(user.email).to.equal('admin1@example.com')
.equal('root') expect(user.roleLabel).to.equal('Administrator')
expect(user.email)
.to
.equal('admin1@example.com')
expect(user.roleLabel)
.to
.equal('Administrator')
expect(user.displayNSFW).to.be.false expect(user.displayNSFW).to.be.false
}) })
@ -297,20 +240,12 @@ describe('Test users', function () {
const total = result.total const total = result.total
const users = result.data const users = result.data
expect(total) expect(total).to.equal(2)
.to expect(users.length).to.equal(1)
.equal(2)
expect(users.length)
.to
.equal(1)
const user = users[ 0 ] const user = users[ 0 ]
expect(user.username) expect(user.username).to.equal('user_1')
.to expect(user.email).to.equal('user_1@example.com')
.equal('user_1')
expect(user.email)
.to
.equal('user_1@example.com')
expect(user.displayNSFW).to.be.false expect(user.displayNSFW).to.be.false
}) })
@ -320,20 +255,12 @@ describe('Test users', function () {
const total = result.total const total = result.total
const users = result.data const users = result.data
expect(total) expect(total).to.equal(2)
.to expect(users.length).to.equal(1)
.equal(2)
expect(users.length)
.to
.equal(1)
const user = users[ 0 ] const user = users[ 0 ]
expect(user.username) expect(user.username).to.equal('user_1')
.to expect(user.email).to.equal('user_1@example.com')
.equal('user_1')
expect(user.email)
.to
.equal('user_1@example.com')
expect(user.displayNSFW).to.be.false expect(user.displayNSFW).to.be.false
}) })
@ -343,27 +270,15 @@ describe('Test users', function () {
const total = result.total const total = result.total
const users = result.data const users = result.data
expect(total) expect(total).to.equal(2)
.to expect(users.length).to.equal(2)
.equal(2)
expect(users.length)
.to
.equal(2)
expect(users[ 0 ].username) expect(users[ 0 ].username).to.equal('root')
.to expect(users[ 0 ].email).to.equal('admin1@example.com')
.equal('root')
expect(users[ 0 ].email)
.to
.equal('admin1@example.com')
expect(users[ 0 ].displayNSFW).to.be.false expect(users[ 0 ].displayNSFW).to.be.false
expect(users[ 1 ].username) expect(users[ 1 ].username).to.equal('user_1')
.to expect(users[ 1 ].email).to.equal('user_1@example.com')
.equal('user_1')
expect(users[ 1 ].email)
.to
.equal('user_1@example.com')
expect(users[ 1 ].displayNSFW).to.be.false expect(users[ 1 ].displayNSFW).to.be.false
}) })
@ -388,20 +303,11 @@ describe('Test users', function () {
const res = await getMyUserInformation(server.url, accessTokenUser) const res = await getMyUserInformation(server.url, accessTokenUser)
const user = res.body const user = res.body
expect(user.username) expect(user.username).to.equal('user_1')
.to expect(user.email).to.equal('user_1@example.com')
.equal('user_1')
expect(user.email)
.to
.equal('user_1@example.com')
expect(user.displayNSFW).to.be.ok expect(user.displayNSFW).to.be.ok
expect(user.videoQuota) expect(user.videoQuota).to.equal(2 * 1024 * 1024)
.to expect(user.id).to.be.a('number')
.equal(2 * 1024 * 1024)
expect(user.id)
.to
.be
.a('number')
}) })
it('Should be able to change the autoPlayVideo attribute', async function () { it('Should be able to change the autoPlayVideo attribute', async function () {
@ -427,20 +333,11 @@ describe('Test users', function () {
const res = await getMyUserInformation(server.url, accessTokenUser) const res = await getMyUserInformation(server.url, accessTokenUser)
const user = res.body const user = res.body
expect(user.username) expect(user.username).to.equal('user_1')
.to expect(user.email).to.equal('updated@example.com')
.equal('user_1')
expect(user.email)
.to
.equal('updated@example.com')
expect(user.displayNSFW).to.be.ok expect(user.displayNSFW).to.be.ok
expect(user.videoQuota) expect(user.videoQuota).to.equal(2 * 1024 * 1024)
.to expect(user.id).to.be.a('number')
.equal(2 * 1024 * 1024)
expect(user.id)
.to
.be
.a('number')
}) })
it('Should be able to update another user', async function () { it('Should be able to update another user', async function () {
@ -456,23 +353,12 @@ describe('Test users', function () {
const res = await getUserInformation(server.url, accessToken, userId) const res = await getUserInformation(server.url, accessToken, userId)
const user = res.body const user = res.body
expect(user.username) expect(user.username).to.equal('user_1')
.to expect(user.email).to.equal('updated2@example.com')
.equal('user_1')
expect(user.email)
.to
.equal('updated2@example.com')
expect(user.displayNSFW).to.be.ok expect(user.displayNSFW).to.be.ok
expect(user.videoQuota) expect(user.videoQuota).to.equal(42)
.to expect(user.roleLabel).to.equal('Moderator')
.equal(42) expect(user.id).to.be.a('number')
expect(user.roleLabel)
.to
.equal('Moderator')
expect(user.id)
.to
.be
.a('number')
}) })
it('Should not be able to delete a user by a moderator', async function () { it('Should not be able to delete a user by a moderator', async function () {
@ -495,14 +381,10 @@ describe('Test users', function () {
it('Should not have videos of this user', async function () { it('Should not have videos of this user', async function () {
const res = await getVideosList(server.url) const res = await getVideosList(server.url)
expect(res.body.total) expect(res.body.total).to.equal(1)
.to
.equal(1)
const video = res.body.data[ 0 ] const video = res.body.data[ 0 ]
expect(video.accountName) expect(video.accountName).to.equal('root')
.to
.equal('root')
}) })
it('Should register a new user', async function () { it('Should register a new user', async function () {
@ -522,9 +404,7 @@ describe('Test users', function () {
const res = await getMyUserInformation(server.url, accessToken) const res = await getMyUserInformation(server.url, accessToken)
const user = res.body const user = res.body
expect(user.videoQuota) expect(user.videoQuota).to.equal(5 * 1024 * 1024)
.to
.equal(5 * 1024 * 1024)
}) })
after(async function () { after(async function () {

View file

@ -30,10 +30,8 @@ describe('Test services', function () {
const videoAttributes = { const videoAttributes = {
name: 'my super name' name: 'my super name'
} }
await uploadVideo(server.url, server.accessToken, videoAttributes) const res = await uploadVideo(server.url, server.accessToken, videoAttributes)
server.video = res.body.video
const res = await getVideosList(server.url)
server.video = res.body.data[0]
}) })
it('Should have a valid oEmbed response', async function () { it('Should have a valid oEmbed response', async function () {

View file

@ -1,21 +1,13 @@
/* tslint:disable:no-unused-expression */ /* tslint:disable:no-unused-expression */
import 'mocha'
import * as chai from 'chai' import * as chai from 'chai'
const expect = chai.expect import 'mocha'
import { import {
ServerInfo, flushAndRunMultipleServers, flushTests, getVideo, getVideosList, killallServers, ServerInfo, setAccessTokensToServers, uploadVideo,
flushTests, wait, webtorrentAdd
uploadVideo, } from '../../utils'
getVideosList,
wait, const expect = chai.expect
setAccessTokensToServers,
flushAndRunMultipleServers,
killallServers,
webtorrentAdd,
getVideo
} from '../../utils/index'
describe('Test video transcoding', function () { describe('Test video transcoding', function () {
let servers: ServerInfo[] = [] let servers: ServerInfo[] = []

View file

@ -1,372 +1,371 @@
// // /!\ Before imports /!\ // /!\ Before imports /!\
// process.env.NODE_ENV = 'test' process.env.NODE_ENV = 'test'
//
// import * as program from 'commander' import * as program from 'commander'
// import { Video, VideoFile, VideoRateType } from '../../../shared' import { Video, VideoFile, VideoRateType } from '../../../shared'
// import { import {
// flushAndRunMultipleServers, flushAndRunMultipleServers,
// flushTests, flushTests, follow,
// getAllVideosListBy, getVideo,
// getVideo, getVideosList, getVideosListPagination,
// getVideosList, killallServers,
// killallServers, removeVideo,
// removeVideo, ServerInfo as DefaultServerInfo,
// ServerInfo as DefaultServerInfo, setAccessTokensToServers,
// setAccessTokensToServers, updateVideo,
// updateVideo, uploadVideo, viewVideo,
// uploadVideo, wait
// wait } from '../utils'
// } from '../utils' import { getJobsListPaginationAndSort } from '../utils/server/jobs'
// import { follow } from '../utils/follows'
// interface ServerInfo extends DefaultServerInfo {
// interface ServerInfo extends DefaultServerInfo { requestsNumber: number
// requestsNumber: number }
// }
// program
// program .option('-c, --create [weight]', 'Weight for creating videos')
// .option('-c, --create [weight]', 'Weight for creating videos') .option('-r, --remove [weight]', 'Weight for removing videos')
// .option('-r, --remove [weight]', 'Weight for removing videos') .option('-u, --update [weight]', 'Weight for updating videos')
// .option('-u, --update [weight]', 'Weight for updating videos') .option('-v, --view [weight]', 'Weight for viewing videos')
// .option('-v, --view [weight]', 'Weight for viewing videos') .option('-l, --like [weight]', 'Weight for liking videos')
// .option('-l, --like [weight]', 'Weight for liking videos') .option('-s, --dislike [weight]', 'Weight for disliking videos')
// .option('-s, --dislike [weight]', 'Weight for disliking videos') .option('-p, --servers [n]', 'Number of servers to run (3 or 6)', /^3|6$/, 3)
// .option('-p, --servers [n]', 'Number of servers to run (3 or 6)', /^3|6$/, 3) .option('-i, --interval-action [interval]', 'Interval in ms for an action')
// .option('-i, --interval-action [interval]', 'Interval in ms for an action') .option('-I, --interval-integrity [interval]', 'Interval in ms for an integrity check')
// .option('-I, --interval-integrity [interval]', 'Interval in ms for an integrity check') .option('-f, --flush', 'Flush data on exit')
// .option('-f, --flush', 'Flush datas on exit') .option('-d, --difference', 'Display difference if integrity is not okay')
// .option('-d, --difference', 'Display difference if integrity is not okay') .parse(process.argv)
// .parse(process.argv)
// const createWeight = program['create'] !== undefined ? parseInt(program['create'], 10) : 5
// const createWeight = program['create'] !== undefined ? parseInt(program['create'], 10) : 5 const removeWeight = program['remove'] !== undefined ? parseInt(program['remove'], 10) : 4
// const removeWeight = program['remove'] !== undefined ? parseInt(program['remove'], 10) : 4 const updateWeight = program['update'] !== undefined ? parseInt(program['update'], 10) : 4
// const updateWeight = program['update'] !== undefined ? parseInt(program['update'], 10) : 4 const viewWeight = program['view'] !== undefined ? parseInt(program['view'], 10) : 4
// const viewWeight = program['view'] !== undefined ? parseInt(program['view'], 10) : 4 const likeWeight = program['like'] !== undefined ? parseInt(program['like'], 10) : 4
// const likeWeight = program['like'] !== undefined ? parseInt(program['like'], 10) : 4 const dislikeWeight = program['dislike'] !== undefined ? parseInt(program['dislike'], 10) : 4
// const dislikeWeight = program['dislike'] !== undefined ? parseInt(program['dislike'], 10) : 4 const flushAtExit = program['flush'] || false
// const flushAtExit = program['flush'] || false const actionInterval = program['intervalAction'] !== undefined ? parseInt(program['intervalAction'], 10) : 500
// const actionInterval = program['intervalAction'] !== undefined ? parseInt(program['intervalAction'], 10) : 500 const integrityInterval = program['intervalIntegrity'] !== undefined ? parseInt(program['intervalIntegrity'], 10) : 60000
// const integrityInterval = program['intervalIntegrity'] !== undefined ? parseInt(program['intervalIntegrity'], 10) : 60000 const displayDiffOnFail = program['difference'] || false
// const displayDiffOnFail = program['difference'] || false
// const numberOfServers = 6
// const numberOfServers = 6
// console.log(
// console.log( 'Create weight: %d, update weight: %d, remove weight: %d, view weight: %d, like weight: %d, dislike weight: %d.',
// 'Create weight: %d, update weight: %d, remove weight: %d, view weight: %d, like weight: %d, dislike weight: %d.', createWeight, updateWeight, removeWeight, viewWeight, likeWeight, dislikeWeight
// createWeight, updateWeight, removeWeight, viewWeight, likeWeight, dislikeWeight )
// )
// if (flushAtExit) {
// if (flushAtExit) { console.log('Program will flush data on exit.')
// console.log('Program will flush data on exit.') } else {
// } else { console.log('Program will not flush data on exit.')
// console.log('Program will not flush data on exit.') }
// } if (displayDiffOnFail) {
// if (displayDiffOnFail) { console.log('Program will display diff on failure.')
// console.log('Program will display diff on failure.') } else {
// } else { console.log('Program will not display diff on failure')
// 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 action: %d.', actionInterval) console.log('Interval in ms for each integrity check: %d.', integrityInterval)
// console.log('Interval in ms for each integrity check: %d.', integrityInterval)
// console.log('Run servers...')
// console.log('Run servers...')
// start()
// start()
// // ----------------------------------------------------------------------------
// // ----------------------------------------------------------------------------
// async function start () {
// async function start () { const servers = await runServers(numberOfServers)
// const servers = await runServers(numberOfServers)
// process.on('exit', async () => {
// process.on('exit', async () => { await exitServers(servers, flushAtExit)
// await exitServers(servers, flushAtExit)
// return
// return })
// }) process.on('SIGINT', goodbye)
// process.on('SIGINT', goodbye) process.on('SIGTERM', goodbye)
// process.on('SIGTERM', goodbye)
// console.log('Servers ran')
// console.log('Servers ran') initializeRequestsPerServer(servers)
// initializeRequestsPerServer(servers)
// let checking = false
// let checking = false
// setInterval(async () => {
// setInterval(async () => { if (checking === true) return
// if (checking === true) return
// const rand = getRandomInt(0, createWeight + updateWeight + removeWeight + viewWeight + likeWeight + dislikeWeight)
// const rand = getRandomInt(0, createWeight + updateWeight + removeWeight + viewWeight + likeWeight + dislikeWeight)
// const numServer = getRandomNumServer(servers)
// const numServer = getRandomNumServer(servers) servers[numServer].requestsNumber++
// servers[numServer].requestsNumber++
// if (rand < createWeight) {
// if (rand < createWeight) { await upload(servers, numServer)
// await upload(servers, numServer) } else if (rand < createWeight + updateWeight) {
// } else if (rand < createWeight + updateWeight) { await update(servers, numServer)
// await update(servers, numServer) } else if (rand < createWeight + updateWeight + removeWeight) {
// } else if (rand < createWeight + updateWeight + removeWeight) { await remove(servers, numServer)
// await remove(servers, numServer) } else if (rand < createWeight + updateWeight + removeWeight + viewWeight) {
// } else if (rand < createWeight + updateWeight + removeWeight + viewWeight) { await view(servers, numServer)
// await view(servers, numServer) } else if (rand < createWeight + updateWeight + removeWeight + viewWeight + likeWeight) {
// } else if (rand < createWeight + updateWeight + removeWeight + viewWeight + likeWeight) { await like(servers, numServer)
// await like(servers, numServer) } else {
// } else { await dislike(servers, numServer)
// await dislike(servers, numServer) }
// } }, actionInterval)
// }, actionInterval)
// // The function will check the consistency between servers (should have the same videos with same attributes...)
// // The function will check the consistency between servers (should have the same videos with same attributes...) setInterval(function () {
// setInterval(function () { if (checking === true) return
// if (checking === true) return
// console.log('Checking integrity...')
// console.log('Checking integrity...') checking = true
// checking = true
// const waitingInterval = setInterval(async () => {
// const waitingInterval = setInterval(async () => { const pendingRequests = await isTherePendingRequests(servers)
// const pendingRequests = await isTherePendingRequests(servers) if (pendingRequests === true) {
// if (pendingRequests === true) { console.log('A server has pending requests, waiting...')
// console.log('A server has pending requests, waiting...') return
// return }
// }
// // Even if there are no pending request, wait some potential processes
// // Even if there are no pending request, wait some potential processes await wait(2000)
// await wait(2000) await checkIntegrity(servers)
// await checkIntegrity(servers)
// initializeRequestsPerServer(servers)
// initializeRequestsPerServer(servers) checking = false
// checking = false clearInterval(waitingInterval)
// clearInterval(waitingInterval) }, 10000)
// }, 10000) }, integrityInterval)
// }, integrityInterval) }
// }
// function initializeRequestsPerServer (servers: ServerInfo[]) {
// function initializeRequestsPerServer (servers: ServerInfo[]) { servers.forEach(server => server.requestsNumber = 0)
// servers.forEach(server => server.requestsNumber = 0) }
// }
// function getRandomInt (min, max) {
// function getRandomInt (min, max) { return Math.floor(Math.random() * (max - min)) + min
// return Math.floor(Math.random() * (max - min)) + min }
// }
// function getRandomNumServer (servers) {
// function getRandomNumServer (servers) { return getRandomInt(0, servers.length)
// return getRandomInt(0, servers.length) }
// }
// async function runServers (numberOfServers: number) {
// async function runServers (numberOfServers: number) { const servers: ServerInfo[] = (await flushAndRunMultipleServers(numberOfServers))
// const servers: ServerInfo[] = (await flushAndRunMultipleServers(numberOfServers)) .map(s => Object.assign({ requestsNumber: 0 }, s))
// .map(s => Object.assign({ requestsNumber: 0 }, s))
// // Get the access tokens
// // Get the access tokens await setAccessTokensToServers(servers)
// await setAccessTokensToServers(servers)
// for (let i = 0; i < numberOfServers; i++) {
// for (let i = 0; i < numberOfServers; i++) { for (let j = 0; j < numberOfServers; j++) {
// for (let j = 0; j < numberOfServers; j++) { if (i === j) continue
// if (i === j) continue
// await follow(servers[i].url, [ servers[j].url ], servers[i].accessToken)
// await follow(servers[i].url, [ servers[j].url ], servers[i].accessToken) }
// } }
// }
// return servers
// return servers }
// }
// async function exitServers (servers: ServerInfo[], flushAtExit: boolean) {
// async function exitServers (servers: ServerInfo[], flushAtExit: boolean) { killallServers(servers)
// killallServers(servers)
// if (flushAtExit) await flushTests()
// if (flushAtExit) await flushTests() }
// }
// function upload (servers: ServerInfo[], numServer: number) {
// function upload (servers: ServerInfo[], numServer: number) { console.log('Uploading video to server ' + numServer)
// console.log('Uploading video to server ' + numServer)
// const videoAttributes = {
// const videoAttributes = { name: Date.now() + ' name',
// name: Date.now() + ' name', category: 4,
// category: 4, nsfw: false,
// nsfw: false, licence: 2,
// licence: 2, language: 1,
// language: 1, description: Date.now() + ' description',
// description: Date.now() + ' description', tags: [ Date.now().toString().substring(0, 5) + 't1', Date.now().toString().substring(0, 5) + 't2' ],
// tags: [ Date.now().toString().substring(0, 5) + 't1', Date.now().toString().substring(0, 5) + 't2' ], fixture: 'video_short1.webm'
// fixture: 'video_short1.webm' }
// } return uploadVideo(servers[numServer].url, servers[numServer].accessToken, videoAttributes)
// return uploadVideo(servers[numServer].url, servers[numServer].accessToken, videoAttributes) }
// }
// async function update (servers: ServerInfo[], numServer: number) {
// async function update (servers: ServerInfo[], numServer: number) { const res = await getVideosList(servers[numServer].url)
// const res = await getVideosList(servers[numServer].url)
// const videos = res.body.data.filter(video => video.isLocal === true)
// const videos = res.body.data.filter(video => video.isLocal === true) if (videos.length === 0) return undefined
// if (videos.length === 0) return undefined
// const toUpdate = videos[getRandomInt(0, videos.length)].id
// const toUpdate = videos[getRandomInt(0, videos.length)].id const attributes = {
// const attributes = { name: Date.now() + ' name',
// name: Date.now() + ' name', description: Date.now() + ' description',
// description: Date.now() + ' description', tags: [ Date.now().toString().substring(0, 5) + 't1', Date.now().toString().substring(0, 5) + 't2' ]
// tags: [ Date.now().toString().substring(0, 5) + 't1', Date.now().toString().substring(0, 5) + 't2' ] }
// }
// console.log('Updating video of server ' + numServer)
// console.log('Updating video of server ' + numServer)
// return updateVideo(servers[numServer].url, servers[numServer].accessToken, toUpdate, attributes)
// return updateVideo(servers[numServer].url, servers[numServer].accessToken, toUpdate, attributes) }
// }
// async function remove (servers: ServerInfo[], numServer: number) {
// async function remove (servers: ServerInfo[], numServer: number) { const res = await getVideosList(servers[numServer].url)
// const res = await getVideosList(servers[numServer].url) const videos = res.body.data.filter(video => video.isLocal === true)
// const videos = res.body.data.filter(video => video.isLocal === true) if (videos.length === 0) return undefined
// if (videos.length === 0) return undefined
// const toRemove = videos[getRandomInt(0, videos.length)].id
// const toRemove = videos[getRandomInt(0, videos.length)].id
// console.log('Removing video from server ' + numServer)
// console.log('Removing video from server ' + numServer) return removeVideo(servers[numServer].url, servers[numServer].accessToken, toRemove)
// return removeVideo(servers[numServer].url, servers[numServer].accessToken, toRemove) }
// }
// async function view (servers: ServerInfo[], numServer: number) {
// async function view (servers: ServerInfo[], numServer: number) { const res = await getVideosList(servers[numServer].url)
// const res = await getVideosList(servers[numServer].url)
// const videos = res.body.data
// const videos = res.body.data if (videos.length === 0) return undefined
// if (videos.length === 0) return undefined
// const toView = videos[getRandomInt(0, videos.length)].id
// const toView = videos[getRandomInt(0, videos.length)].id
// console.log('Viewing video from server ' + numServer)
// console.log('Viewing video from server ' + numServer) return viewVideo(servers[numServer].url, toView)
// return getVideo(servers[numServer].url, toView) }
// }
// function like (servers: ServerInfo[], numServer: number) {
// function like (servers: ServerInfo[], numServer: number) { return rate(servers, numServer, 'like')
// return rate(servers, numServer, 'like') }
// }
// function dislike (servers: ServerInfo[], numServer: number) {
// function dislike (servers: ServerInfo[], numServer: number) { return rate(servers, numServer, 'dislike')
// return rate(servers, numServer, 'dislike') }
// }
// async function rate (servers: ServerInfo[], numServer: number, rating: VideoRateType) {
// async function rate (servers: ServerInfo[], numServer: number, rating: VideoRateType) { const res = await getVideosList(servers[numServer].url)
// const res = await getVideosList(servers[numServer].url)
// const videos = res.body.data
// const videos = res.body.data if (videos.length === 0) return undefined
// if (videos.length === 0) return undefined
// const toRate = videos[getRandomInt(0, videos.length)].id
// const toRate = videos[getRandomInt(0, videos.length)].id
// console.log('Rating (%s) video from server %d', rating, numServer)
// console.log('Rating (%s) video from server %d', rating, numServer) return getVideo(servers[numServer].url, toRate)
// return getVideo(servers[numServer].url, toRate) }
// }
// async function checkIntegrity (servers: ServerInfo[]) {
// async function checkIntegrity (servers: ServerInfo[]) { const videos: Video[][] = []
// const videos: Video[][] = [] const tasks: Promise<any>[] = []
// const tasks: Promise<any>[] = []
// // Fetch all videos and remove some fields that can differ between servers
// // Fetch all videos and remove some fields that can differ between servers for (const server of servers) {
// for (const server of servers) { const p = getVideosListPagination(server.url, 0, 1000000, '-createdAt')
// const p = getAllVideosListBy(server.url).then(res => videos.push(res.body.data)) .then(res => videos.push(res.body.data))
// tasks.push(p) tasks.push(p)
// } }
//
// await Promise.all(tasks) await Promise.all(tasks)
//
// let i = 0 let i = 0
// for (const video of videos) { for (const video of videos) {
// const differences = areDifferences(video, videos[0]) const differences = areDifferences(video, videos[0])
// if (differences !== undefined) { if (differences !== undefined) {
// console.error('Integrity not ok with server %d!', i + 1) console.error('Integrity not ok with server %d!', i + 1)
//
// if (displayDiffOnFail) { if (displayDiffOnFail) {
// console.log(differences) console.log(differences)
// } }
//
// process.exit(-1) process.exit(-1)
// } }
//
// i++ i++
// } }
//
// console.log('Integrity ok.') console.log('Integrity ok.')
// } }
//
// function areDifferences (videos1: Video[], videos2: Video[]) { function areDifferences (videos1: Video[], videos2: Video[]) {
// // Remove some keys we don't want to compare // Remove some keys we don't want to compare
// videos1.concat(videos2).forEach(video => { videos1.concat(videos2).forEach(video => {
// delete video.id delete video.id
// delete video.isLocal delete video.isLocal
// delete video.thumbnailPath delete video.thumbnailPath
// delete video.updatedAt delete video.updatedAt
// delete video.views delete video.views
// }) })
//
// if (videos1.length !== videos2.length) { if (videos1.length !== videos2.length) {
// return `Videos length are different (${videos1.length}/${videos2.length}).` return `Videos length are different (${videos1.length}/${videos2.length}).`
// } }
//
// for (const video1 of videos1) { for (const video1 of videos1) {
// const video2 = videos2.find(video => video.uuid === video1.uuid) const video2 = videos2.find(video => video.uuid === video1.uuid)
//
// if (!video2) return 'Video ' + video1.uuid + ' is missing.' if (!video2) return 'Video ' + video1.uuid + ' is missing.'
//
// for (const videoKey of Object.keys(video1)) { for (const videoKey of Object.keys(video1)) {
// const attribute1 = video1[videoKey] const attribute1 = video1[videoKey]
// const attribute2 = video2[videoKey] const attribute2 = video2[videoKey]
//
// if (videoKey === 'tags') { if (videoKey === 'tags') {
// if (attribute1.length !== attribute2.length) { if (attribute1.length !== attribute2.length) {
// return 'Tags are different.' return 'Tags are different.'
// } }
//
// attribute1.forEach(tag1 => { attribute1.forEach(tag1 => {
// if (attribute2.indexOf(tag1) === -1) { if (attribute2.indexOf(tag1) === -1) {
// return 'Tag ' + tag1 + ' is missing.' return 'Tag ' + tag1 + ' is missing.'
// } }
// }) })
// } else if (videoKey === 'files') { } else if (videoKey === 'files') {
// if (attribute1.length !== attribute2.length) { if (attribute1.length !== attribute2.length) {
// return 'Video files are different.' return 'Video files are different.'
// } }
//
// attribute1.forEach((videoFile1: VideoFile) => { attribute1.forEach((videoFile1: VideoFile) => {
// const videoFile2: VideoFile = attribute2.find(videoFile => videoFile.magnetUri === videoFile1.magnetUri) const videoFile2: VideoFile = attribute2.find(videoFile => videoFile.magnetUri === videoFile1.magnetUri)
// if (!videoFile2) { if (!videoFile2) {
// return `Video ${video1.uuid} has missing video file ${videoFile1.magnetUri}.` return `Video ${video1.uuid} has missing video file ${videoFile1.magnetUri}.`
// } }
//
// if (videoFile1.size !== videoFile2.size || videoFile1.resolutionLabel !== videoFile2.resolutionLabel) { if (videoFile1.size !== videoFile2.size || videoFile1.resolutionLabel !== videoFile2.resolutionLabel) {
// return `Video ${video1.uuid} has different video file ${videoFile1.magnetUri}.` return `Video ${video1.uuid} has different video file ${videoFile1.magnetUri}.`
// } }
// }) })
// } else { } else {
// if (attribute1 !== attribute2) { if (attribute1 !== attribute2) {
// return `Video ${video1.uuid} has different value for attribute ${videoKey}.` return `Video ${video1.uuid} has different value for attribute ${videoKey}.`
// } }
// } }
// } }
// } }
//
// return undefined return undefined
// } }
//
// function goodbye () { function goodbye () {
// return process.exit(-1) return process.exit(-1)
// } }
//
// async function isTherePendingRequests (servers: ServerInfo[]) { async function isTherePendingRequests (servers: ServerInfo[]) {
// const tasks: Promise<any>[] = [] const tasks: Promise<any>[] = []
// let pendingRequests = false let pendingRequests = false
//
// // Check if each server has pending request // Check if each server has pending request
// for (const server of servers) { for (const server of servers) {
// const p = getRequestsStats(server).then(res => { const p = getJobsListPaginationAndSort(server.url, server.accessToken, 0, 10, '-createdAt')
// const stats = res.body .then(res => {
// const jobs = res.body.data
// if (
// stats.requestScheduler.totalRequests !== 0 || for (const job of jobs) {
// stats.requestVideoEventScheduler.totalRequests !== 0 || if (job.state === 'pending' || job.state === 'processing') {
// stats.requestVideoQaduScheduler.totalRequests !== 0 pendingRequests = true
// ) { }
// pendingRequests = true }
// } })
// })
// tasks.push(p)
// tasks.push(p) }
// }
// await Promise.all(tasks)
// await Promise.all(tasks)
// return pendingRequests
// return pendingRequests }
// }