mirror of https://github.com/Chocobozzz/PeerTube
Fix tests
parent
f1569117f9
commit
10a72a7e61
|
@ -14,29 +14,27 @@ import { VideoModel } from '@server/models/video/video'
|
||||||
import { VideoCommentModel } from '@server/models/video/video-comment'
|
import { VideoCommentModel } from '@server/models/video/video-comment'
|
||||||
import { VideoShareModel } from '@server/models/video/video-share'
|
import { VideoShareModel } from '@server/models/video/video-share'
|
||||||
import { HttpStatusCode } from '@shared/models'
|
import { HttpStatusCode } from '@shared/models'
|
||||||
import { logger } from '../../../helpers/logger'
|
import { logger, loggerTagsFactory } from '../../../helpers/logger'
|
||||||
import { AccountVideoRateModel } from '../../../models/account/account-video-rate'
|
import { AccountVideoRateModel } from '../../../models/account/account-video-rate'
|
||||||
|
|
||||||
|
const lTags = loggerTagsFactory('ap-cleaner')
|
||||||
|
|
||||||
// Job to clean remote interactions off local videos
|
// Job to clean remote interactions off local videos
|
||||||
|
|
||||||
async function processActivityPubCleaner (_job: Job) {
|
async function processActivityPubCleaner (_job: Job) {
|
||||||
logger.info('Processing ActivityPub cleaner.')
|
logger.info('Processing ActivityPub cleaner.', lTags())
|
||||||
|
|
||||||
{
|
{
|
||||||
const rateUrls = await AccountVideoRateModel.listRemoteRateUrlsOfLocalVideos()
|
const rateUrls = await AccountVideoRateModel.listRemoteRateUrlsOfLocalVideos()
|
||||||
const { bodyValidator, deleter, updater } = rateOptionsFactory()
|
const { bodyValidator, deleter, updater } = rateOptionsFactory()
|
||||||
|
|
||||||
await map(rateUrls, async rateUrl => {
|
await map(rateUrls, async rateUrl => {
|
||||||
try {
|
const result = await updateObjectIfNeeded({ url: rateUrl, bodyValidator, updater, deleter })
|
||||||
const result = await updateObjectIfNeeded({ url: rateUrl, bodyValidator, updater, deleter })
|
|
||||||
|
|
||||||
if (result?.status === 'deleted') {
|
if (result?.status === 'deleted') {
|
||||||
const { videoId, type } = result.data
|
const { videoId, type } = result.data
|
||||||
|
|
||||||
await VideoModel.updateRatesOf(videoId, type, undefined)
|
await VideoModel.updateRatesOf(videoId, type, undefined)
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
logger.warn('Cannot update/delete remote AP rate %s.', rateUrl, { err })
|
|
||||||
}
|
}
|
||||||
}, { concurrency: AP_CLEANER.CONCURRENCY })
|
}, { concurrency: AP_CLEANER.CONCURRENCY })
|
||||||
}
|
}
|
||||||
|
@ -46,11 +44,7 @@ async function processActivityPubCleaner (_job: Job) {
|
||||||
const { bodyValidator, deleter, updater } = shareOptionsFactory()
|
const { bodyValidator, deleter, updater } = shareOptionsFactory()
|
||||||
|
|
||||||
await map(shareUrls, async shareUrl => {
|
await map(shareUrls, async shareUrl => {
|
||||||
try {
|
await updateObjectIfNeeded({ url: shareUrl, bodyValidator, updater, deleter })
|
||||||
await updateObjectIfNeeded({ url: shareUrl, bodyValidator, updater, deleter })
|
|
||||||
} catch (err) {
|
|
||||||
logger.warn('Cannot update/delete remote AP share %s.', shareUrl, { err })
|
|
||||||
}
|
|
||||||
}, { concurrency: AP_CLEANER.CONCURRENCY })
|
}, { concurrency: AP_CLEANER.CONCURRENCY })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,11 +53,7 @@ async function processActivityPubCleaner (_job: Job) {
|
||||||
const { bodyValidator, deleter, updater } = commentOptionsFactory()
|
const { bodyValidator, deleter, updater } = commentOptionsFactory()
|
||||||
|
|
||||||
await map(commentUrls, async commentUrl => {
|
await map(commentUrls, async commentUrl => {
|
||||||
try {
|
await updateObjectIfNeeded({ url: commentUrl, bodyValidator, updater, deleter })
|
||||||
await updateObjectIfNeeded({ url: commentUrl, bodyValidator, updater, deleter })
|
|
||||||
} catch (err) {
|
|
||||||
logger.warn('Cannot update/delete remote AP comment %s.', commentUrl, { err })
|
|
||||||
}
|
|
||||||
}, { concurrency: AP_CLEANER.CONCURRENCY })
|
}, { concurrency: AP_CLEANER.CONCURRENCY })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -85,7 +75,7 @@ async function updateObjectIfNeeded <T> (options: {
|
||||||
const { url, bodyValidator, updater, deleter } = options
|
const { url, bodyValidator, updater, deleter } = options
|
||||||
|
|
||||||
const on404OrTombstone = async () => {
|
const on404OrTombstone = async () => {
|
||||||
logger.info('Removing remote AP object %s.', url)
|
logger.info('Removing remote AP object %s.', url, lTags(url))
|
||||||
const data = await deleter(url)
|
const data = await deleter(url)
|
||||||
|
|
||||||
return { status: 'deleted' as 'deleted', data }
|
return { status: 'deleted' as 'deleted', data }
|
||||||
|
@ -107,7 +97,7 @@ async function updateObjectIfNeeded <T> (options: {
|
||||||
throw new Error(`New url ${newUrl} has not the same host than old url ${url}`)
|
throw new Error(`New url ${newUrl} has not the same host than old url ${url}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info('Updating remote AP object %s.', url)
|
logger.info('Updating remote AP object %s.', url, lTags(url))
|
||||||
const data = await updater(url, newUrl)
|
const data = await updater(url, newUrl)
|
||||||
|
|
||||||
return { status: 'updated', data }
|
return { status: 'updated', data }
|
||||||
|
@ -120,11 +110,11 @@ async function updateObjectIfNeeded <T> (options: {
|
||||||
return on404OrTombstone()
|
return on404OrTombstone()
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug('Remote AP object %s is unavailable.', url)
|
logger.debug('Remote AP object %s is unavailable.', url, lTags(url))
|
||||||
|
|
||||||
const unavailability = await Redis.Instance.addAPUnavailability(url)
|
const unavailability = await Redis.Instance.addAPUnavailability(url)
|
||||||
if (unavailability >= AP_CLEANER.UNAVAILABLE_TRESHOLD) {
|
if (unavailability >= AP_CLEANER.UNAVAILABLE_TRESHOLD) {
|
||||||
logger.info('Removing unavailable AP resource %s.', url)
|
logger.info('Removing unavailable AP resource %s.', url, lTags(url))
|
||||||
return on404OrTombstone()
|
return on404OrTombstone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -291,12 +291,12 @@ describe('Test AP cleaner', function () {
|
||||||
{
|
{
|
||||||
const video = await servers[0].videos.get({ id: uuid })
|
const video = await servers[0].videos.get({ id: uuid })
|
||||||
|
|
||||||
expect(video.likes).to.equal(3)
|
expect(video.likes).to.equal(2)
|
||||||
expect(video.dislikes).to.equal(0)
|
expect(video.dislikes).to.equal(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const { total } = await servers[0].comments.listThreads({ videoId: videoUUID1 })
|
const { total } = await servers[0].comments.listThreads({ videoId: uuid })
|
||||||
expect(total).to.equal(2)
|
expect(total).to.equal(2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -319,8 +319,15 @@ describe('Test AP cleaner', function () {
|
||||||
await wait(5000)
|
await wait(5000)
|
||||||
await expectNotDeleted()
|
await expectNotDeleted()
|
||||||
|
|
||||||
await wait(15000)
|
let continueWhile = true
|
||||||
await expectDeleted()
|
|
||||||
|
do {
|
||||||
|
try {
|
||||||
|
await expectDeleted()
|
||||||
|
continueWhile = false
|
||||||
|
} catch {
|
||||||
|
}
|
||||||
|
} while (continueWhile)
|
||||||
})
|
})
|
||||||
|
|
||||||
after(async function () {
|
after(async function () {
|
||||||
|
|
|
@ -50,7 +50,7 @@ describe('Test handle downs', function () {
|
||||||
let commentCommands: CommentsCommand[]
|
let commentCommands: CommentsCommand[]
|
||||||
|
|
||||||
before(async function () {
|
before(async function () {
|
||||||
this.timeout(30000)
|
this.timeout(120000)
|
||||||
|
|
||||||
servers = await createMultipleServers(3)
|
servers = await createMultipleServers(3)
|
||||||
commentCommands = servers.map(s => s.comments)
|
commentCommands = servers.map(s => s.comments)
|
||||||
|
|
Loading…
Reference in New Issue