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