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