aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/request-schedulers.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-06-25 17:19:46 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-06-25 17:19:46 +0200
commite636eb88101a51399057c86477af6677f5614d48 (patch)
treeba56f0da932613c8013a2c52905ded1987cd6d6d /server/tests/api/request-schedulers.js
parent4f133041819409a72cf70fa2fa6c4df14c6de4fd (diff)
downloadPeerTube-e636eb88101a51399057c86477af6677f5614d48.tar.gz
PeerTube-e636eb88101a51399057c86477af6677f5614d48.tar.zst
PeerTube-e636eb88101a51399057c86477af6677f5614d48.zip
Requests -> RequestSchedulers
Diffstat (limited to 'server/tests/api/request-schedulers.js')
-rw-r--r--server/tests/api/request-schedulers.js111
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
5const chai = require('chai')
6const each = require('async/each')
7const expect = chai.expect
8const request = require('supertest')
9
10const loginUtils = require('../utils/login')
11const podsUtils = require('../utils/pods')
12const serversUtils = require('../utils/servers')
13const videosUtils = require('../utils/videos')
14
15describe('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})