aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-01-24 16:08:09 +0100
committerChocobozzz <florian.bigard@gmail.com>2016-01-24 16:08:09 +0100
commitee66c5930e6c3694434a259dfb4b7f3e9f39cf7b (patch)
treea880612dca3247fde962417077680ea34cc96d20 /test
parent45239549bf2659998dcf9196d86974b0b625912e (diff)
downloadPeerTube-ee66c5930e6c3694434a259dfb4b7f3e9f39cf7b.tar.gz
PeerTube-ee66c5930e6c3694434a259dfb4b7f3e9f39cf7b.tar.zst
PeerTube-ee66c5930e6c3694434a259dfb4b7f3e9f39cf7b.zip
Tests refractoring
Diffstat (limited to 'test')
-rw-r--r--test/api/checkParams.js36
-rw-r--r--test/api/friendsAdvanced.js267
-rw-r--r--test/api/friendsBasic.js161
-rw-r--r--test/api/multiplePods.js208
-rw-r--r--test/api/singlePod.js28
-rw-r--r--test/api/utils.js64
6 files changed, 419 insertions, 345 deletions
diff --git a/test/api/checkParams.js b/test/api/checkParams.js
index 0fa83655f..11fc68ff9 100644
--- a/test/api/checkParams.js
+++ b/test/api/checkParams.js
@@ -1,6 +1,7 @@
1;(function () { 1;(function () {
2 'use strict' 2 'use strict'
3 3
4 var async = require('async')
4 var chai = require('chai') 5 var chai = require('chai')
5 var expect = chai.expect 6 var expect = chai.expect
6 var request = require('supertest') 7 var request = require('supertest')
@@ -11,18 +12,6 @@
11 var app = null 12 var app = null
12 var url = '' 13 var url = ''
13 14
14 before(function (done) {
15 this.timeout(20000)
16
17 utils.flushTests(function () {
18 utils.runServer(1, function (app1, url1) {
19 app = app1
20 url = url1
21 done()
22 })
23 })
24 })
25
26 function makePostRequest (path, fields, attach, done, fail) { 15 function makePostRequest (path, fields, attach, done, fail) {
27 var status_code = 400 16 var status_code = 400
28 if (fail !== undefined && fail === false) status_code = 200 17 if (fail !== undefined && fail === false) status_code = 200
@@ -50,6 +39,25 @@
50 .expect(status_code, done) 39 .expect(status_code, done)
51 } 40 }
52 41
42 // ---------------------------------------------------------------
43
44 before(function (done) {
45 this.timeout(20000)
46
47 async.series([
48 function (next) {
49 utils.flushTests(next)
50 },
51 function (next) {
52 utils.runServer(1, function (app1, url1) {
53 app = app1
54 url = url1
55 next()
56 })
57 }
58 ], done)
59 })
60
53 describe('Of the pods API', function () { 61 describe('Of the pods API', function () {
54 var path = '/api/v1/pods/' 62 var path = '/api/v1/pods/'
55 63
@@ -284,9 +292,7 @@
284 292
285 // Keep the logs if the test failed 293 // Keep the logs if the test failed
286 if (this.ok) { 294 if (this.ok) {
287 utils.flushTests(function () { 295 utils.flushTests(done)
288 done()
289 })
290 } else { 296 } else {
291 done() 297 done()
292 } 298 }
diff --git a/test/api/friendsAdvanced.js b/test/api/friendsAdvanced.js
index b24cd39c3..61483bee6 100644
--- a/test/api/friendsAdvanced.js
+++ b/test/api/friendsAdvanced.js
@@ -35,145 +35,190 @@
35 return utils.getVideosList(urls[pod_number - 1], callback) 35 return utils.getVideosList(urls[pod_number - 1], callback)
36 } 36 }
37 37
38 // ---------------------------------------------------------------
39
38 before(function (done) { 40 before(function (done) {
39 this.timeout(30000) 41 this.timeout(30000)
40 utils.runMultipleServers(6, function (apps_run, urls_run) { 42 utils.flushAndRunMultipleServers(6, function (apps_run, urls_run) {
41 apps = apps_run 43 apps = apps_run
42 urls = urls_run 44 urls = urls_run
43 done() 45 done()
44 }) 46 })
45 }) 47 })
46 48
47 after(function (done) {
48 apps.forEach(function (app) {
49 process.kill(-app.pid)
50 })
51
52 if (this.ok) {
53 utils.flushTests(function () {
54 done()
55 })
56 } else {
57 done()
58 }
59 })
60
61 it('Should make friends with two pod each in a different group', function (done) { 49 it('Should make friends with two pod each in a different group', function (done) {
62 this.timeout(20000) 50 this.timeout(20000)
63 51
64 // Pod 3 makes friend with the first one 52 async.series([
65 makeFriends(3, function () { 53 // Pod 3 makes friend with the first one
54 function (next) {
55 makeFriends(3, next)
56 },
66 // Pod 4 makes friend with the second one 57 // Pod 4 makes friend with the second one
67 makeFriends(4, function () { 58 function (next) {
68 // Now if the fifth wants to make friends with the third et the first 59 makeFriends(4, next)
69 makeFriends(5, function () { 60 },
70 setTimeout(function () { 61 // Now if the fifth wants to make friends with the third et the first
71 // It should have 0 friends 62 function (next) {
72 getFriendsList(5, function (err, res) { 63 makeFriends(5, next)
73 if (err) throw err 64 },
74 65 function (next) {
75 expect(res.body.length).to.equal(0) 66 setTimeout(next, 11000)
76 67 }],
77 done() 68 function (err) {
78 }) 69 if (err) throw err
79 }, 11000) 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()
80 }) 78 })
81 }) 79 }
82 }) 80 )
83 }) 81 })
84 82
85 it('Should quit all friends', function (done) { 83 it('Should quit all friends', function (done) {
86 this.timeout(10000) 84 this.timeout(10000)
87 quitFriends(1, function () { 85
88 quitFriends(2, function () { 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
89 async.each([ 1, 2, 3, 4, 5, 6 ], function (i, callback) { 96 async.each([ 1, 2, 3, 4, 5, 6 ], function (i, callback) {
90 getFriendsList(i, function (err, res) { 97 getFriendsList(i, function (err, res) {
91 if (err) throw err 98 if (err) throw err
99
92 expect(res.body.length).to.equal(0) 100 expect(res.body.length).to.equal(0)
101
93 callback() 102 callback()
94 }) 103 })
95 }, function () { 104 }, done)
96 done() 105 }
97 }) 106 )
98 })
99 })
100 }) 107 })
101 108
102 it('Should make friends with the pods 1, 2, 3', function (done) { 109 it('Should make friends with the pods 1, 2, 3', function (done) {
103 this.timeout(150000) 110 this.timeout(150000)
104 111
105 // Pods 1, 2, 3 and 4 become friends (yes this is beautiful) 112 async.series([
106 makeFriends(2, function () { 113 // Pods 1, 2, 3 and 4 become friends
107 makeFriends(1, function () { 114 function (next) {
108 makeFriends(4, function () { 115 makeFriends(2, next)
109 // Kill the server 4 116 },
110 apps[3].kill() 117 function (next) {
111 118 makeFriends(1, next)
112 // Expulse pod 4 from pod 1 and 2 119 },
113 uploadVideo(1, function () { 120 function (next) {
114 uploadVideo(2, function () { 121 makeFriends(4, next)
115 setTimeout(function () { 122 },
116 uploadVideo(1, function () { 123 // Kill pod 4
117 uploadVideo(2, function () { 124 function (next) {
118 setTimeout(function () { 125 apps[3].kill()
119 // Rerun server 4 126 next()
120 utils.runServer(4, function (app, url) { 127 },
121 apps[3] = app 128 // Expulse pod 4 from pod 1 and 2
122 getFriendsList(4, function (err, res) { 129 function (next) {
123 if (err) throw err 130 uploadVideo(1, next)
124 // Pod 4 didn't know pod 1 and 2 removed it 131 },
125 expect(res.body.length).to.equal(3) 132 function (next) {
126 133 uploadVideo(2, next)
127 // Pod 6 ask pod 1, 2 and 3 134 },
128 makeFriends(6, function () { 135 function (next) {
129 getFriendsList(6, function (err, res) { 136 setTimeout(next, 11000)
130 if (err) throw err 137 },
131 138 function (next) {
132 // Pod 4 should not be our friend 139 uploadVideo(1, next)
133 var result = res.body 140 },
134 expect(result.length).to.equal(3) 141 function (next) {
135 for (var pod of result) { 142 uploadVideo(2, next)
136 expect(pod.url).not.equal(urls[3]) 143 },
137 } 144 function (next) {
138 145 setTimeout(next, 20000)
139 done() 146 },
140 }) 147 // Rerun server 4
141 }) 148 function (next) {
142 }) 149 utils.runServer(4, function (app, url) {
143 }) 150 apps[3] = app
144 }, 15000) 151 next()
145 })
146 })
147 }, 11000)
148 })
149 })
150 }) 152 })
151 }) 153 },
152 }) 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 )
153 }) 185 })
154 186
155 it('Should pod 1 quit friends', function (done) { 187 it('Should pod 1 quit friends', function (done) {
156 this.timeout(25000) 188 this.timeout(25000)
157 // Upload a video on server 3 for aditionnal tests 189
158 uploadVideo(3, function () { 190 async.series([
159 setTimeout(function () { 191 // Upload a video on server 3 for aditionnal tests
160 quitFriends(1, function () { 192 function (next) {
161 // Remove pod 1 from pod 2 193 uploadVideo(3, next)
162 getVideos(1, function (err, res) { 194 },
163 if (err) throw err 195 function (next) {
164 expect(res.body).to.be.an('array') 196 setTimeout(next, 15000)
165 expect(res.body.length).to.equal(2) 197 },
166 198 function (next) {
167 getVideos(2, function (err, res) { 199 quitFriends(1, next)
168 if (err) throw err 200 },
169 expect(res.body).to.be.an('array') 201 // Remove pod 1 from pod 2
170 expect(res.body.length).to.equal(3) 202 function (next) {
171 done() 203 getVideos(1, function (err, res) {
172 }) 204 if (err) throw err
173 }) 205 expect(res.body).to.be.an('array')
206 expect(res.body.length).to.equal(2)
207
208 next()
174 }) 209 })
175 }, 15000) 210 }],
176 }) 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 )
177 }) 222 })
178 223
179 it('Should make friends between pod 1 and 2 and exchange their videos', function (done) { 224 it('Should make friends between pod 1 and 2 and exchange their videos', function (done) {
@@ -191,5 +236,17 @@
191 }, 5000) 236 }, 5000)
192 }) 237 })
193 }) 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 })
194 }) 251 })
195})() 252})()
diff --git a/test/api/friendsBasic.js b/test/api/friendsBasic.js
index 15b83d421..dbc918383 100644
--- a/test/api/friendsBasic.js
+++ b/test/api/friendsBasic.js
@@ -9,6 +9,9 @@
9 var utils = require('./utils') 9 var utils = require('./utils')
10 10
11 describe('Test basic friends', function () { 11 describe('Test basic friends', function () {
12 var apps = []
13 var urls = []
14
12 function testMadeFriends (urls, url_to_test, callback) { 15 function testMadeFriends (urls, url_to_test, callback) {
13 var friends = [] 16 var friends = []
14 for (var i = 0; i < urls.length; i++) { 17 for (var i = 0; i < urls.length; i++) {
@@ -32,12 +35,11 @@
32 }) 35 })
33 } 36 }
34 37
35 var apps = [] 38 // ---------------------------------------------------------------
36 var urls = []
37 39
38 before(function (done) { 40 before(function (done) {
39 this.timeout(20000) 41 this.timeout(20000)
40 utils.runMultipleServers(3, function (apps_run, urls_run) { 42 utils.flushAndRunMultipleServers(3, function (apps_run, urls_run) {
41 apps = apps_run 43 apps = apps_run
42 urls = urls_run 44 urls = urls_run
43 done() 45 done()
@@ -54,11 +56,7 @@
54 expect(result.length).to.equal(0) 56 expect(result.length).to.equal(0)
55 callback() 57 callback()
56 }) 58 })
57 }, function (err) { 59 }, done)
58 if (err) throw err
59
60 done()
61 })
62 }) 60 })
63 61
64 it('Should make friends', function (done) { 62 it('Should make friends', function (done) {
@@ -66,56 +64,65 @@
66 64
67 var path = '/api/v1/pods/makefriends' 65 var path = '/api/v1/pods/makefriends'
68 66
69 // The second pod make friend with the third 67 async.series([
70 request(urls[1]) 68 // The second pod make friend with the third
71 .get(path) 69 function (next) {
72 .set('Accept', 'application/json') 70 request(urls[1])
73 .expect(204) 71 .get(path)
74 .end(function (err, res) { 72 .set('Accept', 'application/json')
75 if (err) throw err 73 .expect(204)
74 .end(next)
75 },
76 // Wait for the request between pods
77 function (next) {
78 setTimeout(next, 1000)
79 },
80 // The second pod should have the third as a friend
81 function (next) {
82 utils.getFriendsList(urls[1], function (err, res) {
83 if (err) throw err
76 84
77 // Wait for the request between pods 85 var result = res.body
78 setTimeout(function () { 86 expect(result).to.be.an('array')
79 // The second pod should have the third as a friend 87 expect(result.length).to.equal(1)
80 utils.getFriendsList(urls[1], function (err, res) { 88 expect(result[0].url).to.be.equal(urls[2])
81 if (err) throw err
82 89
83 var result = res.body 90 next()
84 expect(result).to.be.an('array') 91 })
85 expect(result.length).to.equal(1) 92 },
86 expect(result[0].url).to.be.equal(urls[2]) 93 // Same here, the third pod should have the second pod as a friend
87 94 function (next) {
88 // Same here, the third pod should have the second pod as a friend 95 utils.getFriendsList(urls[2], function (err, res) {
89 utils.getFriendsList(urls[2], function (err, res) { 96 if (err) throw err
90 if (err) throw err 97
91 98 var result = res.body
92 var result = res.body 99 expect(result).to.be.an('array')
93 expect(result).to.be.an('array') 100 expect(result.length).to.equal(1)
94 expect(result.length).to.equal(1) 101 expect(result[0].url).to.be.equal(urls[1])
95 expect(result[0].url).to.be.equal(urls[1]) 102
96 103 next()
97 // Finally the first pod make friend with the second pod 104 })
98 request(urls[0]) 105 },
99 .get(path) 106 // Finally the first pod make friend with the second pod
100 .set('Accept', 'application/json') 107 function (next) {
101 .expect(204) 108 request(urls[0])
102 .end(function (err, res) { 109 .get(path)
103 if (err) throw err 110 .set('Accept', 'application/json')
104 111 .expect(204)
105 setTimeout(function () { 112 .end(next)
106 // Now each pod should be friend with the other ones 113 },
107 async.each(urls, function (url, callback) { 114 // Wait for the request between pods
108 testMadeFriends(urls, url, callback) 115 function (next) {
109 }, function (err) { 116 setTimeout(next, 1000)
110 if (err) throw err 117 }
111 done() 118 ],
112 }) 119 // Now each pod should be friend with the other ones
113 }, 1000) 120 function (err) {
114 }) 121 if (err) throw err
115 }) 122 async.each(urls, function (url, callback) {
116 }) 123 testMadeFriends(urls, url, callback)
117 }, 1000) 124 }, done)
118 }) 125 })
119 }) 126 })
120 127
121 it('Should not be allowed to make friend again', function (done) { 128 it('Should not be allowed to make friend again', function (done) {
@@ -123,15 +130,25 @@
123 }) 130 })
124 131
125 it('Should quit friends of pod 2', function (done) { 132 it('Should quit friends of pod 2', function (done) {
126 utils.quitFriends(urls[1], function () { 133 async.series([
127 utils.getFriendsList(urls[1], function (err, res) { 134 // Pod 1 quit friends
128 if (err) throw err 135 function (next) {
136 utils.quitFriends(urls[1], next)
137 },
138 // Pod 1 should not have friends anymore
139 function (next) {
140 utils.getFriendsList(urls[1], function (err, res) {
141 if (err) throw err
129 142
130 var result = res.body 143 var result = res.body
131 expect(result).to.be.an('array') 144 expect(result).to.be.an('array')
132 expect(result.length).to.equal(0) 145 expect(result.length).to.equal(0)
133 146
134 // Other pods shouldn't have pod 2 too 147 next()
148 })
149 },
150 // Other pods shouldn't have pod 1 too
151 function (next) {
135 async.each([ urls[0], urls[2] ], function (url, callback) { 152 async.each([ urls[0], urls[2] ], function (url, callback) {
136 utils.getFriendsList(url, function (err, res) { 153 utils.getFriendsList(url, function (err, res) {
137 if (err) throw err 154 if (err) throw err
@@ -142,22 +159,16 @@
142 expect(result[0].url).not.to.be.equal(urls[1]) 159 expect(result[0].url).not.to.be.equal(urls[1])
143 callback() 160 callback()
144 }) 161 })
145 }, function (err) { 162 }, next)
146 if (err) throw err 163 }
147 done() 164 ], done)
148 })
149 })
150 })
151 }) 165 })
152 166
153 it('Should allow pod 2 to make friend again', function (done) { 167 it('Should allow pod 2 to make friend again', function (done) {
154 utils.makeFriends(urls[1], function () { 168 utils.makeFriends(urls[1], function () {
155 async.each(urls, function (url, callback) { 169 async.each(urls, function (url, callback) {
156 testMadeFriends(urls, url, callback) 170 testMadeFriends(urls, url, callback)
157 }, function (err) { 171 }, done)
158 if (err) throw err
159 done()
160 })
161 }) 172 })
162 }) 173 })
163 174
@@ -167,9 +178,7 @@
167 }) 178 })
168 179
169 if (this.ok) { 180 if (this.ok) {
170 utils.flushTests(function () { 181 utils.flushTests(done)
171 done()
172 })
173 } else { 182 } else {
174 done() 183 done()
175 } 184 }
diff --git a/test/api/multiplePods.js b/test/api/multiplePods.js
index 531e1ef33..b579e5e32 100644
--- a/test/api/multiplePods.js
+++ b/test/api/multiplePods.js
@@ -17,26 +17,31 @@
17 before(function (done) { 17 before(function (done) {
18 this.timeout(30000) 18 this.timeout(30000)
19 19
20 utils.runMultipleServers(3, function (apps_run, urls_run) { 20 async.series([
21 apps = apps_run 21 // Run servers
22 urls = urls_run 22 function (next) {
23 23 utils.flushAndRunMultipleServers(3, function (apps_run, urls_run) {
24 apps = apps_run
25 urls = urls_run
26 next()
27 })
28 },
24 // The second pod make friend with the third 29 // The second pod make friend with the third
25 utils.makeFriends(urls[1], function (err, res) { 30 function (next) {
26 if (err) throw err 31 utils.makeFriends(urls[1], next)
27 32 },
28 // Wait for the request between pods 33 // Wait for the request between pods
29 setTimeout(function () { 34 function (next) {
30 utils.makeFriends(urls[0], function (err, res) { 35 setTimeout(next, 10000)
31 if (err) throw err 36 },
32 37 // Pod 1 make friends too
33 webtorrent.create({ host: 'client', port: '1' }, function () { 38 function (next) {
34 done() 39 utils.makeFriends(urls[0], next)
35 }) 40 },
36 }) 41 function (next) {
37 }, 10000) 42 webtorrent.create({ host: 'client', port: '1' }, next)
38 }) 43 }
39 }) 44 ], done)
40 }) 45 })
41 46
42 it('Should not have videos for all pods', function (done) { 47 it('Should not have videos for all pods', function (done) {
@@ -49,22 +54,24 @@
49 54
50 callback() 55 callback()
51 }) 56 })
52 }, function (err) { 57 }, done)
53 if (err) throw err
54
55 done()
56 })
57 }) 58 })
58 59
59 describe('Should upload the video and propagate on each pod', function () { 60 describe('Should upload the video and propagate on each pod', function () {
60 it('Should upload the video on pod 1 and propagate on each pod', function (done) { 61 it('Should upload the video on pod 1 and propagate on each pod', function (done) {
61 this.timeout(15000) 62 this.timeout(15000)
62 63
63 utils.uploadVideo(urls[0], 'my super name for pod 1', 'my super description for pod 1', 'video_short1.webm', function (err) { 64 async.series([
64 if (err) throw err 65 function (next) {
66 utils.uploadVideo(urls[0], 'my super name for pod 1', 'my super description for pod 1', 'video_short1.webm', next)
67 },
68 function (next) {
69 setTimeout(next, 11000)
70 }],
71 // All pods should have this video
72 function (err) {
73 if (err) throw err
65 74
66 setTimeout(function () {
67 // All pods should have this video
68 async.each(urls, function (url, callback) { 75 async.each(urls, function (url, callback) {
69 var base_magnet = null 76 var base_magnet = null
70 77
@@ -89,23 +96,25 @@
89 96
90 callback() 97 callback()
91 }) 98 })
92 }, function (err) { 99 }, done)
93 if (err) throw err 100 }
94 101 )
95 done()
96 })
97 }, 11000)
98 })
99 }) 102 })
100 103
101 it('Should upload the video on pod 2 and propagate on each pod', function (done) { 104 it('Should upload the video on pod 2 and propagate on each pod', function (done) {
102 this.timeout(15000) 105 this.timeout(15000)
103 106
104 utils.uploadVideo(urls[1], 'my super name for pod 2', 'my super description for pod 2', 'video_short2.webm', function (err) { 107 async.series([
105 if (err) throw err 108 function (next) {
109 utils.uploadVideo(urls[1], 'my super name for pod 2', 'my super description for pod 2', 'video_short2.webm', next)
110 },
111 function (next) {
112 setTimeout(next, 11000)
113 }],
114 // All pods should have this video
115 function (err) {
116 if (err) throw err
106 117
107 setTimeout(function () {
108 // All pods should have this video
109 async.each(urls, function (url, callback) { 118 async.each(urls, function (url, callback) {
110 var base_magnet = null 119 var base_magnet = null
111 120
@@ -130,62 +139,60 @@
130 139
131 callback() 140 callback()
132 }) 141 })
133 }, function (err) { 142 }, done)
134 if (err) throw err 143 }
135 144 )
136 done()
137 })
138 }, 11000)
139 })
140 }) 145 })
141 146
142 it('Should upload two videos on pod 3 and propagate on each pod', function (done) { 147 it('Should upload two videos on pod 3 and propagate on each pod', function (done) {
143 this.timeout(30000) 148 this.timeout(30000)
144 149
145 utils.uploadVideo(urls[2], 'my super name for pod 3', 'my super description for pod 3', 'video_short3.webm', function (err) { 150 async.series([
146 if (err) throw err 151 function (next) {
147 utils.uploadVideo(urls[2], 'my super name for pod 3-2', 'my super description for pod 3-2', 'video_short.webm', function (err) { 152 utils.uploadVideo(urls[2], 'my super name for pod 3', 'my super description for pod 3', 'video_short3.webm', next)
153 },
154 function (next) {
155 utils.uploadVideo(urls[2], 'my super name for pod 3-2', 'my super description for pod 3-2', 'video_short.webm', next)
156 },
157 function (next) {
158 setTimeout(next, 22000)
159 }],
160 function (err) {
148 if (err) throw err 161 if (err) throw err
149 162
150 setTimeout(function () { 163 var base_magnet = null
151 var base_magnet = null 164 // All pods should have this video
152 // All pods should have this video 165 async.each(urls, function (url, callback) {
153 async.each(urls, function (url, callback) { 166 utils.getVideosList(url, function (err, res) {
154 utils.getVideosList(url, function (err, res) {
155 if (err) throw err
156
157 var videos = res.body
158 expect(videos).to.be.an('array')
159 expect(videos.length).to.equal(4)
160 var video = videos[2]
161 expect(video.name).to.equal('my super name for pod 3')
162 expect(video.description).to.equal('my super description for pod 3')
163 expect(video.podUrl).to.equal('http://localhost:9003')
164 expect(video.magnetUri).to.exist
165
166 video = videos[3]
167 expect(video.name).to.equal('my super name for pod 3-2')
168 expect(video.description).to.equal('my super description for pod 3-2')
169 expect(video.podUrl).to.equal('http://localhost:9003')
170 expect(video.magnetUri).to.exist
171
172 // All pods should have the same magnet Uri
173 if (base_magnet === null) {
174 base_magnet = video.magnetUri
175 } else {
176 expect(video.magnetUri).to.equal.magnetUri
177 }
178
179 callback()
180 })
181 }, function (err) {
182 if (err) throw err 167 if (err) throw err
183 168
184 done() 169 var videos = res.body
170 expect(videos).to.be.an('array')
171 expect(videos.length).to.equal(4)
172 var video = videos[2]
173 expect(video.name).to.equal('my super name for pod 3')
174 expect(video.description).to.equal('my super description for pod 3')
175 expect(video.podUrl).to.equal('http://localhost:9003')
176 expect(video.magnetUri).to.exist
177
178 video = videos[3]
179 expect(video.name).to.equal('my super name for pod 3-2')
180 expect(video.description).to.equal('my super description for pod 3-2')
181 expect(video.podUrl).to.equal('http://localhost:9003')
182 expect(video.magnetUri).to.exist
183
184 // All pods should have the same magnet Uri
185 if (base_magnet === null) {
186 base_magnet = video.magnetUri
187 } else {
188 expect(video.magnetUri).to.equal.magnetUri
189 }
190
191 callback()
185 }) 192 })
186 }, 22000) 193 }, done)
187 }) 194 }
188 }) 195 )
189 }) 196 })
190 }) 197 })
191 198
@@ -271,17 +278,18 @@
271 it('Should remove the file 3 and 3-2 by asking pod 3', function (done) { 278 it('Should remove the file 3 and 3-2 by asking pod 3', function (done) {
272 this.timeout(15000) 279 this.timeout(15000)
273 280
274 utils.removeVideo(urls[2], to_remove[0], function (err) { 281 async.series([
275 if (err) throw err 282 function (next) {
276 utils.removeVideo(urls[2], to_remove[1], function (err) { 283 utils.removeVideo(urls[2], to_remove[0], next)
284 },
285 function (next) {
286 utils.removeVideo(urls[2], to_remove[1], next)
287 }],
288 function (err) {
277 if (err) throw err 289 if (err) throw err
278 290 setTimeout(done, 11000)
279 // Wait the propagation to the other pods 291 }
280 setTimeout(function () { 292 )
281 done()
282 }, 11000)
283 })
284 })
285 }) 293 })
286 294
287 it('Should have videos 1 and 3 on each pod', function (done) { 295 it('Should have videos 1 and 3 on each pod', function (done) {
@@ -300,11 +308,7 @@
300 308
301 callback() 309 callback()
302 }) 310 })
303 }, function (err) { 311 }, done)
304 if (err) throw err
305
306 done()
307 })
308 }) 312 })
309 }) 313 })
310 314
@@ -316,9 +320,7 @@
316 320
317 // Keep the logs if the test failed 321 // Keep the logs if the test failed
318 if (this.ok) { 322 if (this.ok) {
319 utils.flushTests(function () { 323 utils.flushTests(done)
320 done()
321 })
322 } else { 324 } else {
323 done() 325 done()
324 } 326 }
diff --git a/test/api/singlePod.js b/test/api/singlePod.js
index be944d8da..a8ae43aee 100644
--- a/test/api/singlePod.js
+++ b/test/api/singlePod.js
@@ -1,6 +1,7 @@
1;(function () { 1;(function () {
2 'use strict' 2 'use strict'
3 3
4 var async = require('async')
4 var chai = require('chai') 5 var chai = require('chai')
5 var fs = require('fs') 6 var fs = require('fs')
6 var expect = chai.expect 7 var expect = chai.expect
@@ -18,16 +19,21 @@
18 before(function (done) { 19 before(function (done) {
19 this.timeout(20000) 20 this.timeout(20000)
20 21
21 utils.flushTests(function () { 22 async.series([
22 utils.runServer(1, function (app1, url1) { 23 function (next) {
23 app = app1 24 utils.flushTests(next)
24 url = url1 25 },
25 26 function (next) {
26 webtorrent.create({ host: 'client', port: '1' }, function () { 27 utils.runServer(1, function (app1, url1) {
27 done() 28 app = app1
29 url = url1
30 next()
28 }) 31 })
29 }) 32 },
30 }) 33 function (next) {
34 webtorrent.create({ host: 'client', port: '1' }, next)
35 }
36 ], done)
31 }) 37 })
32 38
33 it('Should not have videos', function (done) { 39 it('Should not have videos', function (done) {
@@ -132,9 +138,7 @@
132 138
133 // Keep the logs if the test failed 139 // Keep the logs if the test failed
134 if (this.ok) { 140 if (this.ok) {
135 utils.flushTests(function () { 141 utils.flushTests(done)
136 done()
137 })
138 } else { 142 } else {
139 done() 143 done()
140 } 144 }
diff --git a/test/api/utils.js b/test/api/utils.js
index b00890539..afb0abb33 100644
--- a/test/api/utils.js
+++ b/test/api/utils.js
@@ -6,10 +6,23 @@
6 var fork = child_process.fork 6 var fork = child_process.fork
7 var request = require('supertest') 7 var request = require('supertest')
8 8
9 module.exports = {
10 flushTests: flushTests,
11 getFriendsList: getFriendsList,
12 getVideosList: getVideosList,
13 makeFriends: makeFriends,
14 quitFriends: quitFriends,
15 removeVideo: removeVideo,
16 flushAndRunMultipleServers: flushAndRunMultipleServers,
17 runServer: runServer,
18 searchVideo: searchVideo,
19 uploadVideo: uploadVideo
20 }
21
22 // ---------------------- Export functions --------------------
23
9 function flushTests (callback) { 24 function flushTests (callback) {
10 exec(__dirname + '/../../scripts/clean_test.sh', function () { 25 exec(__dirname + '/../../scripts/clean_test.sh', callback)
11 callback()
12 })
13 } 26 }
14 27
15 function getFriendsList (url, end) { 28 function getFriendsList (url, end) {
@@ -51,9 +64,7 @@
51 if (err) throw err 64 if (err) throw err
52 65
53 // Wait for the request between pods 66 // Wait for the request between pods
54 setTimeout(function () { 67 setTimeout(callback, 1000)
55 callback()
56 }, 1000)
57 }) 68 })
58 } 69 }
59 70
@@ -69,25 +80,10 @@
69 if (err) throw err 80 if (err) throw err
70 81
71 // Wait for the request between pods 82 // Wait for the request between pods
72 setTimeout(function () { 83 setTimeout(callback, 1000)
73 callback()
74 }, 1000)
75 }) 84 })
76 } 85 }
77 86
78 function uploadVideo (url, name, description, fixture, end) {
79 var path = '/api/v1/videos'
80
81 request(url)
82 .post(path)
83 .set('Accept', 'application/json')
84 .field('name', name)
85 .field('description', description)
86 .attach('input_video', __dirname + '/fixtures/' + fixture)
87 .expect(201)
88 .end(end)
89 }
90
91 function removeVideo (url, id, end) { 87 function removeVideo (url, id, end) {
92 var path = '/api/v1/videos' 88 var path = '/api/v1/videos'
93 89
@@ -98,7 +94,7 @@
98 .end(end) 94 .end(end)
99 } 95 }
100 96
101 function runMultipleServers (total_servers, serversRun) { 97 function flushAndRunMultipleServers (total_servers, serversRun) {
102 var apps = [] 98 var apps = []
103 var urls = [] 99 var urls = []
104 var i = 0 100 var i = 0
@@ -171,16 +167,16 @@
171 .end(end) 167 .end(end)
172 } 168 }
173 169
174 module.exports = { 170 function uploadVideo (url, name, description, fixture, end) {
175 flushTests: flushTests, 171 var path = '/api/v1/videos'
176 getFriendsList: getFriendsList, 172
177 getVideosList: getVideosList, 173 request(url)
178 makeFriends: makeFriends, 174 .post(path)
179 quitFriends: quitFriends, 175 .set('Accept', 'application/json')
180 removeVideo: removeVideo, 176 .field('name', name)
181 runMultipleServers: runMultipleServers, 177 .field('description', description)
182 runServer: runServer, 178 .attach('input_video', __dirname + '/fixtures/' + fixture)
183 searchVideo: searchVideo, 179 .expect(201)
184 uploadVideo: uploadVideo 180 .end(end)
185 } 181 }
186})() 182})()