aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/api/friendsAdvanced.js
diff options
context:
space:
mode:
Diffstat (limited to 'tests/api/friendsAdvanced.js')
-rw-r--r--tests/api/friendsAdvanced.js424
1 files changed, 211 insertions, 213 deletions
diff --git a/tests/api/friendsAdvanced.js b/tests/api/friendsAdvanced.js
index 61483bee6..9838d890f 100644
--- a/tests/api/friendsAdvanced.js
+++ b/tests/api/friendsAdvanced.js
@@ -1,252 +1,250 @@
1;(function () { 1'use strict'
2 'use strict'
3 2
4 var async = require('async') 3var async = require('async')
5 var chai = require('chai') 4var chai = require('chai')
6 var expect = chai.expect 5var expect = chai.expect
7 6
8 var utils = require('./utils') 7var utils = require('./utils')
9 8
10 describe('Test advanced friends', function () { 9describe('Test advanced friends', function () {
11 var apps = [] 10 var apps = []
12 var urls = [] 11 var urls = []
13 12
14 function makeFriends (pod_number, callback) { 13 function makeFriends (pod_number, callback) {
15 return utils.makeFriends(urls[pod_number - 1], callback) 14 return utils.makeFriends(urls[pod_number - 1], callback)
16 } 15 }
17 16
18 function quitFriends (pod_number, callback) { 17 function quitFriends (pod_number, callback) {
19 return utils.quitFriends(urls[pod_number - 1], callback) 18 return utils.quitFriends(urls[pod_number - 1], callback)
20 } 19 }
21 20
22 function getFriendsList (pod_number, end) { 21 function getFriendsList (pod_number, end) {
23 return utils.getFriendsList(urls[pod_number - 1], end) 22 return utils.getFriendsList(urls[pod_number - 1], end)
24 } 23 }
25 24
26 function uploadVideo (pod_number, callback) { 25 function uploadVideo (pod_number, callback) {
27 var name = 'my super video' 26 var name = 'my super video'
28 var description = 'my super description' 27 var description = 'my super description'
29 var fixture = 'video_short.webm' 28 var fixture = 'video_short.webm'
30 29
31 return utils.uploadVideo(urls[pod_number - 1], name, description, fixture, callback) 30 return utils.uploadVideo(urls[pod_number - 1], name, description, fixture, callback)
32 } 31 }
33 32
34 function getVideos (pod_number, callback) { 33 function getVideos (pod_number, callback) {
35 return utils.getVideosList(urls[pod_number - 1], callback) 34 return utils.getVideosList(urls[pod_number - 1], callback)
36 } 35 }
37 36
38 // --------------------------------------------------------------- 37 // ---------------------------------------------------------------
39 38
40 before(function (done) { 39 before(function (done) {
41 this.timeout(30000) 40 this.timeout(30000)
42 utils.flushAndRunMultipleServers(6, function (apps_run, urls_run) { 41 utils.flushAndRunMultipleServers(6, function (apps_run, urls_run) {
43 apps = apps_run 42 apps = apps_run
44 urls = urls_run 43 urls = urls_run
45 done() 44 done()
46 })
47 }) 45 })
46 })
48 47
49 it('Should make friends with two pod each in a different group', function (done) { 48 it('Should make friends with two pod each in a different group', function (done) {
50 this.timeout(20000) 49 this.timeout(20000)
51 50
52 async.series([ 51 async.series([
53 // Pod 3 makes friend with the first one 52 // Pod 3 makes friend with the first one
54 function (next) { 53 function (next) {
55 makeFriends(3, next) 54 makeFriends(3, next)
56 }, 55 },
57 // Pod 4 makes friend with the second one 56 // Pod 4 makes friend with the second one
58 function (next) { 57 function (next) {
59 makeFriends(4, next) 58 makeFriends(4, next)
60 }, 59 },
61 // Now if the fifth wants to make friends with the third et the first 60 // Now if the fifth wants to make friends with the third et the first
62 function (next) { 61 function (next) {
63 makeFriends(5, next) 62 makeFriends(5, next)
64 }, 63 },
65 function (next) { 64 function (next) {
66 setTimeout(next, 11000) 65 setTimeout(next, 11000)
67 }], 66 }],
68 function (err) { 67 function (err) {
68 if (err) throw err
69
70 // It should have 0 friends
71 getFriendsList(5, function (err, res) {
69 if (err) throw err 72 if (err) throw err
70 73
71 // It should have 0 friends 74 expect(res.body.length).to.equal(0)
72 getFriendsList(5, function (err, res) { 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) {
73 if (err) throw err 97 if (err) throw err
74 98
75 expect(res.body.length).to.equal(0) 99 expect(res.body.length).to.equal(0)
76 100
77 done() 101 callback()
78 }) 102 })
79 } 103 }, done)
80 ) 104 }
81 }) 105 )
106 })
82 107
83 it('Should quit all friends', function (done) { 108 it('Should make friends with the pods 1, 2, 3', function (done) {
84 this.timeout(10000) 109 this.timeout(150000)
85 110
86 async.series([ 111 async.series([
87 function (next) { 112 // Pods 1, 2, 3 and 4 become friends
88 quitFriends(1, next) 113 function (next) {
89 }, 114 makeFriends(2, next)
90 function (next) { 115 },
91 quitFriends(2, next) 116 function (next) {
92 }], 117 makeFriends(1, next)
93 function (err) { 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) {
94 if (err) throw err 155 if (err) throw err
95 156
96 async.each([ 1, 2, 3, 4, 5, 6 ], function (i, callback) { 157 // Pod 4 didn't know pod 1 and 2 removed it
97 getFriendsList(i, function (err, res) { 158 expect(res.body.length).to.equal(3)
98 if (err) throw err
99
100 expect(res.body.length).to.equal(0)
101 159
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() 160 next()
127 }, 161 })
128 // Expulse pod 4 from pod 1 and 2 162 },
129 function (next) { 163 // Pod 6 ask pod 1, 2 and 3
130 uploadVideo(1, next) 164 function (next) {
131 }, 165 makeFriends(6, next)
132 function (next) { 166 }],
133 uploadVideo(2, next) 167 function (err) {
134 }, 168 if (err) throw err
135 function (next) { 169
136 setTimeout(next, 11000) 170 getFriendsList(6, function (err, res) {
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 171 if (err) throw err
170 172
171 getFriendsList(6, function (err, res) { 173 // Pod 4 should not be our friend
172 if (err) throw err 174 var result = res.body
175 expect(result.length).to.equal(3)
176 for (var pod of result) {
177 expect(pod.url).not.equal(urls[3])
178 }
173 179
174 // Pod 4 should not be our friend 180 done()
175 var result = res.body 181 })
176 expect(result.length).to.equal(3) 182 }
177 for (var pod of result) { 183 )
178 expect(pod.url).not.equal(urls[3]) 184 })
179 }
180 185
181 done() 186 it('Should pod 1 quit friends', function (done) {
182 }) 187 this.timeout(25000)
183 } 188
184 ) 189 async.series([
185 }) 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)
186 206
187 it('Should pod 1 quit friends', function (done) { 207 next()
188 this.timeout(25000) 208 })
189 209 }],
190 async.series([ 210 function (err) {
191 // Upload a video on server 3 for aditionnal tests 211 if (err) throw err
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 212
208 next() 213 getVideos(2, function (err, res) {
209 })
210 }],
211 function (err) {
212 if (err) throw err 214 if (err) throw err
215 expect(res.body).to.be.an('array')
216 expect(res.body.length).to.equal(3)
217 done()
218 })
219 }
220 )
221 })
213 222
214 getVideos(2, function (err, res) { 223 it('Should make friends between pod 1 and 2 and exchange their videos', function (done) {
215 if (err) throw err 224 this.timeout(20000)
216 expect(res.body).to.be.an('array') 225 makeFriends(1, function () {
217 expect(res.body.length).to.equal(3) 226 setTimeout(function () {
218 done() 227 getVideos(1, function (err, res) {
219 }) 228 if (err) throw err
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 229
231 expect(res.body).to.be.an('array') 230 expect(res.body).to.be.an('array')
232 expect(res.body.length).to.equal(5) 231 expect(res.body.length).to.equal(5)
233 232
234 done() 233 done()
235 }) 234 })
236 }, 5000) 235 }, 5000)
237 })
238 }) 236 })
237 })
239 238
240 after(function (done) { 239 after(function (done) {
241 apps.forEach(function (app) { 240 apps.forEach(function (app) {
242 process.kill(-app.pid) 241 process.kill(-app.pid)
243 })
244
245 if (this.ok) {
246 utils.flushTests(done)
247 } else {
248 done()
249 }
250 }) 242 })
243
244 if (this.ok) {
245 utils.flushTests(done)
246 } else {
247 done()
248 }
251 }) 249 })
252})() 250})