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