]>
Commit | Line | Data |
---|---|---|
e1ab52d7 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | ||
b52f5048 | 3 | import { join } from 'path' |
9ab330b9 | 4 | import { areMockObjectStorageTestsDisabled } from '@shared/core-utils' |
c55e3d72 | 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' |
b52f5048 | 16 | import { checkDirectoryIsEmpty, 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 | |
9ab330b9 | 21 | ? ObjectStorageCommand.getMockWebTorrentBaseUrl() |
e1ab52d7 | 22 | : origin.url |
23 | ||
24 | expectStartWith(file.fileUrl, start) | |
25 | ||
3545e72c | 26 | await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 }) |
e1ab52d7 | 27 | } |
28 | ||
29 | const start = inObjectStorage | |
9ab330b9 | 30 | ? ObjectStorageCommand.getMockPlaylistBaseUrl() |
e1ab52d7 | 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 | ||
3545e72c | 40 | await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 }) |
e1ab52d7 | 41 | } |
42 | } | |
43 | ||
44 | describe('Test create move video storage job', function () { | |
9ab330b9 | 45 | if (areMockObjectStorageTestsDisabled()) return |
e1ab52d7 | 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 | ||
9ab330b9 | 59 | await ObjectStorageCommand.prepareDefaultMockBuckets() |
e1ab52d7 | 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() | |
9ab330b9 | 71 | await servers[0].run(ObjectStorageCommand.getDefaultMockConfig()) |
e1ab52d7 | 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]}` | |
9ab330b9 | 78 | await servers[0].cli.execWithEnv(command, ObjectStorageCommand.getDefaultMockConfig()) |
e1ab52d7 | 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` | |
9ab330b9 | 98 | await servers[0].cli.execWithEnv(command, ObjectStorageCommand.getDefaultMockConfig()) |
e1ab52d7 | 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 | ||
b52f5048 C |
110 | it('Should not have files on disk anymore', async function () { |
111 | await checkDirectoryIsEmpty(servers[0], 'videos', [ 'private' ]) | |
112 | await checkDirectoryIsEmpty(servers[0], join('videos', 'private')) | |
113 | ||
114 | await checkDirectoryIsEmpty(servers[0], join('streaming-playlists', 'hls'), [ 'private' ]) | |
115 | await checkDirectoryIsEmpty(servers[0], join('streaming-playlists', 'hls', 'private')) | |
116 | }) | |
117 | ||
e1ab52d7 | 118 | after(async function () { |
119 | await cleanupTests(servers) | |
120 | }) | |
121 | }) |