]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/server/handle-down.ts
Support short uuid for GET video/playlist
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / handle-down.ts
index 0421b2b40eeeeeec281b52b9f5ded9b908fcdaac..d57d72f5e4763ee50516df698b1ef759f8286f0d 100644 (file)
@@ -1,28 +1,39 @@
-/* tslint:disable:no-unused-expression */
+/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
 import * as chai from 'chai'
 import 'mocha'
 import { JobState, Video } from '../../../../shared/models'
 import { VideoPrivacy } from '../../../../shared/models/videos'
-import { VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model'
-import { completeVideoCheck, getVideo, immutableAssign, reRunServer, unfollow, updateVideo, viewVideo } from '../../utils'
+import { VideoCommentThreadTree } from '../../../../shared/models/videos/comment/video-comment.model'
+
 import {
+  cleanupTests,
+  closeAllSequelize,
+  completeVideoCheck,
   flushAndRunMultipleServers,
+  getVideo,
   getVideosList,
+  immutableAssign,
   killallServers,
+  reRunServer,
   ServerInfo,
   setAccessTokensToServers,
+  setActorFollowScores,
+  unfollow,
+  updateVideo,
   uploadVideo,
+  uploadVideoAndGetId,
   wait
-} from '../../utils/index'
-import { follow, getFollowersListPaginationAndSort } from '../../utils/server/follows'
-import { getJobsListPaginationAndSort, waitJobs } from '../../utils/server/jobs'
+} from '../../../../shared/extra-utils'
+import { follow, getFollowersListPaginationAndSort } from '../../../../shared/extra-utils/server/follows'
+import { getJobsListPaginationAndSort, waitJobs } from '../../../../shared/extra-utils/server/jobs'
 import {
   addVideoCommentReply,
   addVideoCommentThread,
   getVideoCommentThreads,
   getVideoThreadComments
-} from '../../utils/videos/video-comments'
+} from '../../../../shared/extra-utils/videos/video-comments'
+import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
 
 const expect = chai.expect
 
