aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/api/friendsAdvanced.js
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/api/friendsAdvanced.js
parent45239549bf2659998dcf9196d86974b0b625912e (diff)
downloadPeerTube-ee66c5930e6c3694434a259dfb4b7f3e9f39cf7b.tar.gz
PeerTube-ee66c5930e6c3694434a259dfb4b7f3e9f39cf7b.tar.zst
PeerTube-ee66c5930e6c3694434a259dfb4b7f3e9f39cf7b.zip
Tests refractoring
Diffstat (limited to 'test/api/friendsAdvanced.js')
-rw-r--r--test/api/friendsAdvanced.js267
1 files changed, 162 insertions, 105 deletions
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})()