diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-21 15:51:30 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-21 15:51:30 +0200 |
commit | a24bd1ed41b43790bab6ba789580bb4e85f07d85 (patch) | |
tree | a54b0f6c921ba83a6e909cd0ced325b2d4b8863c /server/tests/api/redundancy/redundancy-constraints.ts | |
parent | 5f26f13b3c16ac5ae0a3b0a7142d84a9528cf565 (diff) | |
parent | c63830f15403ac4e750829f27d8bbbdc9a59282c (diff) | |
download | PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.tar.gz PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.tar.zst PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.zip |
Merge branch 'next' into develop
Diffstat (limited to 'server/tests/api/redundancy/redundancy-constraints.ts')
-rw-r--r-- | server/tests/api/redundancy/redundancy-constraints.ts | 69 |
1 files changed, 23 insertions, 46 deletions
diff --git a/server/tests/api/redundancy/redundancy-constraints.ts b/server/tests/api/redundancy/redundancy-constraints.ts index 1cb1603bc..933a2c776 100644 --- a/server/tests/api/redundancy/redundancy-constraints.ts +++ b/server/tests/api/redundancy/redundancy-constraints.ts | |||
@@ -1,29 +1,14 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | 4 | import { expect } from 'chai' |
5 | import { listVideoRedundancies, updateRedundancy } from '@shared/extra-utils/server/redundancy' | 5 | import { cleanupTests, createSingleServer, killallServers, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' |
6 | import { VideoPrivacy } from '@shared/models' | 6 | import { VideoPrivacy } from '@shared/models' |
7 | import { | ||
8 | cleanupTests, | ||
9 | flushAndRunServer, | ||
10 | follow, | ||
11 | killallServers, | ||
12 | reRunServer, | ||
13 | ServerInfo, | ||
14 | setAccessTokensToServers, | ||
15 | updateVideo, | ||
16 | uploadVideo, | ||
17 | waitUntilLog | ||
18 | } from '../../../../shared/extra-utils' | ||
19 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | ||
20 | |||
21 | const expect = chai.expect | ||
22 | 7 | ||
23 | describe('Test redundancy constraints', function () { | 8 | describe('Test redundancy constraints', function () { |
24 | let remoteServer: ServerInfo | 9 | let remoteServer: PeerTubeServer |
25 | let localServer: ServerInfo | 10 | let localServer: PeerTubeServer |
26 | let servers: ServerInfo[] | 11 | let servers: PeerTubeServer[] |
27 | 12 | ||
28 | const remoteServerConfig = { | 13 | const remoteServerConfig = { |
29 | redundancy: { | 14 | redundancy: { |
@@ -43,38 +28,30 @@ describe('Test redundancy constraints', function () { | |||
43 | 28 | ||
44 | async function uploadWrapper (videoName: string) { | 29 | async function uploadWrapper (videoName: string) { |
45 | // Wait for transcoding | 30 | // Wait for transcoding |
46 | const res = await uploadVideo(localServer.url, localServer.accessToken, { name: 'to transcode', privacy: VideoPrivacy.PRIVATE }) | 31 | const { id } = await localServer.videos.upload({ attributes: { name: 'to transcode', privacy: VideoPrivacy.PRIVATE } }) |
47 | await waitJobs([ localServer ]) | 32 | await waitJobs([ localServer ]) |
48 | 33 | ||
49 | // Update video to schedule a federation | 34 | // Update video to schedule a federation |
50 | await updateVideo(localServer.url, localServer.accessToken, res.body.video.id, { name: videoName, privacy: VideoPrivacy.PUBLIC }) | 35 | await localServer.videos.update({ id, attributes: { name: videoName, privacy: VideoPrivacy.PUBLIC } }) |
51 | } | 36 | } |
52 | 37 | ||
53 | async function getTotalRedundanciesLocalServer () { | 38 | async function getTotalRedundanciesLocalServer () { |
54 | const res = await listVideoRedundancies({ | 39 | const body = await localServer.redundancy.listVideos({ target: 'my-videos' }) |
55 | url: localServer.url, | ||
56 | accessToken: localServer.accessToken, | ||
57 | target: 'my-videos' | ||
58 | }) | ||
59 | 40 | ||
60 | return res.body.total | 41 | return body.total |
61 | } | 42 | } |
62 | 43 | ||
63 | async function getTotalRedundanciesRemoteServer () { | 44 | async function getTotalRedundanciesRemoteServer () { |
64 | const res = await listVideoRedundancies({ | 45 | const body = await remoteServer.redundancy.listVideos({ target: 'remote-videos' }) |
65 | url: remoteServer.url, | ||
66 | accessToken: remoteServer.accessToken, | ||
67 | target: 'remote-videos' | ||
68 | }) | ||
69 | 46 | ||
70 | return res.body.total | 47 | return body.total |
71 | } | 48 | } |
72 | 49 | ||
73 | before(async function () { | 50 | before(async function () { |
74 | this.timeout(120000) | 51 | this.timeout(120000) |
75 | 52 | ||
76 | { | 53 | { |
77 | remoteServer = await flushAndRunServer(1, remoteServerConfig) | 54 | remoteServer = await createSingleServer(1, remoteServerConfig) |
78 | } | 55 | } |
79 | 56 | ||
80 | { | 57 | { |
@@ -85,7 +62,7 @@ describe('Test redundancy constraints', function () { | |||
85 | } | 62 | } |
86 | } | 63 | } |
87 | } | 64 | } |
88 | localServer = await flushAndRunServer(2, config) | 65 | localServer = await createSingleServer(2, config) |
89 | } | 66 | } |
90 | 67 | ||
91 | servers = [ remoteServer, localServer ] | 68 | servers = [ remoteServer, localServer ] |
@@ -93,14 +70,14 @@ describe('Test redundancy constraints', function () { | |||
93 | // Get the access tokens | 70 | // Get the access tokens |
94 | await setAccessTokensToServers(servers) | 71 | await setAccessTokensToServers(servers) |
95 | 72 | ||
96 | await uploadVideo(localServer.url, localServer.accessToken, { name: 'video 1 server 2' }) | 73 | await localServer.videos.upload({ attributes: { name: 'video 1 server 2' } }) |
97 | 74 | ||
98 | await waitJobs(servers) | 75 | await waitJobs(servers) |
99 | 76 | ||
100 | // Server 1 and server 2 follow each other | 77 | // Server 1 and server 2 follow each other |
101 | await follow(remoteServer.url, [ localServer.url ], remoteServer.accessToken) | 78 | await remoteServer.follows.follow({ hosts: [ localServer.url ] }) |
102 | await waitJobs(servers) | 79 | await waitJobs(servers) |
103 | await updateRedundancy(remoteServer.url, remoteServer.accessToken, localServer.host, true) | 80 | await remoteServer.redundancy.updateRedundancy({ host: localServer.host, redundancyAllowed: true }) |
104 | 81 | ||
105 | await waitJobs(servers) | 82 | await waitJobs(servers) |
106 | }) | 83 | }) |
@@ -109,7 +86,7 @@ describe('Test redundancy constraints', function () { | |||
109 | this.timeout(120000) | 86 | this.timeout(120000) |
110 | 87 | ||
111 | await waitJobs(servers) | 88 | await waitJobs(servers) |
112 | await waitUntilLog(remoteServer, 'Duplicated ', 5) | 89 | await remoteServer.servers.waitUntilLog('Duplicated ', 5) |
113 | await waitJobs(servers) | 90 | await waitJobs(servers) |
114 | 91 | ||
115 | { | 92 | { |
@@ -134,11 +111,11 @@ describe('Test redundancy constraints', function () { | |||
134 | } | 111 | } |
135 | } | 112 | } |
136 | await killallServers([ localServer ]) | 113 | await killallServers([ localServer ]) |
137 | await reRunServer(localServer, config) | 114 | await localServer.run(config) |
138 | 115 | ||
139 | await uploadWrapper('video 2 server 2') | 116 | await uploadWrapper('video 2 server 2') |
140 | 117 | ||
141 | await waitUntilLog(remoteServer, 'Duplicated ', 10) | 118 | await remoteServer.servers.waitUntilLog('Duplicated ', 10) |
142 | await waitJobs(servers) | 119 | await waitJobs(servers) |
143 | 120 | ||
144 | { | 121 | { |
@@ -163,11 +140,11 @@ describe('Test redundancy constraints', function () { | |||
163 | } | 140 | } |
164 | } | 141 | } |
165 | await killallServers([ localServer ]) | 142 | await killallServers([ localServer ]) |
166 | await reRunServer(localServer, config) | 143 | await localServer.run(config) |
167 | 144 | ||
168 | await uploadWrapper('video 3 server 2') | 145 | await uploadWrapper('video 3 server 2') |
169 | 146 | ||
170 | await waitUntilLog(remoteServer, 'Duplicated ', 15) | 147 | await remoteServer.servers.waitUntilLog('Duplicated ', 15) |
171 | await waitJobs(servers) | 148 | await waitJobs(servers) |
172 | 149 | ||
173 | { | 150 | { |
@@ -184,11 +161,11 @@ describe('Test redundancy constraints', function () { | |||
184 | it('Should have redundancy on server 1 and on server 2 with followings filter now server 2 follows server 1', async function () { | 161 | it('Should have redundancy on server 1 and on server 2 with followings filter now server 2 follows server 1', async function () { |
185 | this.timeout(120000) | 162 | this.timeout(120000) |
186 | 163 | ||
187 | await follow(localServer.url, [ remoteServer.url ], localServer.accessToken) | 164 | await localServer.follows.follow({ hosts: [ remoteServer.url ] }) |
188 | await waitJobs(servers) | 165 | await waitJobs(servers) |
189 | 166 | ||
190 | await uploadWrapper('video 4 server 2') | 167 | await uploadWrapper('video 4 server 2') |
191 | await waitUntilLog(remoteServer, 'Duplicated ', 20) | 168 | await remoteServer.servers.waitUntilLog('Duplicated ', 20) |
192 | await waitJobs(servers) | 169 | await waitJobs(servers) |
193 | 170 | ||
194 | { | 171 | { |