aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/runners/runner-socket.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-04-21 15:00:01 +0200
committerChocobozzz <chocobozzz@cpy.re>2023-05-09 08:57:34 +0200
commitd102de1b38f2877463529c3b27bd35ffef4fd8bf (patch)
tree31fa0bdf26ad7a2ee46d600d804a6f03260266c8 /server/tests/api/runners/runner-socket.ts
parent2fe978744e5b74eb824e4d79c1bb9b840169f125 (diff)
downloadPeerTube-d102de1b38f2877463529c3b27bd35ffef4fd8bf.tar.gz
PeerTube-d102de1b38f2877463529c3b27bd35ffef4fd8bf.tar.zst
PeerTube-d102de1b38f2877463529c3b27bd35ffef4fd8bf.zip
Add runner server tests
Diffstat (limited to 'server/tests/api/runners/runner-socket.ts')
-rw-r--r--server/tests/api/runners/runner-socket.ts116
1 files changed, 116 insertions, 0 deletions
diff --git a/server/tests/api/runners/runner-socket.ts b/server/tests/api/runners/runner-socket.ts
new file mode 100644
index 000000000..df640f99c
--- /dev/null
+++ b/server/tests/api/runners/runner-socket.ts
@@ -0,0 +1,116 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import { expect } from 'chai'
4import { wait } from '@shared/core-utils'
5import {
6 cleanupTests,
7 createSingleServer,
8 PeerTubeServer,
9 setAccessTokensToServers,
10 setDefaultVideoChannel,
11 waitJobs
12} from '@shared/server-commands'
13
14describe('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(true, 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
62 // Wait for debounce
63 await wait(1000)
64 await waitJobs([ server ])
65 expect(pings).to.equal(1)
66
67 await server.videos.quickUpload({ name: 'video2' })
68
69 // Wait for debounce
70 await wait(1000)
71 await waitJobs([ server ])
72 expect(pings).to.equal(2)
73
74 await server.runnerJobs.cancelAllJobs()
75 })
76
77 it('Should send a ping when a child is ready', async function () {
78 let pings = 0
79 const localSocket = server.socketIO.getRunnersSocket({ runnerToken })
80 localSocket.on('available-jobs', () => pings++)
81
82 await server.videos.quickUpload({ name: 'video3' })
83 // Wait for debounce
84 await wait(1000)
85 await waitJobs([ server ])
86
87 expect(pings).to.equal(1)
88
89 await server.runnerJobs.autoProcessWebVideoJob(runnerToken)
90 // Wait for debounce
91 await wait(1000)
92 await waitJobs([ server ])
93
94 expect(pings).to.equal(2)
95 })
96
97 it('Should not send a ping if the ended job does not have a child', async function () {
98 let pings = 0
99 const localSocket = server.socketIO.getRunnersSocket({ runnerToken })
100 localSocket.on('available-jobs', () => pings++)
101
102 const { availableJobs } = await server.runnerJobs.request({ runnerToken })
103 const job = availableJobs.find(j => j.type === 'vod-web-video-transcoding')
104 await server.runnerJobs.autoProcessWebVideoJob(runnerToken, job.uuid)
105
106 // Wait for debounce
107 await wait(1000)
108 await waitJobs([ server ])
109
110 expect(pings).to.equal(0)
111 })
112
113 after(async function () {
114 await cleanupTests([ server ])
115 })
116})