From 9db437c8155f3563a33e22ed2896072a9f1fbdb0 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 13 Oct 2021 11:47:32 +0200 Subject: Process slow followers in unicast job queue --- server/tests/api/server/index.ts | 1 + server/tests/api/server/slow-follows.ts | 81 +++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 server/tests/api/server/slow-follows.ts (limited to 'server/tests/api') 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' import './logs' import './reverse-proxy' import './services' +import './slow-follows' import './stats' import './tracker' import './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 @@ +/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ + +import 'mocha' +import * as chai from 'chai' +import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' +import { Job } from '@shared/models' + +const expect = chai.expect + +describe('Test slow follows', function () { + let servers: PeerTubeServer[] = [] + + let afterFollows: Date + + before(async function () { + this.timeout(60000) + + servers = await createMultipleServers(3) + + // Get the access tokens + await setAccessTokensToServers(servers) + + await doubleFollow(servers[0], servers[1]) + await doubleFollow(servers[0], servers[2]) + + afterFollows = new Date() + + for (let i = 0; i < 5; i++) { + await servers[0].videos.quickUpload({ name: 'video ' + i }) + } + + await waitJobs(servers) + }) + + it('Should only have broadcast jobs', async function () { + const { data } = await servers[0].jobs.list({ jobType: 'activitypub-http-unicast', sort: '-createdAt' }) + + for (const job of data) { + expect(new Date(job.createdAt)).below(afterFollows) + } + }) + + it('Should process bad follower', async function () { + this.timeout(30000) + + await servers[1].kill() + + // Set server 2 as bad follower + await servers[0].videos.quickUpload({ name: 'video 6' }) + await waitJobs(servers[0]) + + afterFollows = new Date() + const filter = (job: Job) => new Date(job.createdAt) > afterFollows + + // Resend another broadcast job + await servers[0].videos.quickUpload({ name: 'video 7' }) + await waitJobs(servers[0]) + + const resBroadcast = await servers[0].jobs.list({ jobType: 'activitypub-http-broadcast', sort: '-createdAt' }) + const resUnicast = await servers[0].jobs.list({ jobType: 'activitypub-http-unicast', sort: '-createdAt' }) + + const broadcast = resBroadcast.data.filter(filter) + const unicast = resUnicast.data.filter(filter) + + expect(unicast).to.have.lengthOf(2) + expect(broadcast).to.have.lengthOf(2) + + for (const u of unicast) { + expect(u.data.uri).to.equal(servers[1].url + '/inbox') + } + + for (const b of broadcast) { + expect(b.data.uris).to.have.lengthOf(1) + expect(b.data.uris[0]).to.equal(servers[2].url + '/inbox') + } + }) + + after(async function () { + await cleanupTests(servers) + }) +}) -- cgit v1.2.3