aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/api/friendsAdvanced.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/api/friendsAdvanced.js')
-rw-r--r--test/api/friendsAdvanced.js88
1 files changed, 77 insertions, 11 deletions
diff --git a/test/api/friendsAdvanced.js b/test/api/friendsAdvanced.js
index a638eb0d4..b24cd39c3 100644
--- a/test/api/friendsAdvanced.js
+++ b/test/api/friendsAdvanced.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 7
@@ -10,8 +11,12 @@
10 var apps = [] 11 var apps = []
11 var urls = [] 12 var urls = []
12 13
13 function makeFriend (pod_number, callback) { 14 function makeFriends (pod_number, callback) {
14 return utils.makeFriend(urls[pod_number - 1], callback) 15 return utils.makeFriends(urls[pod_number - 1], callback)
16 }
17
18 function quitFriends (pod_number, callback) {
19 return utils.quitFriends(urls[pod_number - 1], callback)
15 } 20 }
16 21
17 function getFriendsList (pod_number, end) { 22 function getFriendsList (pod_number, end) {
@@ -26,7 +31,11 @@
26 return utils.uploadVideo(urls[pod_number - 1], name, description, fixture, callback) 31 return utils.uploadVideo(urls[pod_number - 1], name, description, fixture, callback)
27 } 32 }
28 33
29 beforeEach(function (done) { 34 function getVideos (pod_number, callback) {
35 return utils.getVideosList(urls[pod_number - 1], callback)
36 }
37
38 before(function (done) {
30 this.timeout(30000) 39 this.timeout(30000)
31 utils.runMultipleServers(6, function (apps_run, urls_run) { 40 utils.runMultipleServers(6, function (apps_run, urls_run) {
32 apps = apps_run 41 apps = apps_run
@@ -35,7 +44,7 @@
35 }) 44 })
36 }) 45 })
37 46
38 afterEach(function (done) { 47 after(function (done) {
39 apps.forEach(function (app) { 48 apps.forEach(function (app) {
40 process.kill(-app.pid) 49 process.kill(-app.pid)
41 }) 50 })
@@ -53,11 +62,11 @@
53 this.timeout(20000) 62 this.timeout(20000)
54 63
55 // Pod 3 makes friend with the first one 64 // Pod 3 makes friend with the first one
56 makeFriend(3, function () { 65 makeFriends(3, function () {
57 // Pod 4 makes friend with the second one 66 // Pod 4 makes friend with the second one
58 makeFriend(4, function () { 67 makeFriends(4, function () {
59 // Now if the fifth wants to make friends with the third et the first 68 // Now if the fifth wants to make friends with the third et the first
60 makeFriend(5, function () { 69 makeFriends(5, function () {
61 setTimeout(function () { 70 setTimeout(function () {
62 // It should have 0 friends 71 // It should have 0 friends
63 getFriendsList(5, function (err, res) { 72 getFriendsList(5, function (err, res) {
@@ -73,13 +82,30 @@
73 }) 82 })
74 }) 83 })
75 84
85 it('Should quit all friends', function (done) {
86 this.timeout(10000)
87 quitFriends(1, function () {
88 quitFriends(2, function () {
89 async.each([ 1, 2, 3, 4, 5, 6 ], function (i, callback) {
90 getFriendsList(i, function (err, res) {
91 if (err) throw err
92 expect(res.body.length).to.equal(0)
93 callback()
94 })
95 }, function () {
96 done()
97 })
98 })
99 })
100 })
101
76 it('Should make friends with the pods 1, 2, 3', function (done) { 102 it('Should make friends with the pods 1, 2, 3', function (done) {
77 this.timeout(150000) 103 this.timeout(150000)
78 104
79 // Pods 1, 2, 3 and 4 become friends (yes this is beautiful) 105 // Pods 1, 2, 3 and 4 become friends (yes this is beautiful)
80 makeFriend(2, function () { 106 makeFriends(2, function () {
81 makeFriend(1, function () { 107 makeFriends(1, function () {
82 makeFriend(4, function () { 108 makeFriends(4, function () {
83 // Kill the server 4 109 // Kill the server 4
84 apps[3].kill() 110 apps[3].kill()
85 111
@@ -99,7 +125,7 @@
99 expect(res.body.length).to.equal(3) 125 expect(res.body.length).to.equal(3)
100 126
101 // Pod 6 ask pod 1, 2 and 3 127 // Pod 6 ask pod 1, 2 and 3
102 makeFriend(6, function () { 128 makeFriends(6, function () {
103 getFriendsList(6, function (err, res) { 129 getFriendsList(6, function (err, res) {
104 if (err) throw err 130 if (err) throw err
105 131
@@ -125,5 +151,45 @@
125 }) 151 })
126 }) 152 })
127 }) 153 })
154
155 it('Should pod 1 quit friends', function (done) {
156 this.timeout(25000)
157 // Upload a video on server 3 for aditionnal tests
158 uploadVideo(3, function () {
159 setTimeout(function () {
160 quitFriends(1, function () {
161 // Remove pod 1 from pod 2
162 getVideos(1, function (err, res) {
163 if (err) throw err
164 expect(res.body).to.be.an('array')
165 expect(res.body.length).to.equal(2)
166
167 getVideos(2, function (err, res) {
168 if (err) throw err
169 expect(res.body).to.be.an('array')
170 expect(res.body.length).to.equal(3)
171 done()
172 })
173 })
174 })
175 }, 15000)
176 })
177 })
178
179 it('Should make friends between pod 1 and 2 and exchange their videos', function (done) {
180 this.timeout(20000)
181 makeFriends(1, function () {
182 setTimeout(function () {
183 getVideos(1, function (err, res) {
184 if (err) throw err
185
186 expect(res.body).to.be.an('array')
187 expect(res.body.length).to.equal(5)
188
189 done()
190 })
191 }, 5000)
192 })
193 })
128 }) 194 })
129})() 195})()