]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/server/slow-follows.ts
a967fa724e895a0e8ed0689abaa41bb331fbf1f8
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / slow-follows.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import { expect } from 'chai'
4 import { Job } from '@shared/models'
5 import {
6 cleanupTests,
7 createMultipleServers,
8 doubleFollow,
9 PeerTubeServer,
10 setAccessTokensToServers,
11 waitJobs
12 } from '@shared/server-commands'
13
14 describe('Test slow follows', function () {
15 let servers: PeerTubeServer[] = []
16
17 let afterFollows: Date
18
19 before(async function () {
20 this.timeout(120000)
21
22 servers = await createMultipleServers(3)
23
24 // Get the access tokens
25 await setAccessTokensToServers(servers)
26
27 await doubleFollow(servers[0], servers[1])
28 await doubleFollow(servers[0], servers[2])
29
30 afterFollows = new Date()
31
32 for (let i = 0; i < 5; i++) {
33 await servers[0].videos.quickUpload({ name: 'video ' + i })
34 }
35
36 await waitJobs(servers)
37 })
38
39 it('Should only have broadcast jobs', async function () {
40 const { data } = await servers[0].jobs.list({ jobType: 'activitypub-http-unicast', sort: '-createdAt' })
41
42 for (const job of data) {
43 expect(new Date(job.createdAt)).below(afterFollows)
44 }
45 })
46
47 it('Should process bad follower', async function () {
48 this.timeout(30000)
49
50 await servers[1].kill()
51
52 // Set server 2 as bad follower
53 await servers[0].videos.quickUpload({ name: 'video 6' })
54 await waitJobs(servers[0])
55
56 afterFollows = new Date()
57 const filter = (job: Job) => new Date(job.createdAt) > afterFollows
58
59 // Resend another broadcast job
60 await servers[0].videos.quickUpload({ name: 'video 7' })
61 await waitJobs(servers[0])
62
63 const resBroadcast = await servers[0].jobs.list({ jobType: 'activitypub-http-broadcast', sort: '-createdAt' })
64 const resUnicast = await servers[0].jobs.list({ jobType: 'activitypub-http-unicast', sort: '-createdAt' })
65
66 const broadcast = resBroadcast.data.filter(filter)
67 const unicast = resUnicast.data.filter(filter)
68
69 expect(unicast).to.have.lengthOf(2)
70 expect(broadcast).to.have.lengthOf(2)
71
72 for (const u of unicast) {
73 expect(u.data.uri).to.equal(servers[1].url + '/inbox')
74 }
75
76 for (const b of broadcast) {
77 expect(b.data.uris).to.have.lengthOf(1)
78 expect(b.data.uris[0]).to.equal(servers[2].url + '/inbox')
79 }
80 })
81
82 after(async function () {
83 await cleanupTests(servers)
84 })
85 })