X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Factivitypub%2Frefresher.ts;h=bb81d4565f5b1f14ba9ca4dff39f5b6328e0aa1d;hb=7804e577de25345da51ac3d88f6121108012b523;hp=62ad8a0b566e97013c4a999174979dddaa2b11a5;hpb=88108880bbdba473cfe36ecbebc1c3c4f972e102;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/activitypub/refresher.ts b/server/tests/api/activitypub/refresher.ts index 62ad8a0b5..bb81d4565 100644 --- a/server/tests/api/activitypub/refresher.ts +++ b/server/tests/api/activitypub/refresher.ts @@ -1,93 +1,154 @@ -/* tslint:disable:no-unused-expression */ +/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' +import { wait } from '@shared/core-utils' +import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models' import { + cleanupTests, + createMultipleServers, doubleFollow, - flushAndRunMultipleServers, - getVideo, killallServers, - reRunServer, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, - uploadVideo, - wait, - setVideoField, + setDefaultVideoChannel, waitJobs -} from '../../../../shared/utils' +} from '@shared/server-commands' describe('Test AP refresher', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] let videoUUID1: string let videoUUID2: string let videoUUID3: string + let playlistUUID1: string + let playlistUUID2: string before(async function () { this.timeout(60000) - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) // Get the access tokens await setAccessTokensToServers(servers) + await setDefaultVideoChannel(servers) + + for (const server of servers) { + await server.config.disableTranscoding() + } { - const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video1' }) - videoUUID1 = res.body.video.uuid + videoUUID1 = (await servers[1].videos.quickUpload({ name: 'video1' })).uuid + videoUUID2 = (await servers[1].videos.quickUpload({ name: 'video2' })).uuid + videoUUID3 = (await servers[1].videos.quickUpload({ name: 'video3' })).uuid } { - const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video2' }) - videoUUID2 = res.body.video.uuid + const token1 = await servers[1].users.generateUserAndToken('user1') + await servers[1].videos.upload({ token: token1, attributes: { name: 'video4' } }) + + const token2 = await servers[1].users.generateUserAndToken('user2') + await servers[1].videos.upload({ token: token2, attributes: { name: 'video5' } }) } { - const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video3' }) - videoUUID3 = res.body.video.uuid + const attributes = { displayName: 'playlist1', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].store.channel.id } + const created = await servers[1].playlists.create({ attributes }) + playlistUUID1 = created.uuid + } + + { + const attributes = { displayName: 'playlist2', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].store.channel.id } + const created = await servers[1].playlists.create({ attributes }) + playlistUUID2 = created.uuid } await doubleFollow(servers[0], servers[1]) }) - it('Should remove a deleted remote video', async function () { - this.timeout(60000) + describe('Videos refresher', function () { + + 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 servers[1].sql.setVideoField(videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f') + + await servers[0].videos.get({ id: videoUUID1 }) + await servers[0].videos.get({ id: videoUUID2 }) + + await waitJobs(servers) + + await servers[0].videos.get({ id: videoUUID1, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) + await servers[0].videos.get({ id: videoUUID2 }) + }) - await wait(10000) + it('Should not update a remote video if the remote instance is down', async function () { + this.timeout(70000) - // Change UUID so the remote server returns a 404 - await setVideoField(2, videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f') + await killallServers([ servers[1] ]) - await getVideo(servers[0].url, videoUUID1) - await getVideo(servers[0].url, videoUUID2) + await servers[1].sql.setVideoField(videoUUID3, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174e') - await waitJobs(servers) + // Video will need a refresh + await wait(10000) - await getVideo(servers[0].url, videoUUID1, 404) - await getVideo(servers[0].url, videoUUID2, 200) + await servers[0].videos.get({ id: videoUUID3 }) + // The refresh should fail + await waitJobs([ servers[0] ]) + + await servers[1].run() + + await servers[0].videos.get({ id: videoUUID3 }) + }) }) - it('Should not update a remote video if the remote instance is down', async function () { - this.timeout(60000) + describe('Actors refresher', function () { + + it('Should remove a deleted actor', async function () { + this.timeout(60000) + + const command = servers[0].accounts + + await wait(10000) - killallServers([ servers[1] ]) + // Change actor name so the remote server returns a 404 + const to = 'http://localhost:' + servers[1].port + '/accounts/user2' + await servers[1].sql.setActorField(to, 'preferredUsername', 'toto') - await setVideoField(2, videoUUID3, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174e') + await command.get({ accountName: 'user1@localhost:' + servers[1].port }) + await command.get({ accountName: 'user2@localhost:' + servers[1].port }) - // Video will need a refresh - await wait(10000) + await waitJobs(servers) - await getVideo(servers[0].url, videoUUID3) - // The refresh should fail - await waitJobs([ servers[0] ]) + await command.get({ accountName: 'user1@localhost:' + servers[1].port, expectedStatus: HttpStatusCode.OK_200 }) + await command.get({ accountName: 'user2@localhost:' + servers[1].port, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) + }) + }) + + describe('Playlist refresher', function () { + + it('Should remove a deleted playlist', async function () { + this.timeout(60000) - await reRunServer(servers[1]) + await wait(10000) - // 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) + // Change UUID so the remote server returns a 404 + await servers[1].sql.setPlaylistField(playlistUUID2, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b178e') - await getVideo(servers[0].url, videoUUID3, 200) + await servers[0].playlists.get({ playlistId: playlistUUID1 }) + await servers[0].playlists.get({ playlistId: playlistUUID2 }) + + await waitJobs(servers) + + await servers[0].playlists.get({ playlistId: playlistUUID1, expectedStatus: HttpStatusCode.OK_200 }) + await servers[0].playlists.get({ playlistId: playlistUUID2, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) + }) }) after(async function () { - killallServers(servers) + this.timeout(10000) + + await cleanupTests(servers) }) })