]>
Commit | Line | Data |
---|---|---|
e1ab52d7 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | ||
9ab330b9 | 3 | import { areMockObjectStorageTestsDisabled } from '@shared/core-utils' |
c55e3d72 | 4 | import { HttpStatusCode, VideoDetails } from '@shared/models' |
e1ab52d7 | 5 | import { |
e1ab52d7 | 6 | cleanupTests, |
7 | createMultipleServers, | |
8 | doubleFollow, | |
e1ab52d7 | 9 | makeRawRequest, |
10 | ObjectStorageCommand, | |
11 | PeerTubeServer, | |
12 | setAccessTokensToServers, | |
13 | waitJobs | |
bf54587a | 14 | } from '@shared/server-commands' |
c55e3d72 | 15 | import { expectStartWith } from '../shared' |
e1ab52d7 | 16 | |
17 | async function checkFiles (origin: PeerTubeServer, video: VideoDetails, inObjectStorage: boolean) { | |
18 | for (const file of video.files) { | |
19 | const start = inObjectStorage | |
9ab330b9 | 20 | ? ObjectStorageCommand.getMockWebTorrentBaseUrl() |
e1ab52d7 | 21 | : origin.url |
22 | ||
23 | expectStartWith(file.fileUrl, start) | |
24 | ||
3545e72c | 25 | await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 }) |
e1ab52d7 | 26 | } |
27 | ||
28 | const start = inObjectStorage | |
9ab330b9 | 29 | ? ObjectStorageCommand.getMockPlaylistBaseUrl() |
e1ab52d7 | 30 | : origin.url |
31 | ||
32 | const hls = video.streamingPlaylists[0] | |
33 | expectStartWith(hls.playlistUrl, start) | |
34 | expectStartWith(hls.segmentsSha256Url, start) | |
35 | ||
36 | for (const file of hls.files) { | |
37 | expectStartWith(file.fileUrl, start) | |
38 | ||
3545e72c | 39 | await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 }) |
e1ab52d7 | 40 | } |
41 | } | |
42 | ||
43 | describe('Test create move video storage job', function () { | |
9ab330b9 | 44 | if (areMockObjectStorageTestsDisabled()) return |
e1ab52d7 | 45 | |
46 | let servers: PeerTubeServer[] = [] | |
47 | const uuids: string[] = [] | |
48 | ||
49 | before(async function () { | |
50 | this.timeout(360000) | |
51 | ||
52 | // Run server 2 to have transcoding enabled | |
53 | servers = await createMultipleServers(2) | |
54 | await setAccessTokensToServers(servers) | |
55 | ||
56 | await doubleFollow(servers[0], servers[1]) | |
57 | ||
9ab330b9 | 58 | await ObjectStorageCommand.prepareDefaultMockBuckets() |
e1ab52d7 | 59 | |
60 | await servers[0].config.enableTranscoding() | |
61 | ||
62 | for (let i = 0; i < 3; i++) { | |
63 | const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video' + i } }) | |
64 | uuids.push(uuid) | |
65 | } | |
66 | ||
67 | await waitJobs(servers) | |
68 | ||
69 | await servers[0].kill() | |
9ab330b9 | 70 | await servers[0].run(ObjectStorageCommand.getDefaultMockConfig()) |
e1ab52d7 | 71 | }) |
72 | ||
73 | it('Should move only one file', async function () { | |
74 | this.timeout(120000) | |
75 | ||
76 | const command = `npm run create-move-video-storage-job -- --to-object-storage -v ${uuids[1]}` | |
9ab330b9 | 77 | await servers[0].cli.execWithEnv(command, ObjectStorageCommand.getDefaultMockConfig()) |
e1ab52d7 | 78 | await waitJobs(servers) |
79 | ||
80 | for (const server of servers) { | |
81 | const video = await server.videos.get({ id: uuids[1] }) | |
82 | ||
83 | await checkFiles(servers[0], video, true) | |
84 | ||
85 | for (const id of [ uuids[0], uuids[2] ]) { | |
86 | const video = await server.videos.get({ id }) | |
87 | ||
88 | await checkFiles(servers[0], video, false) | |
89 | } | |
90 | } | |
91 | }) | |
92 | ||
93 | it('Should move all files', async function () { | |
94 | this.timeout(120000) | |
95 | ||
96 | const command = `npm run create-move-video-storage-job -- --to-object-storage --all-videos` | |
9ab330b9 | 97 | await servers[0].cli.execWithEnv(command, ObjectStorageCommand.getDefaultMockConfig()) |
e1ab52d7 | 98 | await waitJobs(servers) |
99 | ||
100 | for (const server of servers) { | |
101 | for (const id of [ uuids[0], uuids[2] ]) { | |
102 | const video = await server.videos.get({ id }) | |
103 | ||
104 | await checkFiles(servers[0], video, true) | |
105 | } | |
106 | } | |
107 | }) | |
108 | ||
109 | after(async function () { | |
110 | await cleanupTests(servers) | |
111 | }) | |
112 | }) |