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