diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-01-24 16:08:09 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-01-24 16:08:09 +0100 |
commit | ee66c5930e6c3694434a259dfb4b7f3e9f39cf7b (patch) | |
tree | a880612dca3247fde962417077680ea34cc96d20 /test/api/multiplePods.js | |
parent | 45239549bf2659998dcf9196d86974b0b625912e (diff) | |
download | PeerTube-ee66c5930e6c3694434a259dfb4b7f3e9f39cf7b.tar.gz PeerTube-ee66c5930e6c3694434a259dfb4b7f3e9f39cf7b.tar.zst PeerTube-ee66c5930e6c3694434a259dfb4b7f3e9f39cf7b.zip |
Tests refractoring
Diffstat (limited to 'test/api/multiplePods.js')
-rw-r--r-- | test/api/multiplePods.js | 208 |
1 files changed, 105 insertions, 103 deletions
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 | } |