diff options
author | Chocobozzz <me@florianbigard.com> | 2023-07-31 14:34:36 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2023-08-11 15:02:33 +0200 |
commit | 3a4992633ee62d5edfbb484d9c6bcb3cf158489d (patch) | |
tree | e4510b39bdac9c318fdb4b47018d08f15368b8f0 /server/tests/cli/create-move-video-storage-job.ts | |
parent | 04d1da5621d25d59bd5fa1543b725c497bf5d9a8 (diff) | |
download | PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.tar.gz PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.tar.zst PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.zip |
Migrate server to ESM
Sorry for the very big commit that may lead to git log issues and merge
conflicts, but it's a major step forward:
* Server can be faster at startup because imports() are async and we can
easily lazy import big modules
* Angular doesn't seem to support ES import (with .js extension), so we
had to correctly organize peertube into a monorepo:
* Use yarn workspace feature
* Use typescript reference projects for dependencies
* Shared projects have been moved into "packages", each one is now a
node module (with a dedicated package.json/tsconfig.json)
* server/tools have been moved into apps/ and is now a dedicated app
bundled and published on NPM so users don't have to build peertube
cli tools manually
* server/tests have been moved into packages/ so we don't compile
them every time we want to run the server
* Use isolatedModule option:
* Had to move from const enum to const
(https://www.typescriptlang.org/docs/handbook/enums.html#objects-vs-enums)
* Had to explictely specify "type" imports when used in decorators
* Prefer tsx (that uses esbuild under the hood) instead of ts-node to
load typescript files (tests with mocha or scripts):
* To reduce test complexity as esbuild doesn't support decorator
metadata, we only test server files that do not import server
models
* We still build tests files into js files for a faster CI
* Remove unmaintained peertube CLI import script
* Removed some barrels to speed up execution (less imports)
Diffstat (limited to 'server/tests/cli/create-move-video-storage-job.ts')
-rw-r--r-- | server/tests/cli/create-move-video-storage-job.ts | 124 |
1 files changed, 0 insertions, 124 deletions
diff --git a/server/tests/cli/create-move-video-storage-job.ts b/server/tests/cli/create-move-video-storage-job.ts deleted file mode 100644 index fc6a8e648..000000000 --- a/server/tests/cli/create-move-video-storage-job.ts +++ /dev/null | |||
@@ -1,124 +0,0 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { join } from 'path' | ||
4 | import { areMockObjectStorageTestsDisabled } from '@shared/core-utils' | ||
5 | import { HttpStatusCode, VideoDetails } from '@shared/models' | ||
6 | import { | ||
7 | cleanupTests, | ||
8 | createMultipleServers, | ||
9 | doubleFollow, | ||
10 | makeRawRequest, | ||
11 | ObjectStorageCommand, | ||
12 | PeerTubeServer, | ||
13 | setAccessTokensToServers, | ||
14 | waitJobs | ||
15 | } from '@shared/server-commands' | ||
16 | import { checkDirectoryIsEmpty, expectStartWith } from '../shared' | ||
17 | |||
18 | async function checkFiles (origin: PeerTubeServer, video: VideoDetails, objectStorage?: ObjectStorageCommand) { | ||
19 | for (const file of video.files) { | ||
20 | const start = objectStorage | ||
21 | ? objectStorage.getMockWebVideosBaseUrl() | ||
22 | : origin.url | ||
23 | |||
24 | expectStartWith(file.fileUrl, start) | ||
25 | |||
26 | await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 }) | ||
27 | } | ||
28 | |||
29 | const start = objectStorage | ||
30 | ? objectStorage.getMockPlaylistBaseUrl() | ||
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({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 }) | ||
41 | } | ||
42 | } | ||
43 | |||
44 | describe('Test create move video storage job', function () { | ||
45 | if (areMockObjectStorageTestsDisabled()) return | ||
46 | |||
47 | let servers: PeerTubeServer[] = [] | ||
48 | const uuids: string[] = [] | ||
49 | const objectStorage = new ObjectStorageCommand() | ||
50 | |||
51 | before(async function () { | ||
52 | this.timeout(360000) | ||
53 | |||
54 | // Run server 2 to have transcoding enabled | ||
55 | servers = await createMultipleServers(2) | ||
56 | await setAccessTokensToServers(servers) | ||
57 | |||
58 | await doubleFollow(servers[0], servers[1]) | ||
59 | |||
60 | await objectStorage.prepareDefaultMockBuckets() | ||
61 | |||
62 | await servers[0].config.enableTranscoding() | ||
63 | |||
64 | for (let i = 0; i < 3; i++) { | ||
65 | const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video' + i } }) | ||
66 | uuids.push(uuid) | ||
67 | } | ||
68 | |||
69 | await waitJobs(servers) | ||
70 | |||
71 | await servers[0].kill() | ||
72 | await servers[0].run(objectStorage.getDefaultMockConfig()) | ||
73 | }) | ||
74 | |||
75 | it('Should move only one file', async function () { | ||
76 | this.timeout(120000) | ||
77 | |||
78 | const command = `npm run create-move-video-storage-job -- --to-object-storage -v ${uuids[1]}` | ||
79 | await servers[0].cli.execWithEnv(command, objectStorage.getDefaultMockConfig()) | ||
80 | await waitJobs(servers) | ||
81 | |||
82 | for (const server of servers) { | ||
83 | const video = await server.videos.get({ id: uuids[1] }) | ||
84 | |||
85 | await checkFiles(servers[0], video, objectStorage) | ||
86 | |||
87 | for (const id of [ uuids[0], uuids[2] ]) { | ||
88 | const video = await server.videos.get({ id }) | ||
89 | |||
90 | await checkFiles(servers[0], video) | ||
91 | } | ||
92 | } | ||
93 | }) | ||
94 | |||
95 | it('Should move all files', async function () { | ||
96 | this.timeout(120000) | ||
97 | |||
98 | const command = `npm run create-move-video-storage-job -- --to-object-storage --all-videos` | ||
99 | await servers[0].cli.execWithEnv(command, objectStorage.getDefaultMockConfig()) | ||
100 | await waitJobs(servers) | ||
101 | |||
102 | for (const server of servers) { | ||
103 | for (const id of [ uuids[0], uuids[2] ]) { | ||
104 | const video = await server.videos.get({ id }) | ||
105 | |||
106 | await checkFiles(servers[0], video, objectStorage) | ||
107 | } | ||
108 | } | ||
109 | }) | ||
110 | |||
111 | it('Should not have files on disk anymore', async function () { | ||
112 | await checkDirectoryIsEmpty(servers[0], 'web-videos', [ 'private' ]) | ||
113 | await checkDirectoryIsEmpty(servers[0], join('web-videos', 'private')) | ||
114 | |||
115 | await checkDirectoryIsEmpty(servers[0], join('streaming-playlists', 'hls'), [ 'private' ]) | ||
116 | await checkDirectoryIsEmpty(servers[0], join('streaming-playlists', 'hls', 'private')) | ||
117 | }) | ||
118 | |||
119 | after(async function () { | ||
120 | await objectStorage.cleanupMock() | ||
121 | |||
122 | await cleanupTests(servers) | ||
123 | }) | ||
124 | }) | ||