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/runners/runner-socket.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/runners/runner-socket.ts')
-rw-r--r-- | server/tests/api/runners/runner-socket.ts | 120 |
1 files changed, 0 insertions, 120 deletions
diff --git a/server/tests/api/runners/runner-socket.ts b/server/tests/api/runners/runner-socket.ts deleted file mode 100644 index 215164e48..000000000 --- a/server/tests/api/runners/runner-socket.ts +++ /dev/null | |||
@@ -1,120 +0,0 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { expect } from 'chai' | ||
4 | import { wait } from '@shared/core-utils' | ||
5 | import { | ||
6 | cleanupTests, | ||
7 | createSingleServer, | ||
8 | PeerTubeServer, | ||
9 | setAccessTokensToServers, | ||
10 | setDefaultVideoChannel, | ||
11 | waitJobs | ||
12 | } from '@shared/server-commands' | ||
13 | |||
14 | describe('Test runner socket', function () { | ||
15 | let server: PeerTubeServer | ||
16 | let runnerToken: string | ||
17 | |||
18 | before(async function () { | ||
19 | this.timeout(120_000) | ||
20 | |||
21 | server = await createSingleServer(1) | ||
22 | |||
23 | await setAccessTokensToServers([ server ]) | ||
24 | await setDefaultVideoChannel([ server ]) | ||
25 | |||
26 | await server.config.enableTranscoding({ hls: true, webVideo: true }) | ||
27 | await server.config.enableRemoteTranscoding() | ||
28 | runnerToken = await server.runners.autoRegisterRunner() | ||
29 | }) | ||
30 | |||
31 | it('Should throw an error without runner token', function (done) { | ||
32 | const localSocket = server.socketIO.getRunnersSocket({ runnerToken: null }) | ||
33 | localSocket.on('connect_error', err => { | ||
34 | expect(err.message).to.contain('No runner token provided') | ||
35 | done() | ||
36 | }) | ||
37 | }) | ||
38 | |||
39 | it('Should throw an error with a bad runner token', function (done) { | ||
40 | const localSocket = server.socketIO.getRunnersSocket({ runnerToken: 'ergag' }) | ||
41 | localSocket.on('connect_error', err => { | ||
42 | expect(err.message).to.contain('Invalid runner token') | ||
43 | done() | ||
44 | }) | ||
45 | }) | ||
46 | |||
47 | it('Should not send ping if there is no available jobs', async function () { | ||
48 | let pings = 0 | ||
49 | const localSocket = server.socketIO.getRunnersSocket({ runnerToken }) | ||
50 | localSocket.on('available-jobs', () => pings++) | ||
51 | |||
52 | expect(pings).to.equal(0) | ||
53 | }) | ||
54 | |||
55 | it('Should send a ping on available job', async function () { | ||
56 | let pings = 0 | ||
57 | const localSocket = server.socketIO.getRunnersSocket({ runnerToken }) | ||
58 | localSocket.on('available-jobs', () => pings++) | ||
59 | |||
60 | await server.videos.quickUpload({ name: 'video1' }) | ||
61 | await waitJobs([ server ]) | ||
62 | |||
63 | // eslint-disable-next-line no-unmodified-loop-condition | ||
64 | while (pings !== 1) { | ||
65 | await wait(500) | ||
66 | } | ||
67 | |||
68 | await server.videos.quickUpload({ name: 'video2' }) | ||
69 | await waitJobs([ server ]) | ||
70 | |||
71 | // eslint-disable-next-line no-unmodified-loop-condition | ||
72 | while ((pings as number) !== 2) { | ||
73 | await wait(500) | ||
74 | } | ||
75 | |||
76 | await server.runnerJobs.cancelAllJobs() | ||
77 | }) | ||
78 | |||
79 | it('Should send a ping when a child is ready', async function () { | ||
80 | let pings = 0 | ||
81 | const localSocket = server.socketIO.getRunnersSocket({ runnerToken }) | ||
82 | localSocket.on('available-jobs', () => pings++) | ||
83 | |||
84 | await server.videos.quickUpload({ name: 'video3' }) | ||
85 | await waitJobs([ server ]) | ||
86 | |||
87 | // eslint-disable-next-line no-unmodified-loop-condition | ||
88 | while (pings !== 1) { | ||
89 | await wait(500) | ||
90 | } | ||
91 | |||
92 | await server.runnerJobs.autoProcessWebVideoJob(runnerToken) | ||
93 | await waitJobs([ server ]) | ||
94 | |||
95 | // eslint-disable-next-line no-unmodified-loop-condition | ||
96 | while ((pings as number) !== 2) { | ||
97 | await wait(500) | ||
98 | } | ||
99 | }) | ||
100 | |||
101 | it('Should not send a ping if the ended job does not have a child', async function () { | ||
102 | let pings = 0 | ||
103 | const localSocket = server.socketIO.getRunnersSocket({ runnerToken }) | ||
104 | localSocket.on('available-jobs', () => pings++) | ||
105 | |||
106 | const { availableJobs } = await server.runnerJobs.request({ runnerToken }) | ||
107 | const job = availableJobs.find(j => j.type === 'vod-web-video-transcoding') | ||
108 | await server.runnerJobs.autoProcessWebVideoJob(runnerToken, job.uuid) | ||
109 | |||
110 | // Wait for debounce | ||
111 | await wait(1000) | ||
112 | await waitJobs([ server ]) | ||
113 | |||
114 | expect(pings).to.equal(0) | ||
115 | }) | ||
116 | |||
117 | after(async function () { | ||
118 | await cleanupTests([ server ]) | ||
119 | }) | ||
120 | }) | ||