/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
-import 'mocha'
-import * as chai from 'chai'
+import { expect } from 'chai'
+import { wait } from '@shared/core-utils'
import {
cleanupTests,
- doubleFollow,
createMultipleServers,
+ doubleFollow,
PeerTubeServer,
setAccessTokensToServers,
- wait,
waitJobs
-} from '@shared/extra-utils'
-
-const expect = chai.expect
+} from '@shared/server-commands'
describe('Test AP cleaner', function () {
let servers: PeerTubeServer[] = []
it('Should destroy server 3 internal shares and correctly clean them', async function () {
this.timeout(20000)
- const preCount = await servers[0].sql.getCount('videoShare')
+ const preCount = await servers[0].sql.getVideoShareCount()
expect(preCount).to.equal(6)
await servers[2].sql.deleteAll('videoShare')
await waitJobs(servers)
// Still 6 because we don't have remote shares on local videos
- const postCount = await servers[0].sql.getCount('videoShare')
+ const postCount = await servers[0].sql.getVideoShareCount()
expect(postCount).to.equal(6)
})
async function check (like: string, ofServerUrl: string, urlSuffix: string, remote: 'true' | 'false') {
const query = `SELECT "videoId", "accountVideoRate".url FROM "accountVideoRate" ` +
`INNER JOIN video ON "accountVideoRate"."videoId" = video.id AND remote IS ${remote} WHERE "accountVideoRate"."url" LIKE '${like}'`
- const res = await servers[0].sql.selectQuery(query)
+ const res = await servers[0].sql.selectQuery<{ url: string }>(query)
for (const rate of res) {
const matcher = new RegExp(`^${ofServerUrl}/accounts/root/dislikes/\\d+${urlSuffix}$`)
const query = `SELECT "videoId", "videoComment".url, uuid as "videoUUID" FROM "videoComment" ` +
`INNER JOIN video ON "videoComment"."videoId" = video.id AND remote IS ${remote} WHERE "videoComment"."url" LIKE '${like}'`
- const res = await servers[0].sql.selectQuery(query)
+ const res = await servers[0].sql.selectQuery<{ url: string, videoUUID: string }>(query)
for (const comment of res) {
const matcher = new RegExp(`${ofServerUrl}/videos/watch/${comment.videoUUID}/comments/\\d+${urlSuffix}`)
await checkRemote('kyle')
})
+ it('Should remove unavailable remote resources', async function () {
+ this.timeout(240000)
+
+ async function expectNotDeleted () {
+ {
+ const video = await servers[0].videos.get({ id: uuid })
+
+ expect(video.likes).to.equal(3)
+ expect(video.dislikes).to.equal(0)
+ }
+
+ {
+ const { total } = await servers[0].comments.listThreads({ videoId: uuid })
+ expect(total).to.equal(3)
+ }
+ }
+
+ async function expectDeleted () {
+ {
+ const video = await servers[0].videos.get({ id: uuid })
+
+ expect(video.likes).to.equal(2)
+ expect(video.dislikes).to.equal(0)
+ }
+
+ {
+ const { total } = await servers[0].comments.listThreads({ videoId: uuid })
+ expect(total).to.equal(2)
+ }
+ }
+
+ const uuid = (await servers[0].videos.quickUpload({ name: 'server 1 video 2' })).uuid
+
+ await waitJobs(servers)
+
+ for (const server of servers) {
+ await server.videos.rate({ id: uuid, rating: 'like' })
+ await server.comments.createThread({ videoId: uuid, text: 'comment' })
+ }
+
+ await waitJobs(servers)
+
+ await expectNotDeleted()
+
+ await servers[1].kill()
+
+ await wait(5000)
+ await expectNotDeleted()
+
+ let continueWhile = true
+
+ do {
+ try {
+ await expectDeleted()
+ continueWhile = false
+ } catch {
+ }
+ } while (continueWhile)
+ })
+
after(async function () {
await cleanupTests(servers)
})