2020-01-31 10:56:52 -05:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
2019-04-11 11:33:36 -04:00
|
|
|
|
2022-08-17 09:44:32 -04:00
|
|
|
import { expect } from 'chai'
|
2021-12-17 05:58:15 -05:00
|
|
|
import { wait } from '@shared/core-utils'
|
2019-04-11 11:33:36 -04:00
|
|
|
import {
|
2020-01-31 10:56:52 -05:00
|
|
|
cleanupTests,
|
2021-07-16 03:47:51 -04:00
|
|
|
createMultipleServers,
|
2021-07-16 08:27:30 -04:00
|
|
|
doubleFollow,
|
2019-04-11 11:33:36 -04:00
|
|
|
killallServers,
|
2021-07-16 03:47:51 -04:00
|
|
|
PeerTubeServer,
|
2019-04-11 11:33:36 -04:00
|
|
|
setAccessTokensToServers,
|
2020-01-31 10:56:52 -05:00
|
|
|
waitJobs
|
2021-12-17 05:58:15 -05:00
|
|
|
} from '@shared/server-commands'
|
2019-04-11 11:33:36 -04:00
|
|
|
|
|
|
|
describe('Test video views cleaner', function () {
|
2021-07-16 03:47:51 -04:00
|
|
|
let servers: PeerTubeServer[]
|
2019-04-11 11:33:36 -04:00
|
|
|
|
|
|
|
let videoIdServer1: string
|
|
|
|
let videoIdServer2: string
|
|
|
|
|
|
|
|
before(async function () {
|
2020-12-11 04:36:05 -05:00
|
|
|
this.timeout(120000)
|
2019-04-11 11:33:36 -04:00
|
|
|
|
2021-07-16 03:47:51 -04:00
|
|
|
servers = await createMultipleServers(2)
|
2019-04-11 11:33:36 -04:00
|
|
|
await setAccessTokensToServers(servers)
|
|
|
|
|
|
|
|
await doubleFollow(servers[0], servers[1])
|
|
|
|
|
2021-07-16 03:04:35 -04:00
|
|
|
videoIdServer1 = (await servers[0].videos.quickUpload({ name: 'video server 1' })).uuid
|
|
|
|
videoIdServer2 = (await servers[1].videos.quickUpload({ name: 'video server 2' })).uuid
|
2019-04-11 11:33:36 -04:00
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
2022-03-24 08:36:47 -04:00
|
|
|
await servers[0].views.simulateView({ id: videoIdServer1 })
|
|
|
|
await servers[1].views.simulateView({ id: videoIdServer1 })
|
|
|
|
await servers[0].views.simulateView({ id: videoIdServer2 })
|
|
|
|
await servers[1].views.simulateView({ id: videoIdServer2 })
|
2019-04-11 11:33:36 -04:00
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not clean old video views', async function () {
|
|
|
|
this.timeout(50000)
|
|
|
|
|
2021-07-09 09:37:43 -04:00
|
|
|
await killallServers([ servers[0] ])
|
2019-04-11 11:33:36 -04:00
|
|
|
|
2021-07-16 03:47:51 -04:00
|
|
|
await servers[0].run({ views: { videos: { remote: { max_age: '10 days' } } } })
|
2019-04-11 11:33:36 -04:00
|
|
|
|
|
|
|
await wait(6000)
|
|
|
|
|
|
|
|
// Should still have views
|
|
|
|
|
|
|
|
{
|
|
|
|
for (const server of servers) {
|
2021-07-16 03:04:35 -04:00
|
|
|
const total = await server.sql.countVideoViewsOf(videoIdServer1)
|
2020-11-06 10:43:43 -05:00
|
|
|
expect(total).to.equal(2, 'Server ' + server.serverNumber + ' does not have the correct amount of views')
|
2019-04-11 11:33:36 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
for (const server of servers) {
|
2021-07-16 03:04:35 -04:00
|
|
|
const total = await server.sql.countVideoViewsOf(videoIdServer2)
|
2020-11-06 10:43:43 -05:00
|
|
|
expect(total).to.equal(2, 'Server ' + server.serverNumber + ' does not have the correct amount of views')
|
2019-04-11 11:33:36 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should clean old video views', async function () {
|
|
|
|
this.timeout(50000)
|
|
|
|
|
2021-07-09 09:37:43 -04:00
|
|
|
await killallServers([ servers[0] ])
|
2019-04-11 11:33:36 -04:00
|
|
|
|
2021-07-16 03:47:51 -04:00
|
|
|
await servers[0].run({ views: { videos: { remote: { max_age: '5 seconds' } } } })
|
2019-04-11 11:33:36 -04:00
|
|
|
|
|
|
|
await wait(6000)
|
|
|
|
|
|
|
|
// Should still have views
|
|
|
|
|
|
|
|
{
|
|
|
|
for (const server of servers) {
|
2021-07-16 03:04:35 -04:00
|
|
|
const total = await server.sql.countVideoViewsOf(videoIdServer1)
|
2019-04-11 11:33:36 -04:00
|
|
|
expect(total).to.equal(2)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-07-16 03:04:35 -04:00
|
|
|
const totalServer1 = await servers[0].sql.countVideoViewsOf(videoIdServer2)
|
2019-04-11 11:33:36 -04:00
|
|
|
expect(totalServer1).to.equal(0)
|
|
|
|
|
2021-07-16 03:04:35 -04:00
|
|
|
const totalServer2 = await servers[1].sql.countVideoViewsOf(videoIdServer2)
|
2019-04-11 11:33:36 -04:00
|
|
|
expect(totalServer2).to.equal(2)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-04-24 09:10:37 -04:00
|
|
|
after(async function () {
|
|
|
|
await cleanupTests(servers)
|
2019-04-11 11:33:36 -04:00
|
|
|
})
|
|
|
|
})
|