aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/videos/videos-views-cleaner.ts
blob: fbddd40f4906f1e73c52084075c5dc834fe4a466 (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* tslint:disable:no-unused-expression */

import * as chai from 'chai'
import 'mocha'
import {
  flushAndRunMultipleServers,
  flushTests,
  killallServers,
  reRunServer,
  flushAndRunServer,
  ServerInfo,
  setAccessTokensToServers,
  uploadVideo, uploadVideoAndGetId, viewVideo, wait, countVideoViewsOf, doubleFollow, waitJobs, cleanupTests, closeAllSequelize
} from '../../../../shared/extra-utils'
import { getVideosOverview } from '../../../../shared/extra-utils/overviews/overviews'
import { VideosOverview } from '../../../../shared/models/overviews'
import { listMyVideosHistory } from '../../../../shared/extra-utils/videos/video-history'

const expect = chai.expect

describe('Test video views cleaner', function () {
  let servers: ServerInfo[]

  let videoIdServer1: string
  let videoIdServer2: string

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

    servers = await flushAndRunMultipleServers(2)
    await setAccessTokensToServers(servers)

    await doubleFollow(servers[0], servers[1])

    videoIdServer1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' })).uuid
    videoIdServer2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' })).uuid

    await waitJobs(servers)

    await viewVideo(servers[0].url, videoIdServer1)
    await viewVideo(servers[1].url, videoIdServer1)
    await viewVideo(servers[0].url, videoIdServer2)
    await viewVideo(servers[1].url, videoIdServer2)

    await waitJobs(servers)
  })

  it('Should not clean old video views', async function () {
    this.timeout(50000)

    killallServers([ servers[0] ])

    await reRunServer(servers[0], { views: { videos: { remote: { max_age: '10 days' } } } })

    await wait(6000)

    // Should still have views

    {
      for (const server of servers) {
        const total = await countVideoViewsOf(server.internalServerNumber, videoIdServer1)
        expect(total).to.equal(2)
      }
    }

    {
      for (const server of servers) {
        const total = await countVideoViewsOf(server.internalServerNumber, videoIdServer2)
        expect(total).to.equal(2)
      }
    }
  })

  it('Should clean old video views', async function () {
    this.timeout(50000)

    killallServers([ servers[0] ])

    await reRunServer(servers[0], { views: { videos: { remote: { max_age: '5 seconds' } } } })

    await wait(6000)

    // Should still have views

    {
      for (const server of servers) {
        const total = await countVideoViewsOf(server.internalServerNumber, videoIdServer1)
        expect(total).to.equal(2)
      }
    }

    {
      const totalServer1 = await countVideoViewsOf(servers[0].internalServerNumber, videoIdServer2)
      expect(totalServer1).to.equal(0)

      const totalServer2 = await countVideoViewsOf(servers[1].internalServerNumber, videoIdServer2)
      expect(totalServer2).to.equal(2)
    }
  })

  after(async function () {
    await closeAllSequelize(servers)

    await cleanupTests(servers)
  })
})