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/api/redundancy/redundancy-constraints.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/api/redundancy/redundancy-constraints.ts')
-rw-r--r-- | server/tests/api/redundancy/redundancy-constraints.ts | 191 |
1 files changed, 0 insertions, 191 deletions
diff --git a/server/tests/api/redundancy/redundancy-constraints.ts b/server/tests/api/redundancy/redundancy-constraints.ts deleted file mode 100644 index c86573168..000000000 --- a/server/tests/api/redundancy/redundancy-constraints.ts +++ /dev/null | |||
@@ -1,191 +0,0 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { expect } from 'chai' | ||
4 | import { VideoPrivacy } from '@shared/models' | ||
5 | import { | ||
6 | cleanupTests, | ||
7 | createSingleServer, | ||
8 | killallServers, | ||
9 | PeerTubeServer, | ||
10 | setAccessTokensToServers, | ||
11 | waitJobs | ||
12 | } from '@shared/server-commands' | ||
13 | |||
14 | describe('Test redundancy constraints', function () { | ||
15 | let remoteServer: PeerTubeServer | ||
16 | let localServer: PeerTubeServer | ||
17 | let servers: PeerTubeServer[] | ||
18 | |||
19 | const remoteServerConfig = { | ||
20 | redundancy: { | ||
21 | videos: { | ||
22 | check_interval: '1 second', | ||
23 | strategies: [ | ||
24 | { | ||
25 | strategy: 'recently-added', | ||
26 | min_lifetime: '1 hour', | ||
27 | size: '100MB', | ||
28 | min_views: 0 | ||
29 | } | ||
30 | ] | ||
31 | } | ||
32 | } | ||
33 | } | ||
34 | |||
35 | async function uploadWrapper (videoName: string) { | ||
36 | // Wait for transcoding | ||
37 | const { id } = await localServer.videos.upload({ attributes: { name: 'to transcode', privacy: VideoPrivacy.PRIVATE } }) | ||
38 | await waitJobs([ localServer ]) | ||
39 | |||
40 | // Update video to schedule a federation | ||
41 | await localServer.videos.update({ id, attributes: { name: videoName, privacy: VideoPrivacy.PUBLIC } }) | ||
42 | } | ||
43 | |||
44 | async function getTotalRedundanciesLocalServer () { | ||
45 | const body = await localServer.redundancy.listVideos({ target: 'my-videos' }) | ||
46 | |||
47 | return body.total | ||
48 | } | ||
49 | |||
50 | async function getTotalRedundanciesRemoteServer () { | ||
51 | const body = await remoteServer.redundancy.listVideos({ target: 'remote-videos' }) | ||
52 | |||
53 | return body.total | ||
54 | } | ||
55 | |||
56 | before(async function () { | ||
57 | this.timeout(120000) | ||
58 | |||
59 | { | ||
60 | remoteServer = await createSingleServer(1, remoteServerConfig) | ||
61 | } | ||
62 | |||
63 | { | ||
64 | const config = { | ||
65 | remote_redundancy: { | ||
66 | videos: { | ||
67 | accept_from: 'nobody' | ||
68 | } | ||
69 | } | ||
70 | } | ||
71 | localServer = await createSingleServer(2, config) | ||
72 | } | ||
73 | |||
74 | servers = [ remoteServer, localServer ] | ||
75 | |||
76 | // Get the access tokens | ||
77 | await setAccessTokensToServers(servers) | ||
78 | |||
79 | await localServer.videos.upload({ attributes: { name: 'video 1 server 2' } }) | ||
80 | |||
81 | await waitJobs(servers) | ||
82 | |||
83 | // Server 1 and server 2 follow each other | ||
84 | await remoteServer.follows.follow({ hosts: [ localServer.url ] }) | ||
85 | await waitJobs(servers) | ||
86 | await remoteServer.redundancy.updateRedundancy({ host: localServer.host, redundancyAllowed: true }) | ||
87 | |||
88 | await waitJobs(servers) | ||
89 | }) | ||
90 | |||
91 | it('Should have redundancy on server 1 but not on server 2 with a nobody filter', async function () { | ||
92 | this.timeout(120000) | ||
93 | |||
94 | await waitJobs(servers) | ||
95 | await remoteServer.servers.waitUntilLog('Duplicated ', 5) | ||
96 | await waitJobs(servers) | ||
97 | |||
98 | { | ||
99 | const total = await getTotalRedundanciesRemoteServer() | ||
100 | expect(total).to.equal(1) | ||
101 | } | ||
102 | |||
103 | { | ||
104 | const total = await getTotalRedundanciesLocalServer() | ||
105 | expect(total).to.equal(0) | ||
106 | } | ||
107 | }) | ||
108 | |||
109 | it('Should have redundancy on server 1 and on server 2 with an anybody filter', async function () { | ||
110 | this.timeout(120000) | ||
111 | |||
112 | const config = { | ||
113 | remote_redundancy: { | ||
114 | videos: { | ||
115 | accept_from: 'anybody' | ||
116 | } | ||
117 | } | ||
118 | } | ||
119 | await killallServers([ localServer ]) | ||
120 | await localServer.run(config) | ||
121 | |||
122 | await uploadWrapper('video 2 server 2') | ||
123 | |||
124 | await remoteServer.servers.waitUntilLog('Duplicated ', 10) | ||
125 | await waitJobs(servers) | ||
126 | |||
127 | { | ||
128 | const total = await getTotalRedundanciesRemoteServer() | ||
129 | expect(total).to.equal(2) | ||
130 | } | ||
131 | |||
132 | { | ||
133 | const total = await getTotalRedundanciesLocalServer() | ||
134 | expect(total).to.equal(1) | ||
135 | } | ||
136 | }) | ||
137 | |||
138 | it('Should have redundancy on server 1 but not on server 2 with a followings filter', async function () { | ||
139 | this.timeout(120000) | ||
140 | |||
141 | const config = { | ||
142 | remote_redundancy: { | ||
143 | videos: { | ||
144 | accept_from: 'followings' | ||
145 | } | ||
146 | } | ||
147 | } | ||
148 | await killallServers([ localServer ]) | ||
149 | await localServer.run(config) | ||
150 | |||
151 | await uploadWrapper('video 3 server 2') | ||
152 | |||
153 | await remoteServer.servers.waitUntilLog('Duplicated ', 15) | ||
154 | await waitJobs(servers) | ||
155 | |||
156 | { | ||
157 | const total = await getTotalRedundanciesRemoteServer() | ||
158 | expect(total).to.equal(3) | ||
159 | } | ||
160 | |||
161 | { | ||
162 | const total = await getTotalRedundanciesLocalServer() | ||
163 | expect(total).to.equal(1) | ||
164 | } | ||
165 | }) | ||
166 | |||
167 | it('Should have redundancy on server 1 and on server 2 with followings filter now server 2 follows server 1', async function () { | ||
168 | this.timeout(120000) | ||
169 | |||
170 | await localServer.follows.follow({ hosts: [ remoteServer.url ] }) | ||
171 | await waitJobs(servers) | ||
172 | |||
173 | await uploadWrapper('video 4 server 2') | ||
174 | await remoteServer.servers.waitUntilLog('Duplicated ', 20) | ||
175 | await waitJobs(servers) | ||
176 | |||
177 | { | ||
178 | const total = await getTotalRedundanciesRemoteServer() | ||
179 | expect(total).to.equal(4) | ||
180 | } | ||
181 | |||
182 | { | ||
183 | const total = await getTotalRedundanciesLocalServer() | ||
184 | expect(total).to.equal(2) | ||
185 | } | ||
186 | }) | ||
187 | |||
188 | after(async function () { | ||
189 | await cleanupTests(servers) | ||
190 | }) | ||
191 | }) | ||