aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/request-schedulers.ts
blob: 326ed3468f14921263aa1d05e1a1cc7c9a3a85a9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* tslint:disable:no-unused-expression */

import * as request from 'supertest'
import 'mocha'
import * as chai from 'chai'
const expect = chai.expect

import {
  ServerInfo,
  flushTests,
  uploadVideo,
  makeFriends,
  wait,
  setAccessTokensToServers,
  flushAndRunMultipleServers,
  getRequestsStats,
  killallServers
} from '../utils'

describe('Test requests schedulers stats', function () {
  const requestSchedulerNames = [ 'requestScheduler', 'requestVideoQaduScheduler', 'requestVideoEventScheduler' ]
  const path = '/api/v1/request-schedulers/stats'
  let servers: ServerInfo[] = []

  function uploadVideoWrapper (server: ServerInfo) {
    const videoAttributes = {
      tags: [ 'tag1', 'tag2' ]
    }

    return uploadVideo(server.url, server.accessToken, videoAttributes)
  }

  // ---------------------------------------------------------------

  before(async function () {
    this.timeout(120000)

    servers = await flushAndRunMultipleServers(2)

    await setAccessTokensToServers(servers)

    await makeFriends(servers[0].url, servers[0].accessToken)
  })

  it('Should have a correct timer', async function () {
    const server = servers[0]

    const res = await getRequestsStats(server)

    const requestSchedulers = res.body
    for (const requestSchedulerName of requestSchedulerNames) {
      const requestScheduler = requestSchedulers[requestSchedulerName]

      expect(requestScheduler.remainingMilliSeconds).to.be.at.least(0)
      expect(requestScheduler.remainingMilliSeconds).to.be.at.most(10000)
    }
  })

  it('Should have the correct total request', async function () {
    this.timeout(15000)

    const server = servers[0]
    // Ensure the requests of pod 1 won't be made
    servers[1].app.kill()

    await uploadVideoWrapper(server)

    await wait(1000)

    const res = await getRequestsStats(server)
    const requestSchedulers = res.body
    const requestScheduler = requestSchedulers.requestScheduler
    expect(requestScheduler.totalRequests).to.equal(1)
  })

  after(async function () {
    killallServers(servers)

    if (this['ok']) {
      await flushTests()
    }
  })
})