aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api')
-rw-r--r--server/tests/api/server/handle-down.ts93
1 files changed, 58 insertions, 35 deletions
diff --git a/server/tests/api/server/handle-down.ts b/server/tests/api/server/handle-down.ts
index 84d310ae6..fb9722630 100644
--- a/server/tests/api/server/handle-down.ts
+++ b/server/tests/api/server/handle-down.ts
@@ -2,10 +2,10 @@
2 2
3import * as chai from 'chai' 3import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { JobState } from '../../../../shared/models' 5import { JobState, Video } from '../../../../shared/models'
6import { VideoPrivacy } from '../../../../shared/models/videos' 6import { VideoPrivacy } from '../../../../shared/models/videos'
7import { VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model' 7import { VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model'
8import { completeVideoCheck, getVideo, immutableAssign, reRunServer, viewVideo } from '../../utils' 8import { completeVideoCheck, getVideo, immutableAssign, reRunServer, unfollow, viewVideo } from '../../utils'
9import { 9import {
10 flushAndRunMultipleServers, 10 flushAndRunMultipleServers,
11 getVideosList, 11 getVideosList,
@@ -28,11 +28,13 @@ const expect = chai.expect
28 28
29describe('Test handle downs', function () { 29describe('Test handle downs', function () {
30 let servers: ServerInfo[] = [] 30 let servers: ServerInfo[] = []
31 const videos = []
32 let threadIdServer1: number 31 let threadIdServer1: number
33 let threadIdServer2: number 32 let threadIdServer2: number
34 let commentIdServer1: number 33 let commentIdServer1: number
35 let commentIdServer2: number 34 let commentIdServer2: number
35 let missedVideo1: Video
36 let missedVideo2: Video
37 let unlistedVideo: Video
36 38
37 const videoAttributes = { 39 const videoAttributes = {
38 name: 'my super name for server 1', 40 name: 'my super name for server 1',
@@ -89,7 +91,7 @@ describe('Test handle downs', function () {
89 before(async function () { 91 before(async function () {
90 this.timeout(30000) 92 this.timeout(30000)
91 93
92 servers = await flushAndRunMultipleServers(2) 94 servers = await flushAndRunMultipleServers(3)
93 95
94 // Get the access tokens 96 // Get the access tokens
95 await setAccessTokensToServers(servers) 97 await setAccessTokensToServers(servers)
@@ -98,47 +100,58 @@ describe('Test handle downs', function () {
98 it('Should remove followers that are often down', async function () { 100 it('Should remove followers that are often down', async function () {
99 this.timeout(60000) 101 this.timeout(60000)
100 102
103 // Server 2 and 3 follow server 1
101 await follow(servers[1].url, [ servers[0].url ], servers[1].accessToken) 104 await follow(servers[1].url, [ servers[0].url ], servers[1].accessToken)
105 await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken)
102 106
103 await waitJobs(servers) 107 await waitJobs(servers)
104 108
109 // Upload a video to server 1
105 await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) 110 await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
106 111
107 await waitJobs(servers) 112 await waitJobs(servers)
108 113
114 // And check all servers have this video
109 for (const server of servers) { 115 for (const server of servers) {
110 const res = await getVideosList(server.url) 116 const res = await getVideosList(server.url)
111 expect(res.body.data).to.be.an('array') 117 expect(res.body.data).to.be.an('array')
112 expect(res.body.data).to.have.lengthOf(1) 118 expect(res.body.data).to.have.lengthOf(1)
113 } 119 }
114 120
115 // Kill server 1 121 // Kill server 2
116 killallServers([ servers[1] ]) 122 killallServers([ servers[1] ])
117 123
118 let resVideo = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, unlistedVideoAttributes)
119 videos.push(resVideo.body.video)
120
121 // Remove server 2 follower 124 // Remove server 2 follower
122 for (let i = 0; i < 10; i++) { 125 for (let i = 0; i < 10; i++) {
123 resVideo = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, videoAttributes) 126 await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, videoAttributes)
124 videos.push(resVideo.body.video)
125 } 127 }
126 128
127 await waitJobs(servers[0]) 129 await waitJobs(servers[0])
128 130
129 await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, videoAttributes) 131 // Kill server 3
132 killallServers([ servers[2] ])
133
134 const resLastVideo1 = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, videoAttributes)
135 missedVideo1 = resLastVideo1.body.video
136
137 const resLastVideo2 = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, videoAttributes)
138 missedVideo2 = resLastVideo2.body.video
139
140 // Unlisted video
141 let resVideo = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, unlistedVideoAttributes)
142 unlistedVideo = resVideo.body.video
130 143
131 // Add comments to video 2 144 // Add comments to video 2
132 { 145 {
133 const text = 'thread 1' 146 const text = 'thread 1'
134 let resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, videos[1].uuid, text) 147 let resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, missedVideo2.uuid, text)
135 let comment = resComment.body.comment 148 let comment = resComment.body.comment
136 threadIdServer1 = comment.id 149 threadIdServer1 = comment.id
137 150
138 resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, videos[1].uuid, comment.id, 'comment 1-1') 151 resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, missedVideo2.uuid, comment.id, 'comment 1-1')
139 comment = resComment.body.comment 152 comment = resComment.body.comment
140 153
141 resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, videos[1].uuid, comment.id, 'comment 1-2') 154 resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, missedVideo2.uuid, comment.id, 'comment 1-2')
142 commentIdServer1 = resComment.body.comment.id 155 commentIdServer1 = resComment.body.comment.id
143 } 156 }
144 157
@@ -146,9 +159,11 @@ describe('Test handle downs', function () {
146 // Wait scheduler 159 // Wait scheduler
147 await wait(11000) 160 await wait(11000)
148 161
149 const res = await getFollowersListPaginationAndSort(servers[0].url, 0, 1, 'createdAt') 162 // Only server 3 is still a follower of server 1
163 const res = await getFollowersListPaginationAndSort(servers[0].url, 0, 2, 'createdAt')
150 expect(res.body.data).to.be.an('array') 164 expect(res.body.data).to.be.an('array')
151 expect(res.body.data).to.have.lengthOf(0) 165 expect(res.body.data).to.have.lengthOf(1)
166 expect(res.body.data[0].follower.host).to.equal('localhost:9003')
152 }) 167 })
153 168
154 it('Should not have pending/processing jobs anymore', async function () { 169 it('Should not have pending/processing jobs anymore', async function () {
@@ -160,58 +175,66 @@ describe('Test handle downs', function () {
160 } 175 }
161 }) 176 })
162 177
163 it('Should follow server 1', async function () { 178 it('Should re-follow server 1', async function () {
164 this.timeout(15000) 179 this.timeout(15000)
165 180
166 await reRunServer(servers[1]) 181 await reRunServer(servers[1])
182 await reRunServer(servers[2])
183
184 await unfollow(servers[1].url, servers[1].accessToken, servers[0])
185 await waitJobs(servers)
167 186
168 await follow(servers[1].url, [ servers[0].url ], servers[1].accessToken) 187 await follow(servers[1].url, [ servers[0].url ], servers[1].accessToken)
169 188
170 await waitJobs(servers) 189 await waitJobs(servers)
171 190
172 const res = await getFollowersListPaginationAndSort(servers[0].url, 0, 1, 'createdAt') 191 const res = await getFollowersListPaginationAndSort(servers[0].url, 0, 2, 'createdAt')
173 expect(res.body.data).to.be.an('array') 192 expect(res.body.data).to.be.an('array')
174 expect(res.body.data).to.have.lengthOf(1) 193 expect(res.body.data).to.have.lengthOf(2)
175 }) 194 })
176 195
177 it('Should send a view to server 2, and automatically fetch the video', async function () { 196 it('Should send a view to server 3, and automatically fetch the video', async function () {
178 this.timeout(15000) 197 this.timeout(15000)
179 198
180 await viewVideo(servers[0].url, videos[0].uuid) 199 const res1 = await getVideosList(servers[2].url)
200 expect(res1.body.data).to.be.an('array')
201 expect(res1.body.data).to.have.lengthOf(11)
202
203 await viewVideo(servers[0].url, missedVideo1.uuid)
204 await viewVideo(servers[0].url, unlistedVideo.uuid)
181 205
182 await waitJobs(servers) 206 await waitJobs(servers)
183 207
184 const res = await getVideosList(servers[1].url) 208 const res = await getVideosList(servers[2].url)
185 expect(res.body.data).to.be.an('array') 209 expect(res.body.data).to.be.an('array')
186 // Video is unlisted 210 // 1 video is unlisted
187 expect(res.body.data).to.have.lengthOf(1) 211 expect(res.body.data).to.have.lengthOf(12)
188 212
189 const resVideo = await getVideo(servers[1].url, videos[0].uuid) 213 // Check unlisted video
214 const resVideo = await getVideo(servers[2].url, unlistedVideo.uuid)
190 expect(resVideo.body).not.to.be.undefined 215 expect(resVideo.body).not.to.be.undefined
191 216
192 await completeVideoCheck(servers[1].url, resVideo.body, unlistedCheckAttributes) 217 await completeVideoCheck(servers[2].url, resVideo.body, unlistedCheckAttributes)
193 }) 218 })
194 219
195 it('Should send comments on a video to server 2, and automatically fetch the video', async function () { 220 it('Should send comments on a video to server 3, and automatically fetch the video', async function () {
196 this.timeout(25000) 221 this.timeout(25000)
197 222
198 await addVideoCommentReply(servers[0].url, servers[0].accessToken, videos[1].uuid, commentIdServer1, 'comment 1-3') 223 await addVideoCommentReply(servers[0].url, servers[0].accessToken, missedVideo2.uuid, commentIdServer1, 'comment 1-3')
199 224
200 await waitJobs(servers) 225 await waitJobs(servers)
201 226
202 const resVideo = await getVideo(servers[1].url, videos[0].uuid) 227 const resVideo = await getVideo(servers[2].url, missedVideo2.uuid)
203 expect(resVideo.body).not.to.be.undefined 228 expect(resVideo.body).not.to.be.undefined
204 229
205 await completeVideoCheck(servers[1].url, resVideo.body, unlistedCheckAttributes)
206
207 { 230 {
208 let resComment = await getVideoCommentThreads(servers[1].url, videos[1].uuid, 0, 5) 231 let resComment = await getVideoCommentThreads(servers[2].url, missedVideo2.uuid, 0, 5)
209 expect(resComment.body.data).to.be.an('array') 232 expect(resComment.body.data).to.be.an('array')
210 expect(resComment.body.data).to.have.lengthOf(1) 233 expect(resComment.body.data).to.have.lengthOf(1)
211 234
212 threadIdServer2 = resComment.body.data[0].id 235 threadIdServer2 = resComment.body.data[0].id
213 236
214 resComment = await getVideoThreadComments(servers[1].url, videos[1].uuid, threadIdServer2) 237 resComment = await getVideoThreadComments(servers[2].url, missedVideo2.uuid, threadIdServer2)
215 238
216 const tree: VideoCommentThreadTree = resComment.body 239 const tree: VideoCommentThreadTree = resComment.body
217 expect(tree.comment.text).equal('thread 1') 240 expect(tree.comment.text).equal('thread 1')
@@ -236,12 +259,12 @@ describe('Test handle downs', function () {
236 it('Should correctly reply to the comment', async function () { 259 it('Should correctly reply to the comment', async function () {
237 this.timeout(15000) 260 this.timeout(15000)
238 261
239 await addVideoCommentReply(servers[1].url, servers[1].accessToken, videos[1].uuid, commentIdServer2, 'comment 1-4') 262 await addVideoCommentReply(servers[2].url, servers[2].accessToken, missedVideo2.uuid, commentIdServer2, 'comment 1-4')
240 263
241 await waitJobs(servers) 264 await waitJobs(servers)
242 265
243 { 266 {
244 const resComment = await getVideoThreadComments(servers[0].url, videos[1].uuid, threadIdServer1) 267 const resComment = await getVideoThreadComments(servers[0].url, missedVideo2.uuid, threadIdServer1)
245 268
246 const tree: VideoCommentThreadTree = resComment.body 269 const tree: VideoCommentThreadTree = resComment.body
247 expect(tree.comment.text).equal('thread 1') 270 expect(tree.comment.text).equal('thread 1')