]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import { areObjectStorageTestsDisabled } from '@shared/core-utils' | |
4 | import { HttpStatusCode, VideoDetails } from '@shared/models' | |
5 | import { | |
6 | cleanupTests, | |
7 | createMultipleServers, | |
8 | doubleFollow, | |
9 | makeRawRequest, | |
10 | ObjectStorageCommand, | |
11 | PeerTubeServer, | |
12 | setAccessTokensToServers, | |
13 | waitJobs | |
14 | } from '@shared/server-commands' | |
15 | import { expectStartWith } from '../shared' | |
16 | ||
17 | async function checkFiles (origin: PeerTubeServer, video: VideoDetails, inObjectStorage: boolean) { | |
18 | for (const file of video.files) { | |
19 | const start = inObjectStorage | |
20 | ? ObjectStorageCommand.getWebTorrentBaseUrl() | |
21 | : origin.url | |
22 | ||
23 | expectStartWith(file.fileUrl, start) | |
24 | ||
25 | await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200) | |
26 | } | |
27 | ||
28 | const start = inObjectStorage | |
29 | ? ObjectStorageCommand.getPlaylistBaseUrl() | |
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 | ||
39 | await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200) | |
40 | } | |
41 | } | |
42 | ||
43 | describe('Test create move video storage job', function () { | |
44 | if (areObjectStorageTestsDisabled()) return | |
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 | ||
58 | await ObjectStorageCommand.prepareDefaultBuckets() | |
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() | |
70 | await servers[0].run(ObjectStorageCommand.getDefaultConfig()) | |
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]}` | |
77 | await servers[0].cli.execWithEnv(command, ObjectStorageCommand.getDefaultConfig()) | |
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` | |
97 | await servers[0].cli.execWithEnv(command, ObjectStorageCommand.getDefaultConfig()) | |
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 | }) |