]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import { wait } from '@shared/core-utils' | |
4 | import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models' | |
5 | import { | |
6 | cleanupTests, | |
7 | createMultipleServers, | |
8 | doubleFollow, | |
9 | killallServers, | |
10 | PeerTubeServer, | |
11 | setAccessTokensToServers, | |
12 | setDefaultVideoChannel, | |
13 | waitJobs | |
14 | } from '@shared/server-commands' | |
15 | ||
16 | describe('Test AP refresher', function () { | |
17 | let servers: PeerTubeServer[] = [] | |
18 | let videoUUID1: string | |
19 | let videoUUID2: string | |
20 | let videoUUID3: string | |
21 | let playlistUUID1: string | |
22 | let playlistUUID2: string | |
23 | ||
24 | before(async function () { | |
25 | this.timeout(60000) | |
26 | ||
27 | servers = await createMultipleServers(2) | |
28 | ||
29 | // Get the access tokens | |
30 | await setAccessTokensToServers(servers) | |
31 | await setDefaultVideoChannel(servers) | |
32 | ||
33 | for (const server of servers) { | |
34 | await server.config.disableTranscoding() | |
35 | } | |
36 | ||
37 | { | |
38 | videoUUID1 = (await servers[1].videos.quickUpload({ name: 'video1' })).uuid | |
39 | videoUUID2 = (await servers[1].videos.quickUpload({ name: 'video2' })).uuid | |
40 | videoUUID3 = (await servers[1].videos.quickUpload({ name: 'video3' })).uuid | |
41 | } | |
42 | ||
43 | { | |
44 | const token1 = await servers[1].users.generateUserAndToken('user1') | |
45 | await servers[1].videos.upload({ token: token1, attributes: { name: 'video4' } }) | |
46 | ||
47 | const token2 = await servers[1].users.generateUserAndToken('user2') | |
48 | await servers[1].videos.upload({ token: token2, attributes: { name: 'video5' } }) | |
49 | } | |
50 | ||
51 | { | |
52 | const attributes = { displayName: 'playlist1', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].store.channel.id } | |
53 | const created = await servers[1].playlists.create({ attributes }) | |
54 | playlistUUID1 = created.uuid | |
55 | } | |
56 | ||
57 | { | |
58 | const attributes = { displayName: 'playlist2', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].store.channel.id } | |
59 | const created = await servers[1].playlists.create({ attributes }) | |
60 | playlistUUID2 = created.uuid | |
61 | } | |
62 | ||
63 | await doubleFollow(servers[0], servers[1]) | |
64 | }) | |
65 | ||
66 | describe('Videos refresher', function () { | |
67 | ||
68 | it('Should remove a deleted remote video', async function () { | |
69 | this.timeout(60000) | |
70 | ||
71 | await wait(10000) | |
72 | ||
73 | // Change UUID so the remote server returns a 404 | |
74 | await servers[1].sql.setVideoField(videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f') | |
75 | ||
76 | await servers[0].videos.get({ id: videoUUID1 }) | |
77 | await servers[0].videos.get({ id: videoUUID2 }) | |
78 | ||
79 | await waitJobs(servers) | |
80 | ||
81 | await servers[0].videos.get({ id: videoUUID1, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) | |
82 | await servers[0].videos.get({ id: videoUUID2 }) | |
83 | }) | |
84 | ||
85 | it('Should not update a remote video if the remote instance is down', async function () { | |
86 | this.timeout(70000) | |
87 | ||
88 | await killallServers([ servers[1] ]) | |
89 | ||
90 | await servers[1].sql.setVideoField(videoUUID3, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174e') | |
91 | ||
92 | // Video will need a refresh | |
93 | await wait(10000) | |
94 | ||
95 | await servers[0].videos.get({ id: videoUUID3 }) | |
96 | // The refresh should fail | |
97 | await waitJobs([ servers[0] ]) | |
98 | ||
99 | await servers[1].run() | |
100 | ||
101 | await servers[0].videos.get({ id: videoUUID3 }) | |
102 | }) | |
103 | }) | |
104 | ||
105 | describe('Actors refresher', function () { | |
106 | ||
107 | it('Should remove a deleted actor', async function () { | |
108 | this.timeout(60000) | |
109 | ||
110 | const command = servers[0].accounts | |
111 | ||
112 | await wait(10000) | |
113 | ||
114 | // Change actor name so the remote server returns a 404 | |
115 | const to = 'http://localhost:' + servers[1].port + '/accounts/user2' | |
116 | await servers[1].sql.setActorField(to, 'preferredUsername', 'toto') | |
117 | ||
118 | await command.get({ accountName: 'user1@localhost:' + servers[1].port }) | |
119 | await command.get({ accountName: 'user2@localhost:' + servers[1].port }) | |
120 | ||
121 | await waitJobs(servers) | |
122 | ||
123 | await command.get({ accountName: 'user1@localhost:' + servers[1].port, expectedStatus: HttpStatusCode.OK_200 }) | |
124 | await command.get({ accountName: 'user2@localhost:' + servers[1].port, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) | |
125 | }) | |
126 | }) | |
127 | ||
128 | describe('Playlist refresher', function () { | |
129 | ||
130 | it('Should remove a deleted playlist', async function () { | |
131 | this.timeout(60000) | |
132 | ||
133 | await wait(10000) | |
134 | ||
135 | // Change UUID so the remote server returns a 404 | |
136 | await servers[1].sql.setPlaylistField(playlistUUID2, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b178e') | |
137 | ||
138 | await servers[0].playlists.get({ playlistId: playlistUUID1 }) | |
139 | await servers[0].playlists.get({ playlistId: playlistUUID2 }) | |
140 | ||
141 | await waitJobs(servers) | |
142 | ||
143 | await servers[0].playlists.get({ playlistId: playlistUUID1, expectedStatus: HttpStatusCode.OK_200 }) | |
144 | await servers[0].playlists.get({ playlistId: playlistUUID2, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) | |
145 | }) | |
146 | }) | |
147 | ||
148 | after(async function () { | |
149 | this.timeout(10000) | |
150 | ||
151 | await cleanupTests(servers) | |
152 | }) | |
153 | }) |