]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/activitypub/cleaner.ts
Increase test timeout
[github/Chocobozzz/PeerTube.git] / server / tests / api / activitypub / cleaner.ts
index 1421824dad8e308e954137a421bc6722a49081fb..d0a151f5c9af88d3087b0cc0b19f13a656fefdd8 100644 (file)
@@ -2,20 +2,20 @@
 
 import 'mocha'
 import * as chai from 'chai'
+import { wait } from '@shared/core-utils'
 import {
   cleanupTests,
+  createMultipleServers,
   doubleFollow,
-  flushAndRunMultipleServers,
-  ServerInfo,
+  PeerTubeServer,
   setAccessTokensToServers,
-  wait,
   waitJobs
-} from '@shared/extra-utils'
+} from '@shared/server-commands'
 
 const expect = chai.expect
 
 describe('Test AP cleaner', function () {
-  let servers: ServerInfo[] = []
+  let servers: PeerTubeServer[] = []
   let videoUUID1: string
   let videoUUID2: string
   let videoUUID3: string
@@ -30,7 +30,7 @@ describe('Test AP cleaner', function () {
         videos: { cleanup_remote_interactions: true }
       }
     }
-    servers = await flushAndRunMultipleServers(3, config)
+    servers = await createMultipleServers(3, config)
 
     // Get the access tokens
     await setAccessTokensToServers(servers)
@@ -270,6 +270,66 @@ describe('Test AP cleaner', function () {
     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)
   })