diff options
Diffstat (limited to 'server/tests/api/request-schedulers.js')
-rw-r--r-- | server/tests/api/request-schedulers.js | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/server/tests/api/request-schedulers.js b/server/tests/api/request-schedulers.js new file mode 100644 index 000000000..c5c443f14 --- /dev/null +++ b/server/tests/api/request-schedulers.js | |||
@@ -0,0 +1,111 @@ | |||
1 | /* eslint-disable no-unused-expressions */ | ||
2 | |||
3 | 'use strict' | ||
4 | |||
5 | const chai = require('chai') | ||
6 | const each = require('async/each') | ||
7 | const expect = chai.expect | ||
8 | const request = require('supertest') | ||
9 | |||
10 | const loginUtils = require('../utils/login') | ||
11 | const podsUtils = require('../utils/pods') | ||
12 | const serversUtils = require('../utils/servers') | ||
13 | const videosUtils = require('../utils/videos') | ||
14 | |||
15 | describe('Test requests schedulers stats', function () { | ||
16 | const requestSchedulerNames = [ 'requestScheduler', 'requestVideoQaduScheduler', 'requestVideoEventScheduler' ] | ||
17 | const path = '/api/v1/request-schedulers/stats' | ||
18 | let servers = [] | ||
19 | |||
20 | function uploadVideo (server, callback) { | ||
21 | const videoAttributes = { | ||
22 | tags: [ 'tag1', 'tag2' ] | ||
23 | } | ||
24 | |||
25 | videosUtils.uploadVideo(server.url, server.accessToken, videoAttributes, callback) | ||
26 | } | ||
27 | |||
28 | function getRequestsStats (server, callback) { | ||
29 | request(server.url) | ||
30 | .get(path) | ||
31 | .set('Accept', 'application/json') | ||
32 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
33 | .expect(200) | ||
34 | .end(callback) | ||
35 | } | ||
36 | |||
37 | // --------------------------------------------------------------- | ||
38 | |||
39 | before(function (done) { | ||
40 | this.timeout(20000) | ||
41 | serversUtils.flushAndRunMultipleServers(2, function (serversRun, urlsRun) { | ||
42 | servers = serversRun | ||
43 | |||
44 | each(servers, function (server, callbackEach) { | ||
45 | loginUtils.loginAndGetAccessToken(server, function (err, accessToken) { | ||
46 | if (err) return callbackEach(err) | ||
47 | |||
48 | server.accessToken = accessToken | ||
49 | callbackEach() | ||
50 | }) | ||
51 | }, function (err) { | ||
52 | if (err) throw err | ||
53 | |||
54 | const server1 = servers[0] | ||
55 | podsUtils.makeFriends(server1.url, server1.accessToken, done) | ||
56 | }) | ||
57 | }) | ||
58 | }) | ||
59 | |||
60 | it('Should have a correct timer', function (done) { | ||
61 | const server = servers[0] | ||
62 | |||
63 | getRequestsStats(server, function (err, res) { | ||
64 | if (err) throw err | ||
65 | |||
66 | const requestSchedulers = res.body | ||
67 | for (const requestSchedulerName of requestSchedulerNames) { | ||
68 | const requestScheduler = requestSchedulers[requestSchedulerName] | ||
69 | |||
70 | expect(requestScheduler.remainingMilliSeconds).to.be.at.least(0) | ||
71 | expect(requestScheduler.remainingMilliSeconds).to.be.at.most(10000) | ||
72 | } | ||
73 | |||
74 | done() | ||
75 | }) | ||
76 | }) | ||
77 | |||
78 | it('Should have the correct total request', function (done) { | ||
79 | this.timeout(15000) | ||
80 | |||
81 | const server = servers[0] | ||
82 | // Ensure the requests of pod 1 won't be made | ||
83 | servers[1].app.kill() | ||
84 | |||
85 | uploadVideo(server, function (err) { | ||
86 | if (err) throw err | ||
87 | |||
88 | setTimeout(function () { | ||
89 | getRequestsStats(server, function (err, res) { | ||
90 | if (err) throw err | ||
91 | |||
92 | const requestSchedulers = res.body | ||
93 | const requestScheduler = requestSchedulers.requestScheduler | ||
94 | expect(requestScheduler.totalRequests).to.equal(1) | ||
95 | |||
96 | done() | ||
97 | }) | ||
98 | }, 1000) | ||
99 | }) | ||
100 | }) | ||
101 | |||
102 | after(function (done) { | ||
103 | process.kill(-servers[0].app.pid) | ||
104 | |||
105 | if (this.ok) { | ||
106 | serversUtils.flushTests(done) | ||
107 | } else { | ||
108 | done() | ||
109 | } | ||
110 | }) | ||
111 | }) | ||