diff options
Diffstat (limited to 'test/api')
-rw-r--r-- | test/api/friendsAdvanced.js | 68 | ||||
-rw-r--r-- | test/api/multiplePods.js | 131 |
2 files changed, 124 insertions, 75 deletions
diff --git a/test/api/friendsAdvanced.js b/test/api/friendsAdvanced.js index ccddac4dc..680d90aee 100644 --- a/test/api/friendsAdvanced.js +++ b/test/api/friendsAdvanced.js | |||
@@ -103,9 +103,9 @@ | |||
103 | }) | 103 | }) |
104 | 104 | ||
105 | it('Should make friends with the pods 1, 2, 3', function (done) { | 105 | it('Should make friends with the pods 1, 2, 3', function (done) { |
106 | this.timeout(100000) | 106 | this.timeout(150000) |
107 | 107 | ||
108 | // Pods 1, 2, 3 and 4 become friends | 108 | // Pods 1, 2, 3 and 4 become friends (yes this is beautiful) |
109 | makeFriend(2, function () { | 109 | makeFriend(2, function () { |
110 | makeFriend(1, function () { | 110 | makeFriend(1, function () { |
111 | makeFriend(4, function () { | 111 | makeFriend(4, function () { |
@@ -114,37 +114,45 @@ | |||
114 | 114 | ||
115 | // Expulse pod 4 from pod 1 and 2 | 115 | // Expulse pod 4 from pod 1 and 2 |
116 | uploadVideo(1, function () { | 116 | uploadVideo(1, function () { |
117 | uploadVideo(1, function () { | 117 | setTimeout(function () { |
118 | uploadVideo(2, function () { | 118 | uploadVideo(1, function () { |
119 | uploadVideo(2, function () { | 119 | setTimeout(function () { |
120 | // Rerun server 4 | 120 | uploadVideo(2, function () { |
121 | utils.runServer(4, function (app, url) { | 121 | setTimeout(function () { |
122 | apps[3] = app | 122 | uploadVideo(2, function () { |
123 | getFriendsList(4, function (err, res) { | 123 | setTimeout(function () { |
124 | if (err) throw err | 124 | // Rerun server 4 |
125 | // Pod 4 didn't know pod 1 and 2 removed it | 125 | utils.runServer(4, function (app, url) { |
126 | expect(res.body.length).to.equal(3) | 126 | apps[3] = app |
127 | 127 | getFriendsList(4, function (err, res) { | |
128 | // Pod 6 ask pod 1, 2 and 3 | 128 | if (err) throw err |
129 | makeFriend(6, function () { | 129 | // Pod 4 didn't know pod 1 and 2 removed it |
130 | getFriendsList(6, function (err, res) { | 130 | expect(res.body.length).to.equal(3) |
131 | if (err) throw err | 131 | |
132 | 132 | // Pod 6 ask pod 1, 2 and 3 | |
133 | // Pod 4 should not be our friend | 133 | makeFriend(6, function () { |
134 | var result = res.body | 134 | getFriendsList(6, function (err, res) { |
135 | expect(result.length).to.equal(3) | 135 | if (err) throw err |
136 | for (var pod of result) { | 136 | |
137 | expect(pod.url).not.equal(urls[3]) | 137 | // Pod 4 should not be our friend |
138 | } | 138 | var result = res.body |
139 | 139 | expect(result.length).to.equal(3) | |
140 | done() | 140 | for (var pod of result) { |
141 | }) | 141 | expect(pod.url).not.equal(urls[3]) |
142 | } | ||
143 | |||
144 | done() | ||
145 | }) | ||
146 | }) | ||
147 | }) | ||
148 | }) | ||
149 | }, 11000) | ||
142 | }) | 150 | }) |
143 | }) | 151 | }, 11000) |
144 | }) | 152 | }) |
145 | }) | 153 | }, 11000) |
146 | }) | 154 | }) |
147 | }) | 155 | }, 11000) |
148 | }) | 156 | }) |
149 | }) | 157 | }) |
150 | }) | 158 | }) |
diff --git a/test/api/multiplePods.js b/test/api/multiplePods.js index 1edfc1ce3..3ce57afa8 100644 --- a/test/api/multiplePods.js +++ b/test/api/multiplePods.js | |||
@@ -14,7 +14,7 @@ | |||
14 | var path = '/api/v1/videos' | 14 | var path = '/api/v1/videos' |
15 | var apps = [] | 15 | var apps = [] |
16 | var urls = [] | 16 | var urls = [] |
17 | var video_id = -1 | 17 | var to_remove = [] |
18 | 18 | ||
19 | function getVideosList (url, end) { | 19 | function getVideosList (url, end) { |
20 | request(url) | 20 | request(url) |
@@ -36,6 +36,14 @@ | |||
36 | .end(end) | 36 | .end(end) |
37 | } | 37 | } |
38 | 38 | ||
39 | function removeVideo (url, id, end) { | ||
40 | request(url) | ||
41 | .delete(path + '/' + id) | ||
42 | .set('Accept', 'application/json') | ||
43 | .expect(204) | ||
44 | .end(end) | ||
45 | } | ||
46 | |||
39 | before(function (done) { | 47 | before(function (done) { |
40 | this.timeout(30000) | 48 | this.timeout(30000) |
41 | var path_friends = '/api/v1/pods/makefriends' | 49 | var path_friends = '/api/v1/pods/makefriends' |
@@ -89,7 +97,7 @@ | |||
89 | 97 | ||
90 | describe('Should upload the video and propagate on each pod', function () { | 98 | describe('Should upload the video and propagate on each pod', function () { |
91 | it('Should upload the video on pod 1 and propagate on each pod', function (done) { | 99 | it('Should upload the video on pod 1 and propagate on each pod', function (done) { |
92 | this.timeout(5000) | 100 | this.timeout(15000) |
93 | 101 | ||
94 | uploadVideo(urls[0], 'my super name for pod 1', 'my super description for pod 1', 'video_short1.webm', function (err) { | 102 | uploadVideo(urls[0], 'my super name for pod 1', 'my super description for pod 1', 'video_short1.webm', function (err) { |
95 | if (err) throw err | 103 | if (err) throw err |
@@ -125,12 +133,12 @@ | |||
125 | 133 | ||
126 | done() | 134 | done() |
127 | }) | 135 | }) |
128 | }, 1000) | 136 | }, 11000) |
129 | }) | 137 | }) |
130 | }) | 138 | }) |
131 | 139 | ||
132 | it('Should upload the video on pod 2 and propagate on each pod', function (done) { | 140 | it('Should upload the video on pod 2 and propagate on each pod', function (done) { |
133 | this.timeout(5000) | 141 | this.timeout(15000) |
134 | 142 | ||
135 | uploadVideo(urls[1], 'my super name for pod 2', 'my super description for pod 2', 'video_short2.webm', function (err) { | 143 | uploadVideo(urls[1], 'my super name for pod 2', 'my super description for pod 2', 'video_short2.webm', function (err) { |
136 | if (err) throw err | 144 | if (err) throw err |
@@ -166,47 +174,56 @@ | |||
166 | 174 | ||
167 | done() | 175 | done() |
168 | }) | 176 | }) |
169 | }, 1000) | 177 | }, 11000) |
170 | }) | 178 | }) |
171 | }) | 179 | }) |
172 | 180 | ||
173 | it('Should upload the video on pod 3 and propagate on each pod', function (done) { | 181 | it('Should upload two videos on pod 3 and propagate on each pod', function (done) { |
174 | this.timeout(5000) | 182 | this.timeout(15000) |
175 | 183 | ||
176 | uploadVideo(urls[2], 'my super name for pod 3', 'my super description for pod 3', 'video_short3.webm', function (err) { | 184 | uploadVideo(urls[2], 'my super name for pod 3', 'my super description for pod 3', 'video_short3.webm', function (err) { |
177 | if (err) throw err | 185 | if (err) throw err |
186 | uploadVideo(urls[2], 'my super name for pod 3-2', 'my super description for pod 3-2', 'video_short.webm', function (err) { | ||
187 | if (err) throw err | ||
178 | 188 | ||
179 | setTimeout(function () { | 189 | setTimeout(function () { |
180 | var base_magnet = null | 190 | var base_magnet = null |
181 | // All pods should have this video | 191 | // All pods should have this video |
182 | async.each(urls, function (url, callback) { | 192 | async.each(urls, function (url, callback) { |
183 | getVideosList(url, function (err, res) { | 193 | getVideosList(url, function (err, res) { |
184 | if (err) throw err | 194 | if (err) throw err |
185 | |||
186 | var videos = res.body | ||
187 | expect(videos).to.be.an('array') | ||
188 | expect(videos.length).to.equal(3) | ||
189 | var video = videos[2] | ||
190 | expect(video.name).to.equal('my super name for pod 3') | ||
191 | expect(video.description).to.equal('my super description for pod 3') | ||
192 | expect(video.podUrl).to.equal('http://localhost:9003') | ||
193 | expect(video.magnetUri).to.exist | ||
194 | 195 | ||
195 | // All pods should have the same magnet Uri | 196 | var videos = res.body |
196 | if (base_magnet === null) { | 197 | expect(videos).to.be.an('array') |
197 | base_magnet = video.magnetUri | 198 | expect(videos.length).to.equal(4) |
198 | } else { | 199 | var video = videos[2] |
199 | expect(video.magnetUri).to.equal.magnetUri | 200 | expect(video.name).to.equal('my super name for pod 3') |
200 | } | 201 | expect(video.description).to.equal('my super description for pod 3') |
202 | expect(video.podUrl).to.equal('http://localhost:9003') | ||
203 | expect(video.magnetUri).to.exist | ||
204 | |||
205 | video = videos[3] | ||
206 | expect(video.name).to.equal('my super name for pod 3-2') | ||
207 | expect(video.description).to.equal('my super description for pod 3-2') | ||
208 | expect(video.podUrl).to.equal('http://localhost:9003') | ||
209 | expect(video.magnetUri).to.exist | ||
210 | |||
211 | // All pods should have the same magnet Uri | ||
212 | if (base_magnet === null) { | ||
213 | base_magnet = video.magnetUri | ||
214 | } else { | ||
215 | expect(video.magnetUri).to.equal.magnetUri | ||
216 | } | ||
217 | |||
218 | callback() | ||
219 | }) | ||
220 | }, function (err) { | ||
221 | if (err) throw err | ||
201 | 222 | ||
202 | callback() | 223 | done() |
203 | }) | 224 | }) |
204 | }, function (err) { | 225 | }, 11000) |
205 | if (err) throw err | 226 | }) |
206 | |||
207 | done() | ||
208 | }) | ||
209 | }, 1000) | ||
210 | }) | 227 | }) |
211 | }) | 228 | }) |
212 | }) | 229 | }) |
@@ -220,6 +237,9 @@ | |||
220 | if (err) throw err | 237 | if (err) throw err |
221 | 238 | ||
222 | var video = res.body[0] | 239 | var video = res.body[0] |
240 | to_remove.push(res.body[2]._id) | ||
241 | to_remove.push(res.body[3]._id) | ||
242 | |||
223 | webtorrent.add(video.magnetUri, function (torrent) { | 243 | webtorrent.add(video.magnetUri, function (torrent) { |
224 | expect(torrent.files).to.exist | 244 | expect(torrent.files).to.exist |
225 | expect(torrent.files.length).to.equal(1) | 245 | expect(torrent.files.length).to.equal(1) |
@@ -257,7 +277,6 @@ | |||
257 | if (err) throw err | 277 | if (err) throw err |
258 | 278 | ||
259 | var video = res.body[2] | 279 | var video = res.body[2] |
260 | video_id = res.body[1]._id | ||
261 | 280 | ||
262 | webtorrent.add(video.magnetUri, function (torrent) { | 281 | webtorrent.add(video.magnetUri, function (torrent) { |
263 | expect(torrent.files).to.exist | 282 | expect(torrent.files).to.exist |
@@ -269,19 +288,39 @@ | |||
269 | }) | 288 | }) |
270 | }) | 289 | }) |
271 | 290 | ||
272 | it('Should remove the file 2 by asking pod 2', function (done) { | 291 | it('Should add the file 3-2 by asking pod 1', function (done) { |
273 | request(urls[1]) | 292 | // Yes, this could be long |
274 | .delete(path + '/' + video_id) | 293 | this.timeout(200000) |
275 | .set('Accept', 'application/json') | 294 | |
276 | .expect(204) | 295 | getVideosList(urls[0], function (err, res) { |
277 | .end(function (err, res) { | 296 | if (err) throw err |
297 | |||
298 | var video = res.body[3] | ||
299 | |||
300 | webtorrent.add(video.magnetUri, function (torrent) { | ||
301 | expect(torrent.files).to.exist | ||
302 | expect(torrent.files.length).to.equal(1) | ||
303 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | ||
304 | |||
305 | done() | ||
306 | }) | ||
307 | }) | ||
308 | }) | ||
309 | |||
310 | it('Should remove the file 3 and 3-2 by asking pod 3', function (done) { | ||
311 | this.timeout(15000) | ||
312 | |||
313 | removeVideo(urls[2], to_remove[0], function (err) { | ||
314 | if (err) throw err | ||
315 | removeVideo(urls[2], to_remove[1], function (err) { | ||
278 | if (err) throw err | 316 | if (err) throw err |
279 | 317 | ||
280 | // Wait the propagation to the other pods | 318 | // Wait the propagation to the other pods |
281 | setTimeout(function () { | 319 | setTimeout(function () { |
282 | done() | 320 | done() |
283 | }, 1000) | 321 | }, 11000) |
284 | }) | 322 | }) |
323 | }) | ||
285 | }) | 324 | }) |
286 | 325 | ||
287 | it('Should have videos 1 and 3 on each pod', function (done) { | 326 | it('Should have videos 1 and 3 on each pod', function (done) { |
@@ -293,8 +332,10 @@ | |||
293 | expect(videos).to.be.an('array') | 332 | expect(videos).to.be.an('array') |
294 | expect(videos.length).to.equal(2) | 333 | expect(videos.length).to.equal(2) |
295 | expect(videos[0]._id).not.to.equal(videos[1]._id) | 334 | expect(videos[0]._id).not.to.equal(videos[1]._id) |
296 | expect(videos[0]._id).not.to.equal(video_id) | 335 | expect(videos[0]._id).not.to.equal(to_remove[0]) |
297 | expect(videos[1]._id).not.to.equal(video_id) | 336 | expect(videos[1]._id).not.to.equal(to_remove[0]) |
337 | expect(videos[0]._id).not.to.equal(to_remove[1]) | ||
338 | expect(videos[1]._id).not.to.equal(to_remove[1]) | ||
298 | 339 | ||
299 | callback() | 340 | callback() |
300 | }) | 341 | }) |