diff options
Diffstat (limited to 'server/tests/api')
-rw-r--r-- | server/tests/api/server/redundancy.ts | 205 |
1 files changed, 131 insertions, 74 deletions
diff --git a/server/tests/api/server/redundancy.ts b/server/tests/api/server/redundancy.ts index c0ec75a45..211570d2f 100644 --- a/server/tests/api/server/redundancy.ts +++ b/server/tests/api/server/redundancy.ts | |||
@@ -22,9 +22,14 @@ import { updateRedundancy } from '../../utils/server/redundancy' | |||
22 | import { ActorFollow } from '../../../../shared/models/actors' | 22 | import { ActorFollow } from '../../../../shared/models/actors' |
23 | import { readdir } from 'fs-extra' | 23 | import { readdir } from 'fs-extra' |
24 | import { join } from 'path' | 24 | import { join } from 'path' |
25 | import { VideoRedundancyStrategy } from '../../../../shared/models/redundancy' | ||
25 | 26 | ||
26 | const expect = chai.expect | 27 | const expect = chai.expect |
27 | 28 | ||
29 | let servers: ServerInfo[] = [] | ||
30 | let video1Server2UUID: string | ||
31 | let video2Server2UUID: string | ||
32 | |||
28 | function checkMagnetWebseeds (file: { magnetUri: string, resolution: { id: number } }, baseWebseeds: string[]) { | 33 | function checkMagnetWebseeds (file: { magnetUri: string, resolution: { id: number } }, baseWebseeds: string[]) { |
29 | const parsed = magnetUtil.decode(file.magnetUri) | 34 | const parsed = magnetUtil.decode(file.magnetUri) |
30 | 35 | ||
@@ -34,107 +39,159 @@ function checkMagnetWebseeds (file: { magnetUri: string, resolution: { id: numbe | |||
34 | } | 39 | } |
35 | } | 40 | } |
36 | 41 | ||
37 | describe('Test videos redundancy', function () { | 42 | async function runServers (strategy: VideoRedundancyStrategy) { |
38 | let servers: ServerInfo[] = [] | 43 | const config = { |
39 | let video1Server2UUID: string | 44 | redundancy: { |
40 | let video2Server2UUID: string | 45 | videos: [ |
46 | { | ||
47 | strategy: strategy, | ||
48 | size: '100KB' | ||
49 | } | ||
50 | ] | ||
51 | } | ||
52 | } | ||
53 | servers = await flushAndRunMultipleServers(3, config) | ||
41 | 54 | ||
42 | before(async function () { | 55 | // Get the access tokens |
43 | this.timeout(120000) | 56 | await setAccessTokensToServers(servers) |
44 | 57 | ||
45 | servers = await flushAndRunMultipleServers(3) | 58 | { |
59 | const res = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, { name: 'video 1 server 2' }) | ||
60 | video1Server2UUID = res.body.video.uuid | ||
46 | 61 | ||
47 | // Get the access tokens | 62 | await viewVideo(servers[ 1 ].url, video1Server2UUID) |
48 | await setAccessTokensToServers(servers) | 63 | } |
49 | 64 | ||
50 | { | 65 | { |
51 | const res = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, { name: 'video 1 server 2' }) | 66 | const res = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, { name: 'video 2 server 2' }) |
52 | video1Server2UUID = res.body.video.uuid | 67 | video2Server2UUID = res.body.video.uuid |
68 | } | ||
53 | 69 | ||
54 | await viewVideo(servers[1].url, video1Server2UUID) | 70 | await waitJobs(servers) |
55 | } | ||
56 | 71 | ||
57 | { | 72 | // Server 1 and server 2 follow each other |
58 | const res = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, { name: 'video 2 server 2' }) | 73 | await doubleFollow(servers[ 0 ], servers[ 1 ]) |
59 | video2Server2UUID = res.body.video.uuid | 74 | // Server 1 and server 3 follow each other |
60 | } | 75 | await doubleFollow(servers[ 0 ], servers[ 2 ]) |
76 | // Server 2 and server 3 follow each other | ||
77 | await doubleFollow(servers[ 1 ], servers[ 2 ]) | ||
78 | |||
79 | await waitJobs(servers) | ||
80 | } | ||
61 | 81 | ||
62 | await waitJobs(servers) | 82 | async function check1WebSeed () { |
83 | const webseeds = [ | ||
84 | 'http://localhost:9002/static/webseed/' + video1Server2UUID | ||
85 | ] | ||
63 | 86 | ||
64 | // Server 1 and server 2 follow each other | 87 | for (const server of servers) { |
65 | await doubleFollow(servers[0], servers[1]) | 88 | const res = await getVideo(server.url, video1Server2UUID) |
66 | // Server 1 and server 3 follow each other | ||
67 | await doubleFollow(servers[0], servers[2]) | ||
68 | // Server 2 and server 3 follow each other | ||
69 | await doubleFollow(servers[1], servers[2]) | ||
70 | 89 | ||
71 | await waitJobs(servers) | 90 | const video: VideoDetails = res.body |
72 | }) | 91 | video.files.forEach(f => checkMagnetWebseeds(f, webseeds)) |
92 | } | ||
93 | } | ||
94 | |||
95 | async function enableRedundancy () { | ||
96 | await updateRedundancy(servers[ 0 ].url, servers[ 0 ].accessToken, servers[ 1 ].host, true) | ||
97 | |||
98 | const res = await getFollowingListPaginationAndSort(servers[ 0 ].url, 0, 5, '-createdAt') | ||
99 | const follows: ActorFollow[] = res.body.data | ||
100 | const server2 = follows.find(f => f.following.host === 'localhost:9002') | ||
101 | const server3 = follows.find(f => f.following.host === 'localhost:9003') | ||
102 | |||
103 | expect(server3).to.not.be.undefined | ||
104 | expect(server3.following.hostRedundancyAllowed).to.be.false | ||
105 | |||
106 | expect(server2).to.not.be.undefined | ||
107 | expect(server2.following.hostRedundancyAllowed).to.be.true | ||
108 | } | ||
73 | 109 | ||
74 | it('Should have 1 webseed on the first video', async function () { | 110 | async function check2Webseeds () { |
75 | const webseeds = [ | 111 | await waitJobs(servers) |
76 | 'http://localhost:9002/static/webseed/' + video1Server2UUID | 112 | await wait(15000) |
77 | ] | 113 | await waitJobs(servers) |
78 | 114 | ||
79 | for (const server of servers) { | 115 | const webseeds = [ |
80 | const res = await getVideo(server.url, video1Server2UUID) | 116 | 'http://localhost:9001/static/webseed/' + video1Server2UUID, |
117 | 'http://localhost:9002/static/webseed/' + video1Server2UUID | ||
118 | ] | ||
81 | 119 | ||
82 | const video: VideoDetails = res.body | 120 | for (const server of servers) { |
83 | video.files.forEach(f => checkMagnetWebseeds(f, webseeds)) | 121 | const res = await getVideo(server.url, video1Server2UUID) |
122 | |||
123 | const video: VideoDetails = res.body | ||
124 | |||
125 | for (const file of video.files) { | ||
126 | checkMagnetWebseeds(file, webseeds) | ||
84 | } | 127 | } |
85 | }) | 128 | } |
86 | 129 | ||
87 | it('Should enable redundancy on server 1', async function () { | 130 | const files = await readdir(join(root(), 'test1', 'videos')) |
88 | await updateRedundancy(servers[0].url, servers[0].accessToken, servers[1].host, true) | 131 | expect(files).to.have.lengthOf(4) |
89 | 132 | ||
90 | const res = await getFollowingListPaginationAndSort(servers[0].url, 0, 5, '-createdAt') | 133 | for (const resolution of [ 240, 360, 480, 720 ]) { |
91 | const follows: ActorFollow[] = res.body.data | 134 | expect(files.find(f => f === `${video1Server2UUID}-${resolution}.mp4`)).to.not.be.undefined |
92 | const server2 = follows.find(f => f.following.host === 'localhost:9002') | 135 | } |
93 | const server3 = follows.find(f => f.following.host === 'localhost:9003') | 136 | } |
94 | 137 | ||
95 | expect(server3).to.not.be.undefined | 138 | async function cleanServers () { |
96 | expect(server3.following.hostRedundancyAllowed).to.be.false | 139 | killallServers(servers) |
140 | } | ||
97 | 141 | ||
98 | expect(server2).to.not.be.undefined | 142 | describe('Test videos redundancy', function () { |
99 | expect(server2.following.hostRedundancyAllowed).to.be.true | ||
100 | }) | ||
101 | 143 | ||
102 | it('Should have 2 webseed on the first video', async function () { | 144 | describe('With most-views strategy', function () { |
103 | this.timeout(40000) | ||
104 | 145 | ||
105 | await waitJobs(servers) | 146 | before(function () { |
106 | await wait(15000) | 147 | this.timeout(120000) |
107 | await waitJobs(servers) | ||
108 | 148 | ||
109 | const webseeds = [ | 149 | return runServers('most-views') |
110 | 'http://localhost:9001/static/webseed/' + video1Server2UUID, | 150 | }) |
111 | 'http://localhost:9002/static/webseed/' + video1Server2UUID | ||
112 | ] | ||
113 | 151 | ||
114 | for (const server of servers) { | 152 | it('Should have 1 webseed on the first video', function () { |
115 | const res = await getVideo(server.url, video1Server2UUID) | 153 | return check1WebSeed() |
154 | }) | ||
116 | 155 | ||
117 | const video: VideoDetails = res.body | 156 | it('Should enable redundancy on server 1', async function () { |
157 | return enableRedundancy() | ||
158 | }) | ||
118 | 159 | ||
119 | for (const file of video.files) { | 160 | it('Should have 2 webseed on the first video', async function () { |
120 | checkMagnetWebseeds(file, webseeds) | 161 | this.timeout(40000) |
121 | } | ||
122 | } | ||
123 | 162 | ||
124 | const files = await readdir(join(root(), 'test1', 'videos')) | 163 | return check2Webseeds() |
125 | expect(files).to.have.lengthOf(4) | 164 | }) |
126 | 165 | ||
127 | for (const resolution of [ 240, 360, 480, 720 ]) { | 166 | after(function () { |
128 | expect(files.find(f => f === `${video1Server2UUID}-${resolution}.mp4`)).to.not.be.undefined | 167 | return cleanServers() |
129 | } | 168 | }) |
130 | }) | 169 | }) |
131 | 170 | ||
132 | after(async function () { | 171 | describe('With trending strategy', function () { |
133 | killallServers(servers) | ||
134 | 172 | ||
135 | // Keep the logs if the test failed | 173 | before(function () { |
136 | if (this['ok']) { | 174 | this.timeout(120000) |
137 | await flushTests() | 175 | |
138 | } | 176 | return runServers('trending') |
177 | }) | ||
178 | |||
179 | it('Should have 1 webseed on the first video', function () { | ||
180 | return check1WebSeed() | ||
181 | }) | ||
182 | |||
183 | it('Should enable redundancy on server 1', async function () { | ||
184 | return enableRedundancy() | ||
185 | }) | ||
186 | |||
187 | it('Should have 2 webseed on the first video', async function () { | ||
188 | this.timeout(40000) | ||
189 | |||
190 | return check2Webseeds() | ||
191 | }) | ||
192 | |||
193 | after(function () { | ||
194 | return cleanServers() | ||
195 | }) | ||
139 | }) | 196 | }) |
140 | }) | 197 | }) |