aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/server/index.ts1
-rw-r--r--server/tests/api/server/slow-follows.ts81
2 files changed, 82 insertions, 0 deletions
diff --git a/server/tests/api/server/index.ts b/server/tests/api/server/index.ts
index b16a22ee7..8136fc3c6 100644
--- a/server/tests/api/server/index.ts
+++ b/server/tests/api/server/index.ts
@@ -11,6 +11,7 @@ import './jobs'
11import './logs' 11import './logs'
12import './reverse-proxy' 12import './reverse-proxy'
13import './services' 13import './services'
14import './slow-follows'
14import './stats' 15import './stats'
15import './tracker' 16import './tracker'
16import './no-client' 17import './no-client'
diff --git a/server/tests/api/server/slow-follows.ts b/server/tests/api/server/slow-follows.ts
new file mode 100644
index 000000000..2bef0c9f2
--- /dev/null
+++ b/server/tests/api/server/slow-follows.ts
@@ -0,0 +1,81 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import * as chai from 'chai'
5import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
6import { Job } from '@shared/models'
7
8const expect = chai.expect
9
10describe('Test slow follows', function () {
11 let servers: PeerTubeServer[] = []
12
13 let afterFollows: Date
14
15 before(async function () {
16 this.timeout(60000)
17
18 servers = await createMultipleServers(3)
19
20 // Get the access tokens
21 await setAccessTokensToServers(servers)
22
23 await doubleFollow(servers[0], servers[1])
24 await doubleFollow(servers[0], servers[2])
25
26 afterFollows = new Date()
27
28 for (let i = 0; i < 5; i++) {
29 await servers[0].videos.quickUpload({ name: 'video ' + i })
30 }
31
32 await waitJobs(servers)
33 })
34
35 it('Should only have broadcast jobs', async function () {
36 const { data } = await servers[0].jobs.list({ jobType: 'activitypub-http-unicast', sort: '-createdAt' })
37
38 for (const job of data) {
39 expect(new Date(job.createdAt)).below(afterFollows)
40 }
41 })
42
43 it('Should process bad follower', async function () {
44 this.timeout(30000)
45
46 await servers[1].kill()
47
48 // Set server 2 as bad follower
49 await servers[0].videos.quickUpload({ name: 'video 6' })
50 await waitJobs(servers[0])
51
52 afterFollows = new Date()
53 const filter = (job: Job) => new Date(job.createdAt) > afterFollows
54
55 // Resend another broadcast job
56 await servers[0].videos.quickUpload({ name: 'video 7' })
57 await waitJobs(servers[0])
58
59 const resBroadcast = await servers[0].jobs.list({ jobType: 'activitypub-http-broadcast', sort: '-createdAt' })
60 const resUnicast = await servers[0].jobs.list({ jobType: 'activitypub-http-unicast', sort: '-createdAt' })
61
62 const broadcast = resBroadcast.data.filter(filter)
63 const unicast = resUnicast.data.filter(filter)
64
65 expect(unicast).to.have.lengthOf(2)
66 expect(broadcast).to.have.lengthOf(2)
67
68 for (const u of unicast) {
69 expect(u.data.uri).to.equal(servers[1].url + '/inbox')
70 }
71
72 for (const b of broadcast) {
73 expect(b.data.uris).to.have.lengthOf(1)
74 expect(b.data.uris[0]).to.equal(servers[2].url + '/inbox')
75 }
76 })
77
78 after(async function () {
79 await cleanupTests(servers)
80 })
81})