1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { expect } from 'chai'
4 import { Job } from '@shared/models'
10 setAccessTokensToServers,
12 } from '@shared/server-commands'
14 describe('Test slow follows', function () {
15 let servers: PeerTubeServer[] = []
17 let afterFollows: Date
19 before(async function () {
22 servers = await createMultipleServers(3)
24 // Get the access tokens
25 await setAccessTokensToServers(servers)
27 await doubleFollow(servers[0], servers[1])
28 await doubleFollow(servers[0], servers[2])
30 afterFollows = new Date()
32 for (let i = 0; i < 5; i++) {
33 await servers[0].videos.quickUpload({ name: 'video ' + i })
36 await waitJobs(servers)
39 it('Should only have broadcast jobs', async function () {
40 const { data } = await servers[0].jobs.list({ jobType: 'activitypub-http-unicast', sort: '-createdAt' })
42 for (const job of data) {
43 expect(new Date(job.createdAt)).below(afterFollows)
47 it('Should process bad follower', async function () {
50 await servers[1].kill()
52 // Set server 2 as bad follower
53 await servers[0].videos.quickUpload({ name: 'video 6' })
54 await waitJobs(servers[0])
56 afterFollows = new Date()
57 const filter = (job: Job) => new Date(job.createdAt) > afterFollows
59 // Resend another broadcast job
60 await servers[0].videos.quickUpload({ name: 'video 7' })
61 await waitJobs(servers[0])
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' })
66 const broadcast = resBroadcast.data.filter(filter)
67 const unicast = resUnicast.data.filter(filter)
69 expect(unicast).to.have.lengthOf(2)
70 expect(broadcast).to.have.lengthOf(2)
72 for (const u of unicast) {
73 expect(u.data.uri).to.equal(servers[1].url + '/inbox')
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')
82 after(async function () {
83 await cleanupTests(servers)