]>
Commit | Line | Data |
---|---|---|
1 | 'use strict' | |
2 | ||
3 | const chai = require('chai') | |
4 | const each = require('async/each') | |
5 | const expect = chai.expect | |
6 | const series = require('async/series') | |
7 | ||
8 | const utils = require('./utils') | |
9 | ||
10 | describe('Test advanced friends', function () { | |
11 | let servers = [] | |
12 | ||
13 | function makeFriends (podNumber, callback) { | |
14 | const server = servers[podNumber - 1] | |
15 | return utils.makeFriends(server.url, server.accessToken, callback) | |
16 | } | |
17 | ||
18 | function quitFriends (podNumber, callback) { | |
19 | const server = servers[podNumber - 1] | |
20 | return utils.quitFriends(server.url, server.accessToken, callback) | |
21 | } | |
22 | ||
23 | function getFriendsList (podNumber, end) { | |
24 | const server = servers[podNumber - 1] | |
25 | return utils.getFriendsList(server.url, end) | |
26 | } | |
27 | ||
28 | function uploadVideo (podNumber, callback) { | |
29 | const name = 'my super video' | |
30 | const description = 'my super description' | |
31 | const tags = [ 'tag1', 'tag2' ] | |
32 | const fixture = 'video_short.webm' | |
33 | const server = servers[podNumber - 1] | |
34 | ||
35 | return utils.uploadVideo(server.url, server.accessToken, name, description, tags, fixture, callback) | |
36 | } | |
37 | ||
38 | function getVideos (podNumber, callback) { | |
39 | return utils.getVideosList(servers[podNumber - 1].url, callback) | |
40 | } | |
41 | ||
42 | // --------------------------------------------------------------- | |
43 | ||
44 | before(function (done) { | |
45 | this.timeout(30000) | |
46 | utils.flushAndRunMultipleServers(6, function (serversRun, urlsRun) { | |
47 | servers = serversRun | |
48 | ||
49 | each(servers, function (server, callbackEach) { | |
50 | utils.loginAndGetAccessToken(server, function (err, accessToken) { | |
51 | if (err) return callbackEach(err) | |
52 | ||
53 | server.accessToken = accessToken | |
54 | callbackEach() | |
55 | }) | |
56 | }, done) | |
57 | }) | |
58 | }) | |
59 | ||
60 | it('Should make friends with two pod each in a different group', function (done) { | |
61 | this.timeout(20000) | |
62 | ||
63 | series([ | |
64 | // Pod 3 makes friend with the first one | |
65 | function (next) { | |
66 | makeFriends(3, next) | |
67 | }, | |
68 | // Pod 4 makes friend with the second one | |
69 | function (next) { | |
70 | makeFriends(4, next) | |
71 | }, | |
72 | // Now if the fifth wants to make friends with the third et the first | |
73 | function (next) { | |
74 | makeFriends(5, next) | |
75 | }, | |
76 | function (next) { | |
77 | setTimeout(next, 11000) | |
78 | }], | |
79 | function (err) { | |
80 | if (err) throw err | |
81 | ||
82 | // It should have 0 friends | |
83 | getFriendsList(5, function (err, res) { | |
84 | if (err) throw err | |
85 | ||
86 | expect(res.body.length).to.equal(0) | |
87 | ||
88 | done() | |
89 | }) | |
90 | } | |
91 | ) | |
92 | }) | |
93 | ||
94 | it('Should quit all friends', function (done) { | |
95 | this.timeout(10000) | |
96 | ||
97 | series([ | |
98 | function (next) { | |
99 | quitFriends(1, next) | |
100 | }, | |
101 | function (next) { | |
102 | quitFriends(2, next) | |
103 | }], | |
104 | function (err) { | |
105 | if (err) throw err | |
106 | ||
107 | each([ 1, 2, 3, 4, 5, 6 ], function (i, callback) { | |
108 | getFriendsList(i, function (err, res) { | |
109 | if (err) throw err | |
110 | ||
111 | expect(res.body.length).to.equal(0) | |
112 | ||
113 | callback() | |
114 | }) | |
115 | }, done) | |
116 | } | |
117 | ) | |
118 | }) | |
119 | ||
120 | it('Should make friends with the pods 1, 2, 3', function (done) { | |
121 | this.timeout(150000) | |
122 | ||
123 | series([ | |
124 | // Pods 1, 2, 3 and 4 become friends | |
125 | function (next) { | |
126 | makeFriends(2, next) | |
127 | }, | |
128 | function (next) { | |
129 | makeFriends(1, next) | |
130 | }, | |
131 | function (next) { | |
132 | makeFriends(4, next) | |
133 | }, | |
134 | // Check the pods 1, 2, 3 and 4 are friends | |
135 | function (next) { | |
136 | each([ 1, 2, 3, 4 ], function (i, callback) { | |
137 | getFriendsList(i, function (err, res) { | |
138 | if (err) throw err | |
139 | ||
140 | expect(res.body.length).to.equal(3) | |
141 | ||
142 | callback() | |
143 | }) | |
144 | }, next) | |
145 | }, | |
146 | // Kill pod 4 | |
147 | function (next) { | |
148 | servers[3].app.kill() | |
149 | next() | |
150 | }, | |
151 | // Expulse pod 4 from pod 1 and 2 | |
152 | function (next) { | |
153 | uploadVideo(1, next) | |
154 | }, | |
155 | function (next) { | |
156 | uploadVideo(2, next) | |
157 | }, | |
158 | function (next) { | |
159 | setTimeout(next, 11000) | |
160 | }, | |
161 | function (next) { | |
162 | uploadVideo(1, next) | |
163 | }, | |
164 | function (next) { | |
165 | uploadVideo(2, next) | |
166 | }, | |
167 | function (next) { | |
168 | setTimeout(next, 11000) | |
169 | }, | |
170 | // Rerun server 4 | |
171 | function (next) { | |
172 | utils.runServer(4, function (server) { | |
173 | servers[3].app = server.app | |
174 | next() | |
175 | }) | |
176 | }, | |
177 | function (next) { | |
178 | getFriendsList(4, function (err, res) { | |
179 | if (err) throw err | |
180 | ||
181 | // Pod 4 didn't know pod 1 and 2 removed it | |
182 | expect(res.body.length).to.equal(3) | |
183 | next() | |
184 | }) | |
185 | }, | |
186 | // Pod 6 ask pod 1, 2 and 3 | |
187 | function (next) { | |
188 | makeFriends(6, next) | |
189 | }, | |
190 | function (next) { | |
191 | setTimeout(next, 11000) | |
192 | }], | |
193 | function (err) { | |
194 | if (err) throw err | |
195 | ||
196 | getFriendsList(6, function (err, res) { | |
197 | if (err) throw err | |
198 | ||
199 | // Pod 4 should not be our friend | |
200 | const result = res.body | |
201 | expect(result.length).to.equal(3) | |
202 | for (const pod of result) { | |
203 | expect(pod.url).not.equal(servers[3].url) | |
204 | } | |
205 | ||
206 | done() | |
207 | }) | |
208 | } | |
209 | ) | |
210 | }) | |
211 | ||
212 | it('Should pod 1 quit friends', function (done) { | |
213 | this.timeout(25000) | |
214 | ||
215 | series([ | |
216 | // Upload a video on server 3 for aditionnal tests | |
217 | function (next) { | |
218 | uploadVideo(3, next) | |
219 | }, | |
220 | function (next) { | |
221 | setTimeout(next, 15000) | |
222 | }, | |
223 | function (next) { | |
224 | quitFriends(1, next) | |
225 | }, | |
226 | // Remove pod 1 from pod 2 | |
227 | function (next) { | |
228 | getVideos(1, function (err, res) { | |
229 | if (err) throw err | |
230 | ||
231 | const videos = res.body.data | |
232 | expect(videos).to.be.an('array') | |
233 | expect(videos.length).to.equal(2) | |
234 | ||
235 | next() | |
236 | }) | |
237 | }], | |
238 | function (err) { | |
239 | if (err) throw err | |
240 | ||
241 | getVideos(2, function (err, res) { | |
242 | if (err) throw err | |
243 | ||
244 | const videos = res.body.data | |
245 | expect(videos).to.be.an('array') | |
246 | expect(videos.length).to.equal(3) | |
247 | done() | |
248 | }) | |
249 | } | |
250 | ) | |
251 | }) | |
252 | ||
253 | it('Should make friends between pod 1 and 2 and exchange their videos', function (done) { | |
254 | this.timeout(20000) | |
255 | makeFriends(1, function () { | |
256 | setTimeout(function () { | |
257 | getVideos(1, function (err, res) { | |
258 | if (err) throw err | |
259 | ||
260 | const videos = res.body.data | |
261 | expect(videos).to.be.an('array') | |
262 | expect(videos.length).to.equal(5) | |
263 | ||
264 | done() | |
265 | }) | |
266 | }, 11000) | |
267 | }) | |
268 | }) | |
269 | ||
270 | after(function (done) { | |
271 | servers.forEach(function (server) { | |
272 | process.kill(-server.app.pid) | |
273 | }) | |
274 | ||
275 | if (this.ok) { | |
276 | utils.flushTests(done) | |
277 | } else { | |
278 | done() | |
279 | } | |
280 | }) | |
281 | }) |