diff options
Diffstat (limited to 'server/tests/api/activitypub/cleaner.ts')
-rw-r--r-- | server/tests/api/activitypub/cleaner.ts | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/server/tests/api/activitypub/cleaner.ts b/server/tests/api/activitypub/cleaner.ts index 1c1495022..d67175e20 100644 --- a/server/tests/api/activitypub/cleaner.ts +++ b/server/tests/api/activitypub/cleaner.ts | |||
@@ -1,6 +1,7 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | 2 | ||
3 | import { expect } from 'chai' | 3 | import { expect } from 'chai' |
4 | import { SQLCommand } from '@server/tests/shared' | ||
4 | import { wait } from '@shared/core-utils' | 5 | import { wait } from '@shared/core-utils' |
5 | import { | 6 | import { |
6 | cleanupTests, | 7 | cleanupTests, |
@@ -13,6 +14,8 @@ import { | |||
13 | 14 | ||
14 | describe('Test AP cleaner', function () { | 15 | describe('Test AP cleaner', function () { |
15 | let servers: PeerTubeServer[] = [] | 16 | let servers: PeerTubeServer[] = [] |
17 | const sqlCommands: SQLCommand[] = [] | ||
18 | |||
16 | let videoUUID1: string | 19 | let videoUUID1: string |
17 | let videoUUID2: string | 20 | let videoUUID2: string |
18 | let videoUUID3: string | 21 | let videoUUID3: string |
@@ -56,6 +59,8 @@ describe('Test AP cleaner', function () { | |||
56 | await server.videos.rate({ id: uuid, rating: 'like' }) | 59 | await server.videos.rate({ id: uuid, rating: 'like' }) |
57 | await server.comments.createThread({ videoId: uuid, text: 'comment' }) | 60 | await server.comments.createThread({ videoId: uuid, text: 'comment' }) |
58 | } | 61 | } |
62 | |||
63 | sqlCommands.push(new SQLCommand(server)) | ||
59 | } | 64 | } |
60 | 65 | ||
61 | await waitJobs(servers) | 66 | await waitJobs(servers) |
@@ -75,9 +80,9 @@ describe('Test AP cleaner', function () { | |||
75 | it('Should destroy server 3 internal likes and correctly clean them', async function () { | 80 | it('Should destroy server 3 internal likes and correctly clean them', async function () { |
76 | this.timeout(20000) | 81 | this.timeout(20000) |
77 | 82 | ||
78 | await servers[2].sql.deleteAll('accountVideoRate') | 83 | await sqlCommands[2].deleteAll('accountVideoRate') |
79 | for (const uuid of videoUUIDs) { | 84 | for (const uuid of videoUUIDs) { |
80 | await servers[2].sql.setVideoField(uuid, 'likes', '0') | 85 | await sqlCommands[2].setVideoField(uuid, 'likes', '0') |
81 | } | 86 | } |
82 | 87 | ||
83 | await wait(5000) | 88 | await wait(5000) |
@@ -121,10 +126,10 @@ describe('Test AP cleaner', function () { | |||
121 | it('Should destroy server 3 internal dislikes and correctly clean them', async function () { | 126 | it('Should destroy server 3 internal dislikes and correctly clean them', async function () { |
122 | this.timeout(20000) | 127 | this.timeout(20000) |
123 | 128 | ||
124 | await servers[2].sql.deleteAll('accountVideoRate') | 129 | await sqlCommands[2].deleteAll('accountVideoRate') |
125 | 130 | ||
126 | for (const uuid of videoUUIDs) { | 131 | for (const uuid of videoUUIDs) { |
127 | await servers[2].sql.setVideoField(uuid, 'dislikes', '0') | 132 | await sqlCommands[2].setVideoField(uuid, 'dislikes', '0') |
128 | } | 133 | } |
129 | 134 | ||
130 | await wait(5000) | 135 | await wait(5000) |
@@ -148,15 +153,15 @@ describe('Test AP cleaner', function () { | |||
148 | it('Should destroy server 3 internal shares and correctly clean them', async function () { | 153 | it('Should destroy server 3 internal shares and correctly clean them', async function () { |
149 | this.timeout(20000) | 154 | this.timeout(20000) |
150 | 155 | ||
151 | const preCount = await servers[0].sql.getVideoShareCount() | 156 | const preCount = await sqlCommands[0].getVideoShareCount() |
152 | expect(preCount).to.equal(6) | 157 | expect(preCount).to.equal(6) |
153 | 158 | ||
154 | await servers[2].sql.deleteAll('videoShare') | 159 | await sqlCommands[2].deleteAll('videoShare') |
155 | await wait(5000) | 160 | await wait(5000) |
156 | await waitJobs(servers) | 161 | await waitJobs(servers) |
157 | 162 | ||
158 | // Still 6 because we don't have remote shares on local videos | 163 | // Still 6 because we don't have remote shares on local videos |
159 | const postCount = await servers[0].sql.getVideoShareCount() | 164 | const postCount = await sqlCommands[0].getVideoShareCount() |
160 | expect(postCount).to.equal(6) | 165 | expect(postCount).to.equal(6) |
161 | }) | 166 | }) |
162 | 167 | ||
@@ -168,7 +173,7 @@ describe('Test AP cleaner', function () { | |||
168 | expect(total).to.equal(3) | 173 | expect(total).to.equal(3) |
169 | } | 174 | } |
170 | 175 | ||
171 | await servers[2].sql.deleteAll('videoComment') | 176 | await sqlCommands[2].deleteAll('videoComment') |
172 | 177 | ||
173 | await wait(5000) | 178 | await wait(5000) |
174 | await waitJobs(servers) | 179 | await waitJobs(servers) |
@@ -185,7 +190,7 @@ describe('Test AP cleaner', function () { | |||
185 | async function check (like: string, ofServerUrl: string, urlSuffix: string, remote: 'true' | 'false') { | 190 | async function check (like: string, ofServerUrl: string, urlSuffix: string, remote: 'true' | 'false') { |
186 | const query = `SELECT "videoId", "accountVideoRate".url FROM "accountVideoRate" ` + | 191 | const query = `SELECT "videoId", "accountVideoRate".url FROM "accountVideoRate" ` + |
187 | `INNER JOIN video ON "accountVideoRate"."videoId" = video.id AND remote IS ${remote} WHERE "accountVideoRate"."url" LIKE '${like}'` | 192 | `INNER JOIN video ON "accountVideoRate"."videoId" = video.id AND remote IS ${remote} WHERE "accountVideoRate"."url" LIKE '${like}'` |
188 | const res = await servers[0].sql.selectQuery<{ url: string }>(query) | 193 | const res = await sqlCommands[0].selectQuery<{ url: string }>(query) |
189 | 194 | ||
190 | for (const rate of res) { | 195 | for (const rate of res) { |
191 | const matcher = new RegExp(`^${ofServerUrl}/accounts/root/dislikes/\\d+${urlSuffix}$`) | 196 | const matcher = new RegExp(`^${ofServerUrl}/accounts/root/dislikes/\\d+${urlSuffix}$`) |
@@ -214,7 +219,7 @@ describe('Test AP cleaner', function () { | |||
214 | 219 | ||
215 | { | 220 | { |
216 | const query = `UPDATE "accountVideoRate" SET url = url || 'stan'` | 221 | const query = `UPDATE "accountVideoRate" SET url = url || 'stan'` |
217 | await servers[1].sql.updateQuery(query) | 222 | await sqlCommands[1].updateQuery(query) |
218 | 223 | ||
219 | await wait(5000) | 224 | await wait(5000) |
220 | await waitJobs(servers) | 225 | await waitJobs(servers) |
@@ -231,7 +236,7 @@ describe('Test AP cleaner', function () { | |||
231 | const query = `SELECT "videoId", "videoComment".url, uuid as "videoUUID" FROM "videoComment" ` + | 236 | const query = `SELECT "videoId", "videoComment".url, uuid as "videoUUID" FROM "videoComment" ` + |
232 | `INNER JOIN video ON "videoComment"."videoId" = video.id AND remote IS ${remote} WHERE "videoComment"."url" LIKE '${like}'` | 237 | `INNER JOIN video ON "videoComment"."videoId" = video.id AND remote IS ${remote} WHERE "videoComment"."url" LIKE '${like}'` |
233 | 238 | ||
234 | const res = await servers[0].sql.selectQuery<{ url: string, videoUUID: string }>(query) | 239 | const res = await sqlCommands[0].selectQuery<{ url: string, videoUUID: string }>(query) |
235 | 240 | ||
236 | for (const comment of res) { | 241 | for (const comment of res) { |
237 | const matcher = new RegExp(`${ofServerUrl}/videos/watch/${comment.videoUUID}/comments/\\d+${urlSuffix}`) | 242 | const matcher = new RegExp(`${ofServerUrl}/videos/watch/${comment.videoUUID}/comments/\\d+${urlSuffix}`) |
@@ -257,7 +262,7 @@ describe('Test AP cleaner', function () { | |||
257 | 262 | ||
258 | { | 263 | { |
259 | const query = `UPDATE "videoComment" SET url = url || 'kyle'` | 264 | const query = `UPDATE "videoComment" SET url = url || 'kyle'` |
260 | await servers[1].sql.updateQuery(query) | 265 | await sqlCommands[1].updateQuery(query) |
261 | 266 | ||
262 | await wait(5000) | 267 | await wait(5000) |
263 | await waitJobs(servers) | 268 | await waitJobs(servers) |
@@ -328,6 +333,10 @@ describe('Test AP cleaner', function () { | |||
328 | }) | 333 | }) |
329 | 334 | ||
330 | after(async function () { | 335 | after(async function () { |
336 | for (const sql of sqlCommands) { | ||
337 | await sql.cleanup() | ||
338 | } | ||
339 | |||
331 | await cleanupTests(servers) | 340 | await cleanupTests(servers) |
332 | }) | 341 | }) |
333 | }) | 342 | }) |