aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/request-schedulers.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/request-schedulers.ts')
-rw-r--r--server/tests/api/request-schedulers.ts89
1 files changed, 89 insertions, 0 deletions
diff --git a/server/tests/api/request-schedulers.ts b/server/tests/api/request-schedulers.ts
new file mode 100644
index 000000000..2358ed8f7
--- /dev/null
+++ b/server/tests/api/request-schedulers.ts
@@ -0,0 +1,89 @@
1/* tslint:disable:no-unused-expression */
2
3import * as request from 'supertest'
4import 'mocha'
5import * as chai from 'chai'
6const expect = chai.expect
7
8import {
9 ServerInfo,
10 flushTests,
11 uploadVideo,
12 makeFriends,
13 wait,
14 setAccessTokensToServers,
15 flushAndRunMultipleServers
16} from '../utils'
17
18describe('Test requests schedulers stats', function () {
19 const requestSchedulerNames = [ 'requestScheduler', 'requestVideoQaduScheduler', 'requestVideoEventScheduler' ]
20 const path = '/api/v1/request-schedulers/stats'
21 let servers: ServerInfo[] = []
22
23 function uploadVideoWrapper (server: ServerInfo) {
24 const videoAttributes = {
25 tags: [ 'tag1', 'tag2' ]
26 }
27
28 return uploadVideo(server.url, server.accessToken, videoAttributes)
29 }
30
31 function getRequestsStats (server: ServerInfo) {
32 return request(server.url)
33 .get(path)
34 .set('Accept', 'application/json')
35 .set('Authorization', 'Bearer ' + server.accessToken)
36 .expect(200)
37 }
38
39 // ---------------------------------------------------------------
40
41 before(async function () {
42 this.timeout(120000)
43
44 servers = await flushAndRunMultipleServers(2)
45
46 await setAccessTokensToServers(servers)
47
48 await makeFriends(servers[0].url, servers[0].accessToken)
49 })
50
51 it('Should have a correct timer', async function () {
52 const server = servers[0]
53
54 const res = await getRequestsStats(server)
55
56 const requestSchedulers = res.body
57 for (const requestSchedulerName of requestSchedulerNames) {
58 const requestScheduler = requestSchedulers[requestSchedulerName]
59
60 expect(requestScheduler.remainingMilliSeconds).to.be.at.least(0)
61 expect(requestScheduler.remainingMilliSeconds).to.be.at.most(10000)
62 }
63 })
64
65 it('Should have the correct total request', async function () {
66 this.timeout(15000)
67
68 const server = servers[0]
69 // Ensure the requests of pod 1 won't be made
70 servers[1].app.kill()
71
72 await uploadVideoWrapper(server)
73
74 await wait(1000)
75
76 const res = await getRequestsStats(server)
77 const requestSchedulers = res.body
78 const requestScheduler = requestSchedulers.requestScheduler
79 expect(requestScheduler.totalRequests).to.equal(1)
80 })
81
82 after(async function () {
83 process.kill(-servers[0].app.pid)
84
85 if (this['ok']) {
86 await flushTests()
87 }
88 })
89})