aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/activitypub/refresher.ts
blob: 67e04f79eaf5b7719ef86401a633b86613cab9c5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* tslint:disable:no-unused-expression */

import 'mocha'
import { doubleFollow, getVideo, reRunServer } from '../../utils'
import { flushAndRunMultipleServers, killallServers, ServerInfo, setAccessTokensToServers, uploadVideo, wait } from '../../utils/index'
import { waitJobs } from '../../utils/server/jobs'
import { setVideoField } from '../../utils/miscs/sql'

describe('Test AP refresher', function () {
  let servers: ServerInfo[] = []
  let videoUUID1: string
  let videoUUID2: string
  let videoUUID3: string

  before(async function () {
    this.timeout(30000)

    servers = await flushAndRunMultipleServers(2)

    // Get the access tokens
    await setAccessTokensToServers(servers)

    {
      const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video1' })
      videoUUID1 = res.body.video.uuid
    }

    {
      const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video2' })
      videoUUID2 = res.body.video.uuid
    }

    {
      const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video3' })
      videoUUID3 = res.body.video.uuid
    }

    await doubleFollow(servers[0], servers[1])
  })

  it('Should remove a deleted remote video', async function () {
    this.timeout(60000)

    await wait(10000)

    // Change UUID so the remote server returns a 404
    await setVideoField(2, videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f')

    await getVideo(servers[0].url, videoUUID1)
    await getVideo(servers[0].url, videoUUID2)

    await waitJobs(servers)

    await getVideo(servers[0].url, videoUUID1, 404)
    await getVideo(servers[0].url, videoUUID2, 200)
  })

  it('Should not update a remote video if the remote instance is down', async function () {
    this.timeout(60000)

    killallServers([ servers[1] ])

    await setVideoField(2, videoUUID3, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174e')

    // Video will need a refresh
    await wait(10000)

    await getVideo(servers[0].url, videoUUID3)
    // The refresh should fail
    await waitJobs([ servers[0] ])

    await reRunServer(servers[1])

    // Should not refresh the video, even if the last refresh failed (to avoir a loop on dead instances)
    await getVideo(servers[0].url, videoUUID3)
    await waitJobs(servers)

    await getVideo(servers[0].url, videoUUID3, 200)
  })

  after(async function () {
    killallServers(servers)
  })
})