]>
Commit | Line | Data |
---|---|---|
1 | ;(function () { | |
2 | 'use strict' | |
3 | ||
4 | var async = require('async') | |
5 | var chai = require('chai') | |
6 | var expect = chai.expect | |
7 | ||
8 | var utils = require('./utils') | |
9 | ||
10 | describe('Test advanced friends', function () { | |
11 | var apps = [] | |
12 | var urls = [] | |
13 | ||
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) | |
20 | } | |
21 | ||
22 | function getFriendsList (pod_number, end) { | |
23 | return utils.getFriendsList(urls[pod_number - 1], end) | |
24 | } | |
25 | ||
26 | function uploadVideo (pod_number, callback) { | |
27 | var name = 'my super video' | |
28 | var description = 'my super description' | |
29 | var fixture = 'video_short.webm' | |
30 | ||
31 | return utils.uploadVideo(urls[pod_number - 1], name, description, fixture, callback) | |
32 | } | |
33 | ||
34 | function getVideos (pod_number, callback) { | |
35 | return utils.getVideosList(urls[pod_number - 1], callback) | |
36 | } | |
37 | ||
38 | // --------------------------------------------------------------- | |
39 | ||
40 | before(function (done) { | |
41 | this.timeout(30000) | |
42 | utils.flushAndRunMultipleServers(6, function (apps_run, urls_run) { | |
43 | apps = apps_run | |
44 | urls = urls_run | |
45 | done() | |
46 | }) | |
47 | }) | |
48 | ||
49 | it('Should make friends with two pod each in a different group', function (done) { | |
50 | this.timeout(20000) | |
51 | ||
52 | async.series([ | |
53 | // Pod 3 makes friend with the first one | |
54 | function (next) { | |
55 | makeFriends(3, next) | |
56 | }, | |
57 | // Pod 4 makes friend with the second one | |
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() | |
78 | }) | |
79 | } | |
80 | ) | |
81 | }) | |
82 | ||
83 | it('Should quit all friends', function (done) { | |
84 | this.timeout(10000) | |
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 | ||
96 | async.each([ 1, 2, 3, 4, 5, 6 ], function (i, callback) { | |
97 | getFriendsList(i, function (err, res) { | |
98 | if (err) throw err | |
99 | ||
100 | expect(res.body.length).to.equal(0) | |
101 | ||
102 | callback() | |
103 | }) | |
104 | }, done) | |
105 | } | |
106 | ) | |
107 | }) | |
108 | ||
109 | it('Should make friends with the pods 1, 2, 3', function (done) { | |
110 | this.timeout(150000) | |
111 | ||
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() | |
152 | }) | |
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 | ) | |
185 | }) | |
186 | ||
187 | it('Should pod 1 quit friends', function (done) { | |
188 | this.timeout(25000) | |
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() | |
209 | }) | |
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 | ) | |
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 | }) | |
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 | }) | |
251 | }) | |
252 | })() |