2020-01-31 09:56:52 -06:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
2019-04-11 10:33:36 -05:00
|
|
|
|
|
|
|
import 'mocha'
|
2021-07-09 08:37:43 -05:00
|
|
|
import * as chai from 'chai'
|
2019-04-11 10:33:36 -05:00
|
|
|
import {
|
2020-01-31 09:56:52 -06:00
|
|
|
cleanupTests,
|
|
|
|
doubleFollow,
|
2019-04-11 10:33:36 -05:00
|
|
|
flushAndRunMultipleServers,
|
|
|
|
killallServers,
|
|
|
|
reRunServer,
|
|
|
|
ServerInfo,
|
|
|
|
setAccessTokensToServers,
|
2020-01-31 09:56:52 -06:00
|
|
|
uploadVideoAndGetId,
|
|
|
|
viewVideo,
|
|
|
|
wait,
|
|
|
|
waitJobs
|
2019-04-15 08:26:15 -05:00
|
|
|
} from '../../../../shared/extra-utils'
|
2019-04-11 10:33:36 -05:00
|
|
|
|
|
|
|
const expect = chai.expect
|
|
|
|
|
|
|
|
describe('Test video views cleaner', function () {
|
|
|
|
let servers: ServerInfo[]
|
|
|
|
|
|
|
|
let videoIdServer1: string
|
|
|
|
let videoIdServer2: string
|
|
|
|
|
|
|
|
before(async function () {
|
2020-12-11 03:36:05 -06:00
|
|
|
this.timeout(120000)
|
2019-04-11 10:33:36 -05:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2021-07-09 08:37:43 -05:00
|
|
|
await killallServers([ servers[0] ])
|
2019-04-11 10:33:36 -05:00
|
|
|
|
|
|
|
await reRunServer(servers[0], { views: { videos: { remote: { max_age: '10 days' } } } })
|
|
|
|
|
|
|
|
await wait(6000)
|
|
|
|
|
|
|
|
// Should still have views
|
|
|
|
|
|
|
|
{
|
|
|
|
for (const server of servers) {
|
2021-07-09 08:37:43 -05:00
|
|
|
const total = await server.sqlCommand.countVideoViewsOf(videoIdServer1)
|
2020-11-06 09:43:43 -06:00
|
|
|
expect(total).to.equal(2, 'Server ' + server.serverNumber + ' does not have the correct amount of views')
|
2019-04-11 10:33:36 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
for (const server of servers) {
|
2021-07-09 08:37:43 -05:00
|
|
|
const total = await server.sqlCommand.countVideoViewsOf(videoIdServer2)
|
2020-11-06 09:43:43 -06:00
|
|
|
expect(total).to.equal(2, 'Server ' + server.serverNumber + ' does not have the correct amount of views')
|
2019-04-11 10:33:36 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should clean old video views', async function () {
|
|
|
|
this.timeout(50000)
|
|
|
|
|
2021-07-09 08:37:43 -05:00
|
|
|
await killallServers([ servers[0] ])
|
2019-04-11 10:33:36 -05:00
|
|
|
|
|
|
|
await reRunServer(servers[0], { views: { videos: { remote: { max_age: '5 seconds' } } } })
|
|
|
|
|
|
|
|
await wait(6000)
|
|
|
|
|
|
|
|
// Should still have views
|
|
|
|
|
|
|
|
{
|
|
|
|
for (const server of servers) {
|
2021-07-09 08:37:43 -05:00
|
|
|
const total = await server.sqlCommand.countVideoViewsOf(videoIdServer1)
|
2019-04-11 10:33:36 -05:00
|
|
|
expect(total).to.equal(2)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-07-09 08:37:43 -05:00
|
|
|
const totalServer1 = await servers[0].sqlCommand.countVideoViewsOf(videoIdServer2)
|
2019-04-11 10:33:36 -05:00
|
|
|
expect(totalServer1).to.equal(0)
|
|
|
|
|
2021-07-09 08:37:43 -05:00
|
|
|
const totalServer2 = await servers[1].sqlCommand.countVideoViewsOf(videoIdServer2)
|
2019-04-11 10:33:36 -05:00
|
|
|
expect(totalServer2).to.equal(2)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-04-24 08:10:37 -05:00
|
|
|
after(async function () {
|
|
|
|
await cleanupTests(servers)
|
2019-04-11 10:33:36 -05:00
|
|
|
})
|
|
|
|
})
|