aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/check-params/follows.ts84
-rw-r--r--server/tests/api/follows.ts174
-rw-r--r--server/tests/api/index-slow.ts1
-rw-r--r--server/tests/cli/reset-password.ts2
-rw-r--r--server/tests/real-world/real-world.ts745
-rw-r--r--server/tests/utils/follows.ts13
-rw-r--r--server/tests/utils/index.ts1
-rw-r--r--server/tests/utils/request-schedulers.ts20
8 files changed, 604 insertions, 436 deletions
diff --git a/server/tests/api/check-params/follows.ts b/server/tests/api/check-params/follows.ts
index a215e7b1a..0af1562f5 100644
--- a/server/tests/api/check-params/follows.ts
+++ b/server/tests/api/check-params/follows.ts
@@ -166,47 +166,49 @@ describe('Test server follows API validators', function () {
166 }) 166 })
167 167
168 describe('When removing following', function () { 168 describe('When removing following', function () {
169 // it('Should fail with an invalid token', async function () { 169 const path = '/api/v1/server/following'
170 // await request(server.url) 170
171 // .delete(path + '/1') 171 it('Should fail with an invalid token', async function () {
172 // .set('Authorization', 'Bearer faketoken') 172 await request(server.url)
173 // .set('Accept', 'application/json') 173 .delete(path + '/1')
174 // .expect(401) 174 .set('Authorization', 'Bearer faketoken')
175 // }) 175 .set('Accept', 'application/json')
176 // 176 .expect(401)
177 // it('Should fail if the user is not an administrator', async function () { 177 })
178 // await request(server.url) 178
179 // .delete(path + '/1') 179 it('Should fail if the user is not an administrator', async function () {
180 // .set('Authorization', 'Bearer ' + userAccessToken) 180 await request(server.url)
181 // .set('Accept', 'application/json') 181 .delete(path + '/1')
182 // .expect(403) 182 .set('Authorization', 'Bearer ' + userAccessToken)
183 // }) 183 .set('Accept', 'application/json')
184 // 184 .expect(403)
185 // it('Should fail with an undefined id', async function () { 185 })
186 // await request(server.url) 186
187 // .delete(path + '/' + undefined) 187 it('Should fail with an undefined id', async function () {
188 // .set('Authorization', 'Bearer ' + server.accessToken) 188 await request(server.url)
189 // .set('Accept', 'application/json') 189 .delete(path + '/' + undefined)
190 // .expect(400) 190 .set('Authorization', 'Bearer ' + server.accessToken)
191 // }) 191 .set('Accept', 'application/json')
192 // 192 .expect(400)
193 // it('Should fail with an invalid id', async function () { 193 })
194 // await request(server.url) 194
195 // .delete(path + '/foobar') 195 it('Should fail with an invalid id', async function () {
196 // .set('Authorization', 'Bearer ' + server.accessToken) 196 await request(server.url)
197 // .set('Accept', 'application/json') 197 .delete(path + '/foobar')
198 // .expect(400) 198 .set('Authorization', 'Bearer ' + server.accessToken)
199 // }) 199 .set('Accept', 'application/json')
200 // 200 .expect(400)
201 // it('Should fail we do not follow this server', async function () { 201 })
202 // await request(server.url) 202
203 // .delete(path + '/-1') 203 it('Should fail we do not follow this server', async function () {
204 // .set('Authorization', 'Bearer ' + server.accessToken) 204 await request(server.url)
205 // .set('Accept', 'application/json') 205 .delete(path + '/-1')
206 // .expect(404) 206 .set('Authorization', 'Bearer ' + server.accessToken)
207 // }) 207 .set('Accept', 'application/json')
208 // 208 .expect(404)
209 // it('Should succeed with the correct parameters') 209 })
210
211 it('Should succeed with the correct parameters')
210 }) 212 })
211 }) 213 })
212 214
diff --git a/server/tests/api/follows.ts b/server/tests/api/follows.ts
new file mode 100644
index 000000000..b2f53d3a7
--- /dev/null
+++ b/server/tests/api/follows.ts
@@ -0,0 +1,174 @@
1/* tslint:disable:no-unused-expression */
2
3import * as chai from 'chai'
4import 'mocha'
5
6import {
7 flushAndRunMultipleServers,
8 flushTests,
9 getVideosList,
10 killallServers,
11 ServerInfo,
12 setAccessTokensToServers,
13 uploadVideo,
14 wait
15} from '../utils'
16import { follow, getFollowersListPaginationAndSort, getFollowingListPaginationAndSort, unfollow } from '../utils/follows'
17
18const expect = chai.expect
19
20describe('Test follows', function () {
21 let servers: ServerInfo[] = []
22 let server3Id: number
23
24 before(async function () {
25 this.timeout(120000)
26
27 servers = await flushAndRunMultipleServers(3)
28
29 // Get the access tokens
30 await setAccessTokensToServers(servers)
31 })
32
33 it('Should not have followers', async function () {
34 for (const server of servers) {
35 const res = await getFollowersListPaginationAndSort(server.url, 0, 5, 'createdAt')
36 const follows = res.body.data
37
38 expect(res.body.total).to.equal(0)
39 expect(follows).to.be.an('array')
40 expect(follows.length).to.equal(0)
41 }
42 })
43
44 it('Should not have following', async function () {
45 for (const server of servers) {
46 const res = await getFollowingListPaginationAndSort(server.url, 0, 5, 'createdAt')
47 const follows = res.body.data
48
49 expect(res.body.total).to.equal(0)
50 expect(follows).to.be.an('array')
51 expect(follows.length).to.equal(0)
52 }
53 })
54
55 it('Should have server 1 following server 2 and 3', async function () {
56 this.timeout(10000)
57
58 await follow(servers[0].url, [ servers[1].url, servers[2].url ], servers[0].accessToken)
59
60 await wait(7000)
61 })
62
63 it('Should have 2 followings on server 1', async function () {
64 let res = await getFollowingListPaginationAndSort(servers[0].url, 0, 1, 'createdAt')
65 let follows = res.body.data
66
67 expect(res.body.total).to.equal(2)
68 expect(follows).to.be.an('array')
69 expect(follows.length).to.equal(1)
70
71 res = await getFollowingListPaginationAndSort(servers[0].url, 1, 1, 'createdAt')
72 follows = follows.concat(res.body.data)
73
74 const server2Follow = follows.find(f => f.following.host === 'localhost:9002')
75 const server3Follow = follows.find(f => f.following.host === 'localhost:9003')
76
77 expect(server2Follow).to.not.be.undefined
78 expect(server3Follow).to.not.be.undefined
79 expect(server2Follow.state).to.equal('accepted')
80 expect(server3Follow.state).to.equal('accepted')
81
82 server3Id = server3Follow.following.id
83 })
84
85 it('Should have 0 followings on server 1 and 2', async function () {
86 for (const server of [ servers[1], servers[2] ]) {
87 const res = await getFollowingListPaginationAndSort(server.url, 0, 5, 'createdAt')
88 const follows = res.body.data
89
90 expect(res.body.total).to.equal(0)
91 expect(follows).to.be.an('array')
92 expect(follows.length).to.equal(0)
93 }
94 })
95
96 it('Should have 1 followers on server 2 and 3', async function () {
97 for (const server of [ servers[1], servers[2] ]) {
98 let res = await getFollowersListPaginationAndSort(server.url, 0, 1, 'createdAt')
99
100 let follows = res.body.data
101 expect(res.body.total).to.equal(1)
102 expect(follows).to.be.an('array')
103 expect(follows.length).to.equal(1)
104 expect(follows[0].follower.host).to.equal('localhost:9001')
105 }
106 })
107
108 it('Should have 0 followers on server 1', async function () {
109 const res = await getFollowersListPaginationAndSort(servers[0].url, 0, 5, 'createdAt')
110 const follows = res.body.data
111
112 expect(res.body.total).to.equal(0)
113 expect(follows).to.be.an('array')
114 expect(follows.length).to.equal(0)
115 })
116
117 it('Should unfollow server 3 on server 1', async function () {
118 this.timeout(5000)
119
120 await unfollow(servers[0].url, servers[0].accessToken, server3Id)
121
122 await wait(3000)
123 })
124
125 it('Should not follow server 3 on server 1 anymore', async function () {
126 const res = await getFollowingListPaginationAndSort(servers[0].url, 0, 2, 'createdAt')
127 let follows = res.body.data
128
129 expect(res.body.total).to.equal(1)
130 expect(follows).to.be.an('array')
131 expect(follows.length).to.equal(1)
132
133 expect(follows[0].following.host).to.equal('localhost:9002')
134 })
135
136 it('Should not have server 1 as follower on server 3 anymore', async function () {
137 const res = await getFollowersListPaginationAndSort(servers[2].url, 0, 1, 'createdAt')
138
139 let follows = res.body.data
140 expect(res.body.total).to.equal(0)
141 expect(follows).to.be.an('array')
142 expect(follows.length).to.equal(0)
143 })
144
145 it('Should upload a video on server 2 ans 3 and propagate only the video of server 2', async function () {
146 this.timeout(10000)
147
148 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'server2' })
149 await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3' })
150
151 await wait(5000)
152
153 let res = await getVideosList(servers[0].url)
154 expect(res.body.total).to.equal(1)
155 expect(res.body.data[0].name).to.equal('server2')
156
157 res = await getVideosList(servers[1].url)
158 expect(res.body.total).to.equal(1)
159 expect(res.body.data[0].name).to.equal('server2')
160
161 res = await getVideosList(servers[2].url)
162 expect(res.body.total).to.equal(1)
163 expect(res.body.data[0].name).to.equal('server3')
164 })
165
166 after(async function () {
167 killallServers(servers)
168
169 // Keep the logs if the test failed
170 if (this['ok']) {
171 await flushTests()
172 }
173 })
174})
diff --git a/server/tests/api/index-slow.ts b/server/tests/api/index-slow.ts
index b3c3d778c..da56398b1 100644
--- a/server/tests/api/index-slow.ts
+++ b/server/tests/api/index-slow.ts
@@ -1,3 +1,4 @@
1// Order of the tests we want to execute 1// Order of the tests we want to execute
2// import './multiple-servers' 2// import './multiple-servers'
3import './video-transcoder' 3import './video-transcoder'
4import './follows'
diff --git a/server/tests/cli/reset-password.ts b/server/tests/cli/reset-password.ts
index c75a1611c..98ea7d456 100644
--- a/server/tests/cli/reset-password.ts
+++ b/server/tests/cli/reset-password.ts
@@ -26,7 +26,7 @@ describe('Test reset password scripts', function () {
26 }) 26 })
27 27
28 it('Should change the user password from CLI', async function () { 28 it('Should change the user password from CLI', async function () {
29 this.timeout(30000) 29 this.timeout(60000)
30 30
31 const env = getEnvCli(server) 31 const env = getEnvCli(server)
32 await execCLI(`echo coucou | ${env} npm run reset-password -- -u user_1`) 32 await execCLI(`echo coucou | ${env} npm run reset-password -- -u user_1`)
diff --git a/server/tests/real-world/real-world.ts b/server/tests/real-world/real-world.ts
index ac83d64a6..1afa55267 100644
--- a/server/tests/real-world/real-world.ts
+++ b/server/tests/real-world/real-world.ts
@@ -1,373 +1,372 @@
1// /!\ Before imports /!\ 1// // /!\ Before imports /!\
2process.env.NODE_ENV = 'test' 2// process.env.NODE_ENV = 'test'
3 3//
4import * as program from 'commander' 4// import * as program from 'commander'
5import { Video, VideoFile, VideoRateType } from '../../../shared' 5// import { Video, VideoFile, VideoRateType } from '../../../shared'
6import { 6// import {
7 flushAndRunMultipleServers, 7// flushAndRunMultipleServers,
8 flushTests, 8// flushTests,
9 getAllVideosListBy, 9// getAllVideosListBy,
10 getRequestsStats, 10// getVideo,
11 getVideo, 11// getVideosList,
12 getVideosList, 12// killallServers,
13 killallServers, 13// removeVideo,
14 removeVideo, 14// ServerInfo as DefaultServerInfo,
15 ServerInfo as DefaultServerInfo, 15// setAccessTokensToServers,
16 setAccessTokensToServers, 16// updateVideo,
17 updateVideo, 17// uploadVideo,
18 uploadVideo, 18// wait
19 wait 19// } from '../utils'
20} from '../utils' 20// import { follow } from '../utils/follows'
21import { follow } from '../utils/follows' 21//
22 22// interface ServerInfo extends DefaultServerInfo {
23interface ServerInfo extends DefaultServerInfo { 23// requestsNumber: number
24 requestsNumber: number 24// }
25} 25//
26 26// program
27program 27// .option('-c, --create [weight]', 'Weight for creating videos')
28 .option('-c, --create [weight]', 'Weight for creating videos') 28// .option('-r, --remove [weight]', 'Weight for removing videos')
29 .option('-r, --remove [weight]', 'Weight for removing videos') 29// .option('-u, --update [weight]', 'Weight for updating videos')
30 .option('-u, --update [weight]', 'Weight for updating videos') 30// .option('-v, --view [weight]', 'Weight for viewing videos')
31 .option('-v, --view [weight]', 'Weight for viewing videos') 31// .option('-l, --like [weight]', 'Weight for liking videos')
32 .option('-l, --like [weight]', 'Weight for liking videos') 32// .option('-s, --dislike [weight]', 'Weight for disliking videos')
33 .option('-s, --dislike [weight]', 'Weight for disliking videos') 33// .option('-p, --servers [n]', 'Number of servers to run (3 or 6)', /^3|6$/, 3)
34 .option('-p, --servers [n]', 'Number of servers to run (3 or 6)', /^3|6$/, 3) 34// .option('-i, --interval-action [interval]', 'Interval in ms for an action')
35 .option('-i, --interval-action [interval]', 'Interval in ms for an action') 35// .option('-I, --interval-integrity [interval]', 'Interval in ms for an integrity check')
36 .option('-I, --interval-integrity [interval]', 'Interval in ms for an integrity check') 36// .option('-f, --flush', 'Flush datas on exit')
37 .option('-f, --flush', 'Flush datas on exit') 37// .option('-d, --difference', 'Display difference if integrity is not okay')
38 .option('-d, --difference', 'Display difference if integrity is not okay') 38// .parse(process.argv)
39 .parse(process.argv) 39//
40 40// const createWeight = program['create'] !== undefined ? parseInt(program['create'], 10) : 5
41const createWeight = program['create'] !== undefined ? parseInt(program['create'], 10) : 5 41// const removeWeight = program['remove'] !== undefined ? parseInt(program['remove'], 10) : 4
42const removeWeight = program['remove'] !== undefined ? parseInt(program['remove'], 10) : 4 42// const updateWeight = program['update'] !== undefined ? parseInt(program['update'], 10) : 4
43const updateWeight = program['update'] !== undefined ? parseInt(program['update'], 10) : 4 43// const viewWeight = program['view'] !== undefined ? parseInt(program['view'], 10) : 4
44const viewWeight = program['view'] !== undefined ? parseInt(program['view'], 10) : 4 44// const likeWeight = program['like'] !== undefined ? parseInt(program['like'], 10) : 4
45const likeWeight = program['like'] !== undefined ? parseInt(program['like'], 10) : 4 45// const dislikeWeight = program['dislike'] !== undefined ? parseInt(program['dislike'], 10) : 4
46const dislikeWeight = program['dislike'] !== undefined ? parseInt(program['dislike'], 10) : 4 46// const flushAtExit = program['flush'] || false
47const flushAtExit = program['flush'] || false 47// const actionInterval = program['intervalAction'] !== undefined ? parseInt(program['intervalAction'], 10) : 500
48const actionInterval = program['intervalAction'] !== undefined ? parseInt(program['intervalAction'], 10) : 500 48// const integrityInterval = program['intervalIntegrity'] !== undefined ? parseInt(program['intervalIntegrity'], 10) : 60000
49const integrityInterval = program['intervalIntegrity'] !== undefined ? parseInt(program['intervalIntegrity'], 10) : 60000 49// const displayDiffOnFail = program['difference'] || false
50const displayDiffOnFail = program['difference'] || false 50//
51 51// const numberOfServers = 6
52const numberOfServers = 6 52//
53 53// console.log(
54console.log( 54// 'Create weight: %d, update weight: %d, remove weight: %d, view weight: %d, like weight: %d, dislike weight: %d.',
55 'Create weight: %d, update weight: %d, remove weight: %d, view weight: %d, like weight: %d, dislike weight: %d.', 55// createWeight, updateWeight, removeWeight, viewWeight, likeWeight, dislikeWeight
56 createWeight, updateWeight, removeWeight, viewWeight, likeWeight, dislikeWeight 56// )
57) 57//
58 58// if (flushAtExit) {
59if (flushAtExit) { 59// console.log('Program will flush data on exit.')
60 console.log('Program will flush data on exit.') 60// } else {
61} else { 61// console.log('Program will not flush data on exit.')
62 console.log('Program will not flush data on exit.') 62// }
63} 63// if (displayDiffOnFail) {
64if (displayDiffOnFail) { 64// console.log('Program will display diff on failure.')
65 console.log('Program will display diff on failure.') 65// } else {
66} else { 66// console.log('Program will not display diff on failure')
67 console.log('Program will not display diff on failure') 67// }
68} 68// console.log('Interval in ms for each action: %d.', actionInterval)
69console.log('Interval in ms for each action: %d.', actionInterval) 69// console.log('Interval in ms for each integrity check: %d.', integrityInterval)
70console.log('Interval in ms for each integrity check: %d.', integrityInterval) 70//
71 71// console.log('Run servers...')
72console.log('Run servers...') 72//
73 73// start()
74start() 74//
75 75// // ----------------------------------------------------------------------------
76// ---------------------------------------------------------------------------- 76//
77 77// async function start () {
78async function start () { 78// const servers = await runServers(numberOfServers)
79 const servers = await runServers(numberOfServers) 79//
80 80// process.on('exit', async () => {
81 process.on('exit', async () => { 81// await exitServers(servers, flushAtExit)
82 await exitServers(servers, flushAtExit) 82//
83 83// return
84 return 84// })
85 }) 85// process.on('SIGINT', goodbye)
86 process.on('SIGINT', goodbye) 86// process.on('SIGTERM', goodbye)
87 process.on('SIGTERM', goodbye) 87//
88 88// console.log('Servers ran')
89 console.log('Servers ran') 89// initializeRequestsPerServer(servers)
90 initializeRequestsPerServer(servers) 90//
91 91// let checking = false
92 let checking = false 92//
93 93// setInterval(async () => {
94 setInterval(async () => { 94// if (checking === true) return
95 if (checking === true) return 95//
96 96// const rand = getRandomInt(0, createWeight + updateWeight + removeWeight + viewWeight + likeWeight + dislikeWeight)
97 const rand = getRandomInt(0, createWeight + updateWeight + removeWeight + viewWeight + likeWeight + dislikeWeight) 97//
98 98// const numServer = getRandomNumServer(servers)
99 const numServer = getRandomNumServer(servers) 99// servers[numServer].requestsNumber++
100 servers[numServer].requestsNumber++ 100//
101 101// if (rand < createWeight) {
102 if (rand < createWeight) { 102// await upload(servers, numServer)
103 await upload(servers, numServer) 103// } else if (rand < createWeight + updateWeight) {
104 } else if (rand < createWeight + updateWeight) { 104// await update(servers, numServer)
105 await update(servers, numServer) 105// } else if (rand < createWeight + updateWeight + removeWeight) {
106 } else if (rand < createWeight + updateWeight + removeWeight) { 106// await remove(servers, numServer)
107 await remove(servers, numServer) 107// } else if (rand < createWeight + updateWeight + removeWeight + viewWeight) {
108 } else if (rand < createWeight + updateWeight + removeWeight + viewWeight) { 108// await view(servers, numServer)
109 await view(servers, numServer) 109// } else if (rand < createWeight + updateWeight + removeWeight + viewWeight + likeWeight) {
110 } else if (rand < createWeight + updateWeight + removeWeight + viewWeight + likeWeight) { 110// await like(servers, numServer)
111 await like(servers, numServer) 111// } else {
112 } else { 112// await dislike(servers, numServer)
113 await dislike(servers, numServer) 113// }
114 } 114// }, actionInterval)
115 }, actionInterval) 115//
116 116// // The function will check the consistency between servers (should have the same videos with same attributes...)
117 // The function will check the consistency between servers (should have the same videos with same attributes...) 117// setInterval(function () {
118 setInterval(function () { 118// if (checking === true) return
119 if (checking === true) return 119//
120 120// console.log('Checking integrity...')
121 console.log('Checking integrity...') 121// checking = true
122 checking = true 122//
123 123// const waitingInterval = setInterval(async () => {
124 const waitingInterval = setInterval(async () => { 124// const pendingRequests = await isTherePendingRequests(servers)
125 const pendingRequests = await isTherePendingRequests(servers) 125// if (pendingRequests === true) {
126 if (pendingRequests === true) { 126// console.log('A server has pending requests, waiting...')
127 console.log('A server has pending requests, waiting...') 127// return
128 return 128// }
129 } 129//
130 130// // Even if there are no pending request, wait some potential processes
131 // Even if there are no pending request, wait some potential processes 131// await wait(2000)
132 await wait(2000) 132// await checkIntegrity(servers)
133 await checkIntegrity(servers) 133//
134 134// initializeRequestsPerServer(servers)
135 initializeRequestsPerServer(servers) 135// checking = false
136 checking = false 136// clearInterval(waitingInterval)
137 clearInterval(waitingInterval) 137// }, 10000)
138 }, 10000) 138// }, integrityInterval)
139 }, integrityInterval) 139// }
140} 140//
141 141// function initializeRequestsPerServer (servers: ServerInfo[]) {
142function initializeRequestsPerServer (servers: ServerInfo[]) { 142// servers.forEach(server => server.requestsNumber = 0)
143 servers.forEach(server => server.requestsNumber = 0) 143// }
144} 144//
145 145// function getRandomInt (min, max) {
146function getRandomInt (min, max) { 146// return Math.floor(Math.random() * (max - min)) + min
147 return Math.floor(Math.random() * (max - min)) + min 147// }
148} 148//
149 149// function getRandomNumServer (servers) {
150function getRandomNumServer (servers) { 150// return getRandomInt(0, servers.length)
151 return getRandomInt(0, servers.length) 151// }
152} 152//
153 153// async function runServers (numberOfServers: number) {
154async function runServers (numberOfServers: number) { 154// const servers: ServerInfo[] = (await flushAndRunMultipleServers(numberOfServers))
155 const servers: ServerInfo[] = (await flushAndRunMultipleServers(numberOfServers)) 155// .map(s => Object.assign({ requestsNumber: 0 }, s))
156 .map(s => Object.assign({ requestsNumber: 0 }, s)) 156//
157 157// // Get the access tokens
158 // Get the access tokens 158// await setAccessTokensToServers(servers)
159 await setAccessTokensToServers(servers) 159//
160 160// for (let i = 0; i < numberOfServers; i++) {
161 for (let i = 0; i < numberOfServers; i++) { 161// for (let j = 0; j < numberOfServers; j++) {
162 for (let j = 0; j < numberOfServers; j++) { 162// if (i === j) continue
163 if (i === j) continue 163//
164 164// await follow(servers[i].url, [ servers[j].url ], servers[i].accessToken)
165 await follow(servers[i].url, [ servers[j].url ], servers[i].accessToken) 165// }
166 } 166// }
167 } 167//
168 168// return servers
169 return servers 169// }
170} 170//
171 171// async function exitServers (servers: ServerInfo[], flushAtExit: boolean) {
172async function exitServers (servers: ServerInfo[], flushAtExit: boolean) { 172// killallServers(servers)
173 killallServers(servers) 173//
174 174// if (flushAtExit) await flushTests()
175 if (flushAtExit) await flushTests() 175// }
176} 176//
177 177// function upload (servers: ServerInfo[], numServer: number) {
178function upload (servers: ServerInfo[], numServer: number) { 178// console.log('Uploading video to server ' + numServer)
179 console.log('Uploading video to server ' + numServer) 179//
180 180// const videoAttributes = {
181 const videoAttributes = { 181// name: Date.now() + ' name',
182 name: Date.now() + ' name', 182// category: 4,
183 category: 4, 183// nsfw: false,
184 nsfw: false, 184// licence: 2,
185 licence: 2, 185// language: 1,
186 language: 1, 186// description: Date.now() + ' description',
187 description: Date.now() + ' description', 187// tags: [ Date.now().toString().substring(0, 5) + 't1', Date.now().toString().substring(0, 5) + 't2' ],
188 tags: [ Date.now().toString().substring(0, 5) + 't1', Date.now().toString().substring(0, 5) + 't2' ], 188// fixture: 'video_short1.webm'
189 fixture: 'video_short1.webm' 189// }
190 } 190// return uploadVideo(servers[numServer].url, servers[numServer].accessToken, videoAttributes)
191 return uploadVideo(servers[numServer].url, servers[numServer].accessToken, videoAttributes) 191// }
192} 192//
193 193// async function update (servers: ServerInfo[], numServer: number) {
194async function update (servers: ServerInfo[], numServer: number) { 194// const res = await getVideosList(servers[numServer].url)
195 const res = await getVideosList(servers[numServer].url) 195//
196 196// const videos = res.body.data.filter(video => video.isLocal === true)
197 const videos = res.body.data.filter(video => video.isLocal === true) 197// if (videos.length === 0) return undefined
198 if (videos.length === 0) return undefined 198//
199 199// const toUpdate = videos[getRandomInt(0, videos.length)].id
200 const toUpdate = videos[getRandomInt(0, videos.length)].id 200// const attributes = {
201 const attributes = { 201// name: Date.now() + ' name',
202 name: Date.now() + ' name', 202// description: Date.now() + ' description',
203 description: Date.now() + ' description', 203// tags: [ Date.now().toString().substring(0, 5) + 't1', Date.now().toString().substring(0, 5) + 't2' ]
204 tags: [ Date.now().toString().substring(0, 5) + 't1', Date.now().toString().substring(0, 5) + 't2' ] 204// }
205 } 205//
206 206// console.log('Updating video of server ' + numServer)
207 console.log('Updating video of server ' + numServer) 207//
208 208// return updateVideo(servers[numServer].url, servers[numServer].accessToken, toUpdate, attributes)
209 return updateVideo(servers[numServer].url, servers[numServer].accessToken, toUpdate, attributes) 209// }
210} 210//
211 211// async function remove (servers: ServerInfo[], numServer: number) {
212async function remove (servers: ServerInfo[], numServer: number) { 212// const res = await getVideosList(servers[numServer].url)
213 const res = await getVideosList(servers[numServer].url) 213// const videos = res.body.data.filter(video => video.isLocal === true)
214 const videos = res.body.data.filter(video => video.isLocal === true) 214// if (videos.length === 0) return undefined
215 if (videos.length === 0) return undefined 215//
216 216// const toRemove = videos[getRandomInt(0, videos.length)].id
217 const toRemove = videos[getRandomInt(0, videos.length)].id 217//
218 218// console.log('Removing video from server ' + numServer)
219 console.log('Removing video from server ' + numServer) 219// return removeVideo(servers[numServer].url, servers[numServer].accessToken, toRemove)
220 return removeVideo(servers[numServer].url, servers[numServer].accessToken, toRemove) 220// }
221} 221//
222 222// async function view (servers: ServerInfo[], numServer: number) {
223async function view (servers: ServerInfo[], numServer: number) { 223// const res = await getVideosList(servers[numServer].url)
224 const res = await getVideosList(servers[numServer].url) 224//
225 225// const videos = res.body.data
226 const videos = res.body.data 226// if (videos.length === 0) return undefined
227 if (videos.length === 0) return undefined 227//
228 228// const toView = videos[getRandomInt(0, videos.length)].id
229 const toView = videos[getRandomInt(0, videos.length)].id 229//
230 230// console.log('Viewing video from server ' + numServer)
231 console.log('Viewing video from server ' + numServer) 231// return getVideo(servers[numServer].url, toView)
232 return getVideo(servers[numServer].url, toView) 232// }
233} 233//
234 234// function like (servers: ServerInfo[], numServer: number) {
235function like (servers: ServerInfo[], numServer: number) { 235// return rate(servers, numServer, 'like')
236 return rate(servers, numServer, 'like') 236// }
237} 237//
238 238// function dislike (servers: ServerInfo[], numServer: number) {
239function dislike (servers: ServerInfo[], numServer: number) { 239// return rate(servers, numServer, 'dislike')
240 return rate(servers, numServer, 'dislike') 240// }
241} 241//
242 242// async function rate (servers: ServerInfo[], numServer: number, rating: VideoRateType) {
243async function rate (servers: ServerInfo[], numServer: number, rating: VideoRateType) { 243// const res = await getVideosList(servers[numServer].url)
244 const res = await getVideosList(servers[numServer].url) 244//
245 245// const videos = res.body.data
246 const videos = res.body.data 246// if (videos.length === 0) return undefined
247 if (videos.length === 0) return undefined 247//
248 248// const toRate = videos[getRandomInt(0, videos.length)].id
249 const toRate = videos[getRandomInt(0, videos.length)].id 249//
250 250// console.log('Rating (%s) video from server %d', rating, numServer)
251 console.log('Rating (%s) video from server %d', rating, numServer) 251// return getVideo(servers[numServer].url, toRate)
252 return getVideo(servers[numServer].url, toRate) 252// }
253} 253//
254 254// async function checkIntegrity (servers: ServerInfo[]) {
255async function checkIntegrity (servers: ServerInfo[]) { 255// const videos: Video[][] = []
256 const videos: Video[][] = [] 256// const tasks: Promise<any>[] = []
257 const tasks: Promise<any>[] = [] 257//
258 258// // Fetch all videos and remove some fields that can differ between servers
259 // Fetch all videos and remove some fields that can differ between servers 259// for (const server of servers) {
260 for (const server of servers) { 260// const p = getAllVideosListBy(server.url).then(res => videos.push(res.body.data))
261 const p = getAllVideosListBy(server.url).then(res => videos.push(res.body.data)) 261// tasks.push(p)
262 tasks.push(p) 262// }
263 } 263//
264 264// await Promise.all(tasks)
265 await Promise.all(tasks) 265//
266 266// let i = 0
267 let i = 0 267// for (const video of videos) {
268 for (const video of videos) { 268// const differences = areDifferences(video, videos[0])
269 const differences = areDifferences(video, videos[0]) 269// if (differences !== undefined) {
270 if (differences !== undefined) { 270// console.error('Integrity not ok with server %d!', i + 1)
271 console.error('Integrity not ok with server %d!', i + 1) 271//
272 272// if (displayDiffOnFail) {
273 if (displayDiffOnFail) { 273// console.log(differences)
274 console.log(differences) 274// }
275 } 275//
276 276// process.exit(-1)
277 process.exit(-1) 277// }
278 } 278//
279 279// i++
280 i++ 280// }
281 } 281//
282 282// console.log('Integrity ok.')
283 console.log('Integrity ok.') 283// }
284} 284//
285 285// function areDifferences (videos1: Video[], videos2: Video[]) {
286function areDifferences (videos1: Video[], videos2: Video[]) { 286// // Remove some keys we don't want to compare
287 // Remove some keys we don't want to compare 287// videos1.concat(videos2).forEach(video => {
288 videos1.concat(videos2).forEach(video => { 288// delete video.id
289 delete video.id 289// delete video.isLocal
290 delete video.isLocal 290// delete video.thumbnailPath
291 delete video.thumbnailPath 291// delete video.updatedAt
292 delete video.updatedAt 292// delete video.views
293 delete video.views 293// })
294 }) 294//
295 295// if (videos1.length !== videos2.length) {
296 if (videos1.length !== videos2.length) { 296// return `Videos length are different (${videos1.length}/${videos2.length}).`
297 return `Videos length are different (${videos1.length}/${videos2.length}).` 297// }
298 } 298//
299 299// for (const video1 of videos1) {
300 for (const video1 of videos1) { 300// const video2 = videos2.find(video => video.uuid === video1.uuid)
301 const video2 = videos2.find(video => video.uuid === video1.uuid) 301//
302 302// if (!video2) return 'Video ' + video1.uuid + ' is missing.'
303 if (!video2) return 'Video ' + video1.uuid + ' is missing.' 303//
304 304// for (const videoKey of Object.keys(video1)) {
305 for (const videoKey of Object.keys(video1)) { 305// const attribute1 = video1[videoKey]
306 const attribute1 = video1[videoKey] 306// const attribute2 = video2[videoKey]
307 const attribute2 = video2[videoKey] 307//
308 308// if (videoKey === 'tags') {
309 if (videoKey === 'tags') { 309// if (attribute1.length !== attribute2.length) {
310 if (attribute1.length !== attribute2.length) { 310// return 'Tags are different.'
311 return 'Tags are different.' 311// }
312 } 312//
313 313// attribute1.forEach(tag1 => {
314 attribute1.forEach(tag1 => { 314// if (attribute2.indexOf(tag1) === -1) {
315 if (attribute2.indexOf(tag1) === -1) { 315// return 'Tag ' + tag1 + ' is missing.'
316 return 'Tag ' + tag1 + ' is missing.' 316// }
317 } 317// })
318 }) 318// } else if (videoKey === 'files') {
319 } else if (videoKey === 'files') { 319// if (attribute1.length !== attribute2.length) {
320 if (attribute1.length !== attribute2.length) { 320// return 'Video files are different.'
321 return 'Video files are different.' 321// }
322 } 322//
323 323// attribute1.forEach((videoFile1: VideoFile) => {
324 attribute1.forEach((videoFile1: VideoFile) => { 324// const videoFile2: VideoFile = attribute2.find(videoFile => videoFile.magnetUri === videoFile1.magnetUri)
325 const videoFile2: VideoFile = attribute2.find(videoFile => videoFile.magnetUri === videoFile1.magnetUri) 325// if (!videoFile2) {
326 if (!videoFile2) { 326// return `Video ${video1.uuid} has missing video file ${videoFile1.magnetUri}.`
327 return `Video ${video1.uuid} has missing video file ${videoFile1.magnetUri}.` 327// }
328 } 328//
329 329// if (videoFile1.size !== videoFile2.size || videoFile1.resolutionLabel !== videoFile2.resolutionLabel) {
330 if (videoFile1.size !== videoFile2.size || videoFile1.resolutionLabel !== videoFile2.resolutionLabel) { 330// return `Video ${video1.uuid} has different video file ${videoFile1.magnetUri}.`
331 return `Video ${video1.uuid} has different video file ${videoFile1.magnetUri}.` 331// }
332 } 332// })
333 }) 333// } else {
334 } else { 334// if (attribute1 !== attribute2) {
335 if (attribute1 !== attribute2) { 335// return `Video ${video1.uuid} has different value for attribute ${videoKey}.`
336 return `Video ${video1.uuid} has different value for attribute ${videoKey}.` 336// }
337 } 337// }
338 } 338// }
339 } 339// }
340 } 340//
341 341// return undefined
342 return undefined 342// }
343} 343//
344 344// function goodbye () {
345function goodbye () { 345// return process.exit(-1)
346 return process.exit(-1) 346// }
347} 347//
348 348// async function isTherePendingRequests (servers: ServerInfo[]) {
349async function isTherePendingRequests (servers: ServerInfo[]) { 349// const tasks: Promise<any>[] = []
350 const tasks: Promise<any>[] = [] 350// let pendingRequests = false
351 let pendingRequests = false 351//
352 352// // Check if each server has pending request
353 // Check if each server has pending request 353// for (const server of servers) {
354 for (const server of servers) { 354// const p = getRequestsStats(server).then(res => {
355 const p = getRequestsStats(server).then(res => { 355// const stats = res.body
356 const stats = res.body 356//
357 357// if (
358 if ( 358// stats.requestScheduler.totalRequests !== 0 ||
359 stats.requestScheduler.totalRequests !== 0 || 359// stats.requestVideoEventScheduler.totalRequests !== 0 ||
360 stats.requestVideoEventScheduler.totalRequests !== 0 || 360// stats.requestVideoQaduScheduler.totalRequests !== 0
361 stats.requestVideoQaduScheduler.totalRequests !== 0 361// ) {
362 ) { 362// pendingRequests = true
363 pendingRequests = true 363// }
364 } 364// })
365 }) 365//
366 366// tasks.push(p)
367 tasks.push(p) 367// }
368 } 368//
369 369// await Promise.all(tasks)
370 await Promise.all(tasks) 370//
371 371// return pendingRequests
372 return pendingRequests 372// }
373}
diff --git a/server/tests/utils/follows.ts b/server/tests/utils/follows.ts
index 618436b3c..b88776011 100644
--- a/server/tests/utils/follows.ts
+++ b/server/tests/utils/follows.ts
@@ -42,6 +42,18 @@ async function follow (follower: string, following: string[], accessToken: strin
42 return res 42 return res
43} 43}
44 44
45async function unfollow (url: string, accessToken: string, id: number, expectedStatus = 204) {
46 const path = '/api/v1/server/following/' + id
47
48 const res = await request(url)
49 .delete(path)
50 .set('Accept', 'application/json')
51 .set('Authorization', 'Bearer ' + accessToken)
52 .expect(expectedStatus)
53
54 return res
55}
56
45async function doubleFollow (server1: ServerInfo, server2: ServerInfo) { 57async function doubleFollow (server1: ServerInfo, server2: ServerInfo) {
46 await Promise.all([ 58 await Promise.all([
47 follow(server1.url, [ server2.url ], server1.accessToken), 59 follow(server1.url, [ server2.url ], server1.accessToken),
@@ -59,6 +71,7 @@ async function doubleFollow (server1: ServerInfo, server2: ServerInfo) {
59export { 71export {
60 getFollowersListPaginationAndSort, 72 getFollowersListPaginationAndSort,
61 getFollowingListPaginationAndSort, 73 getFollowingListPaginationAndSort,
74 unfollow,
62 follow, 75 follow,
63 doubleFollow 76 doubleFollow
64} 77}
diff --git a/server/tests/utils/index.ts b/server/tests/utils/index.ts
index fe6d3b041..4308fd49a 100644
--- a/server/tests/utils/index.ts
+++ b/server/tests/utils/index.ts
@@ -4,7 +4,6 @@ export * from './config'
4export * from './login' 4export * from './login'
5export * from './miscs' 5export * from './miscs'
6export * from './follows' 6export * from './follows'
7export * from './request-schedulers'
8export * from './requests' 7export * from './requests'
9export * from './servers' 8export * from './servers'
10export * from './services' 9export * from './services'
diff --git a/server/tests/utils/request-schedulers.ts b/server/tests/utils/request-schedulers.ts
deleted file mode 100644
index f100f6d99..000000000
--- a/server/tests/utils/request-schedulers.ts
+++ /dev/null
@@ -1,20 +0,0 @@
1import * as request from 'supertest'
2
3import { ServerInfo } from '../utils'
4
5function getRequestsStats (server: ServerInfo) {
6 const path = '/api/v1/request-schedulers/stats'
7
8 return request(server.url)
9 .get(path)
10 .set('Accept', 'application/json')
11 .set('Authorization', 'Bearer ' + server.accessToken)
12 .expect(200)
13 .expect('Content-Type', /json/)
14}
15
16// ---------------------------------------------------------------------------
17
18export {
19 getRequestsStats
20}