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