@@ -36,6 +47,8 @@ describe('Test handle downs', function () {
   let missedVideo2: Video
   let unlistedVideo: Video
 
+  const videoIdsServer1: string[] = []
+
   const videoAttributes = {
     name: 'my super name for server 1',
     category: 5,
@@ -53,53 +66,56 @@ describe('Test handle downs', function () {
     privacy: VideoPrivacy.UNLISTED
   })
 
-  const checkAttributes = {
-    name: 'my super name for server 1',
-    category: 5,
-    licence: 4,
-    language: 'ja',
-    nsfw: true,
-    description: 'my super description for server 1',
-    support: 'my super support text for server 1',
-    account: {
-      name: 'root',
-      host: 'localhost:9001'
-    },
-    isLocal: false,
-    duration: 10,
-    tags: [ 'tag1p1', 'tag2p1' ],
-    privacy: VideoPrivacy.PUBLIC,
-    commentsEnabled: true,
-    channel: {
-      name: 'root_channel',
-      displayName: 'Main root channel',
-      description: '',
-      isLocal: false
-    },
-    fixture: 'video_short1.webm',
-    files: [
-      {
-        resolution: 720,
-        size: 572456
-      }
-    ]
-  }
-
-  const unlistedCheckAttributes = immutableAssign(checkAttributes, {
-    privacy: VideoPrivacy.UNLISTED
-  })
+  let checkAttributes: any
+  let unlistedCheckAttributes: any
 
   before(async function () {
     this.timeout(30000)
 
     servers = await flushAndRunMultipleServers(3)
 
+    checkAttributes = {
+      name: 'my super name for server 1',
+      category: 5,
+      licence: 4,
+      language: 'ja',
+      nsfw: true,
+      description: 'my super description for server 1',
+      support: 'my super support text for server 1',
+      account: {
+        name: 'root',
+        host: 'localhost:' + servers[0].port
+      },
+      isLocal: false,
+      duration: 10,
+      tags: [ 'tag1p1', 'tag2p1' ],
+      privacy: VideoPrivacy.PUBLIC,
+      commentsEnabled: true,
+      downloadEnabled: true,
+      channel: {
+        name: 'root_channel',
+        displayName: 'Main root channel',
+        description: '',
+        isLocal: false
+      },
+      fixture: 'video_short1.webm',
+      files: [
+        {
+          resolution: 720,
+          size: 572456
+        }
+      ]
+    }
+    unlistedCheckAttributes = immutableAssign(checkAttributes, {
+      privacy: VideoPrivacy.UNLISTED
+    })
+
     // Get the access tokens
     await setAccessTokensToServers(servers)
   })
 
   it('Should remove followers that are often down', async function () {
-    this.timeout(60000)
+    this.timeout(240000)
 
     // Server 2 and 3 follow server 1
     await follow(servers[1].url, [ servers[0].url ], servers[1].accessToken)
@@ -124,22 +140,22 @@ describe('Test handle downs', function () {
 
     // Remove server 2 follower
     for (let i = 0; i < 10; i++) {
-      await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, videoAttributes)
+      await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
     }
 
-    await waitJobs(servers[0])
+    await waitJobs([ servers[0], servers[2] ])
 
     // Kill server 3
     killallServers([ servers[2] ])
 
-    const resLastVideo1 = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, videoAttributes)
+    const resLastVideo1 = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
     missedVideo1 = resLastVideo1.body.video
 
-    const resLastVideo2 = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, videoAttributes)
+    const resLastVideo2 = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
     missedVideo2 = resLastVideo2.body.video
 
     // Unlisted video
-    let resVideo = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, unlistedVideoAttributes)
+    const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, unlistedVideoAttributes)
     unlistedVideo = resVideo.body.video
 
     // Add comments to video 2
@@ -161,17 +177,24 @@ describe('Test handle downs', function () {
     await wait(11000)
 
     // Only server 3 is still a follower of server 1
-    const res = await getFollowersListPaginationAndSort(servers[0].url, 0, 2, 'createdAt')
+    const res = await getFollowersListPaginationAndSort({ url: servers[0].url, start: 0, count: 2, sort: 'createdAt' })
     expect(res.body.data).to.be.an('array')
     expect(res.body.data).to.have.lengthOf(1)
-    expect(res.body.data[0].follower.host).to.equal('localhost:9003')
+    expect(res.body.data[0].follower.host).to.equal('localhost:' + servers[2].port)
   })
 
   it('Should not have pending/processing jobs anymore', async function () {
     const states: JobState[] = [ 'waiting', 'active' ]
 
     for (const state of states) {
-      const res = await getJobsListPaginationAndSort(servers[ 0 ].url, servers[ 0 ].accessToken, state,0, 50, '-createdAt')
+      const res = await getJobsListPaginationAndSort({
+        url: servers[0].url,
+        accessToken: servers[0].accessToken,
+        state: state,
+        start: 0,
+        count: 50,
+        sort: '-createdAt'
+      })
       expect(res.body.data).to.have.length(0)
     }
   })
@@ -189,7 +212,7 @@ describe('Test handle downs', function () {
 
     await waitJobs(servers)
 
-    const res = await getFollowersListPaginationAndSort(servers[0].url, 0, 2, 'createdAt')
+    const res = await getFollowersListPaginationAndSort({ url: servers[0].url, start: 0, count: 2, sort: 'createdAt' })
     expect(res.body.data).to.be.an('array')
     expect(res.body.data).to.have.lengthOf(2)
   })
@@ -201,8 +224,8 @@ describe('Test handle downs', function () {
     expect(res1.body.data).to.be.an('array')
     expect(res1.body.data).to.have.lengthOf(11)
 
-    await updateVideo(servers[0].url, servers[0].accessToken, missedVideo1.uuid, { })
-    await updateVideo(servers[0].url, servers[0].accessToken, unlistedVideo.uuid, { })
+    await updateVideo(servers[0].url, servers[0].accessToken, missedVideo1.uuid, {})
+    await updateVideo(servers[0].url, servers[0].accessToken, unlistedVideo.uuid, {})
 
     await waitJobs(servers)
 
@@ -289,7 +312,56 @@ describe('Test handle downs', function () {
     }
   })
 
+  it('Should upload many videos on server 1', async function () {
+    this.timeout(120000)
+
+    for (let i = 0; i < 10; i++) {
+      const uuid = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video ' + i })).uuid
+      videoIdsServer1.push(uuid)
+    }
+
+    await waitJobs(servers)
+
+    for (const id of videoIdsServer1) {
+      await getVideo(servers[1].url, id)
+    }
+
+    await waitJobs(servers)
+    await setActorFollowScores(servers[1].internalServerNumber, 20)
+
+    // Wait video expiration
+    await wait(11000)
+
+    // Refresh video -> score + 10 = 30
+    await getVideo(servers[1].url, videoIdsServer1[0])
+
+    await waitJobs(servers)
+  })
+
+  it('Should remove followings that are down', async function () {
+    this.timeout(120000)
+
+    killallServers([ servers[0] ])
+
+    // Wait video expiration
+    await wait(11000)
+
+    for (let i = 0; i < 5; i++) {
+      try {
+        await getVideo(servers[1].url, videoIdsServer1[i])
+        await waitJobs([ servers[1] ])
+        await wait(1500)
+      } catch {}
+    }
+
+    for (const id of videoIdsServer1) {
+      await getVideo(servers[1].url, id, HttpStatusCode.FORBIDDEN_403)
+    }
+  })
+
   after(async function () {
-    killallServers(servers)
+    await closeAllSequelize([ servers[1] ])
+
+    await cleanupTests(servers)
   })
 })