]>
Commit | Line | Data |
---|---|---|
9f10b292 | 1 | 'use strict' |
3bcb78b3 | 2 | |
f0f5567b C |
3 | const async = require('async') |
4 | const chai = require('chai') | |
5 | const expect = chai.expect | |
3bcb78b3 | 6 | |
f0f5567b | 7 | const utils = require('./utils') |
3bcb78b3 | 8 | |
9f10b292 | 9 | describe('Test advanced friends', function () { |
0c1cbbfe | 10 | let servers = [] |
3bcb78b3 | 11 | |
bc503c2a | 12 | function makeFriends (podNumber, callback) { |
b3b92647 C |
13 | const server = servers[podNumber - 1] |
14 | return utils.makeFriends(server.url, server.accessToken, callback) | |
9f10b292 | 15 | } |
45239549 | 16 | |
bc503c2a | 17 | function quitFriends (podNumber, callback) { |
b3b92647 C |
18 | const server = servers[podNumber - 1] |
19 | return utils.quitFriends(server.url, server.accessToken, callback) | |
9f10b292 | 20 | } |
3bcb78b3 | 21 | |
bc503c2a | 22 | function getFriendsList (podNumber, end) { |
b3b92647 C |
23 | const server = servers[podNumber - 1] |
24 | return utils.getFriendsList(server.url, end) | |
9f10b292 | 25 | } |
3bcb78b3 | 26 | |
bc503c2a | 27 | function uploadVideo (podNumber, callback) { |
f0f5567b C |
28 | const name = 'my super video' |
29 | const description = 'my super description' | |
30 | const fixture = 'video_short.webm' | |
bc503c2a | 31 | const server = servers[podNumber - 1] |
3bcb78b3 | 32 | |
b6c6f935 | 33 | return utils.uploadVideo(server.url, server.accessToken, name, description, fixture, callback) |
9f10b292 | 34 | } |
3bcb78b3 | 35 | |
bc503c2a C |
36 | function getVideos (podNumber, callback) { |
37 | return utils.getVideosList(servers[podNumber - 1].url, callback) | |
9f10b292 | 38 | } |
45239549 | 39 | |
9f10b292 | 40 | // --------------------------------------------------------------- |
ee66c593 | 41 | |
9f10b292 C |
42 | before(function (done) { |
43 | this.timeout(30000) | |
bc503c2a C |
44 | utils.flushAndRunMultipleServers(6, function (serversRun, urlsRun) { |
45 | servers = serversRun | |
0c1cbbfe | 46 | |
bc503c2a C |
47 | async.each(servers, function (server, callbackEach) { |
48 | utils.loginAndGetAccessToken(server, function (err, accessToken) { | |
49 | if (err) return callbackEach(err) | |
0c1cbbfe | 50 | |
bc503c2a C |
51 | server.accessToken = accessToken |
52 | callbackEach() | |
0c1cbbfe C |
53 | }) |
54 | }, done) | |
3bcb78b3 | 55 | }) |
9f10b292 | 56 | }) |
3bcb78b3 | 57 | |
9f10b292 C |
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) { | |
ee66c593 C |
82 | if (err) throw err |
83 | ||
9f10b292 C |
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) { | |
ee66c593 C |
107 | if (err) throw err |
108 | ||
109 | expect(res.body.length).to.equal(0) | |
110 | ||
9f10b292 | 111 | callback() |
3bcb78b3 | 112 | }) |
9f10b292 C |
113 | }, done) |
114 | } | |
115 | ) | |
116 | }) | |
3bcb78b3 | 117 | |
9f10b292 C |
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) { | |
0c1cbbfe | 134 | servers[3].app.kill() |
9f10b292 C |
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) { | |
0c1cbbfe C |
158 | utils.runServer(4, function (server) { |
159 | servers[3].app = server.app | |
9f10b292 C |
160 | next() |
161 | }) | |
162 | }, | |
163 | function (next) { | |
164 | getFriendsList(4, function (err, res) { | |
ee66c593 C |
165 | if (err) throw err |
166 | ||
9f10b292 C |
167 | // Pod 4 didn't know pod 1 and 2 removed it |
168 | expect(res.body.length).to.equal(3) | |
ee66c593 | 169 | next() |
9f10b292 C |
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) { | |
ee66c593 C |
180 | if (err) throw err |
181 | ||
9f10b292 | 182 | // Pod 4 should not be our friend |
f0f5567b | 183 | const result = res.body |
9f10b292 | 184 | expect(result.length).to.equal(3) |
f0f5567b | 185 | for (const pod of result) { |
0c1cbbfe | 186 | expect(pod.url).not.equal(servers[3].url) |
9f10b292 | 187 | } |
ee66c593 | 188 | |
9f10b292 C |
189 | done() |
190 | }) | |
191 | } | |
192 | ) | |
193 | }) | |
ee66c593 | 194 | |
9f10b292 C |
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 | |
68ce3ae0 C |
213 | |
214 | const videos = res.body.data | |
215 | expect(videos).to.be.an('array') | |
216 | expect(videos.length).to.equal(2) | |
45239549 | 217 | |
9f10b292 C |
218 | next() |
219 | }) | |
220 | }], | |
221 | function (err) { | |
222 | if (err) throw err | |
ee66c593 | 223 | |
9f10b292 | 224 | getVideos(2, function (err, res) { |
ee66c593 | 225 | if (err) throw err |
68ce3ae0 C |
226 | |
227 | const videos = res.body.data | |
228 | expect(videos).to.be.an('array') | |
229 | expect(videos.length).to.equal(3) | |
9f10b292 C |
230 | done() |
231 | }) | |
232 | } | |
233 | ) | |
234 | }) | |
ee66c593 | 235 | |
9f10b292 C |
236 | it('Should make friends between pod 1 and 2 and exchange their videos', function (done) { |
237 | this.timeout(20000) | |
238 | makeFriends(1, function () { | |
239 | setTimeout(function () { | |
240 | getVideos(1, function (err, res) { | |
241 | if (err) throw err | |
45239549 | 242 | |
68ce3ae0 C |
243 | const videos = res.body.data |
244 | expect(videos).to.be.an('array') | |
245 | expect(videos.length).to.equal(5) | |
45239549 | 246 | |
9f10b292 C |
247 | done() |
248 | }) | |
249 | }, 5000) | |
45239549 | 250 | }) |
9f10b292 | 251 | }) |
ee66c593 | 252 | |
9f10b292 | 253 | after(function (done) { |
0c1cbbfe C |
254 | servers.forEach(function (server) { |
255 | process.kill(-server.app.pid) | |
ee66c593 | 256 | }) |
9f10b292 C |
257 | |
258 | if (this.ok) { | |
259 | utils.flushTests(done) | |
260 | } else { | |
261 | done() | |
262 | } | |
3bcb78b3 | 263 | }) |
9f10b292 | 264 | }) |