3 var async = require('async')
4 var chai = require('chai')
5 var expect = chai.expect
7 var utils = require('./utils')
9 describe('Test advanced friends', function () {
13 function makeFriends (pod_number, callback) {
14 return utils.makeFriends(urls[pod_number - 1], callback)
17 function quitFriends (pod_number, callback) {
18 return utils.quitFriends(urls[pod_number - 1], callback)
21 function getFriendsList (pod_number, end) {
22 return utils.getFriendsList(urls[pod_number - 1], end)
25 function uploadVideo (pod_number, callback) {
26 var name = 'my super video'
27 var description = 'my super description'
28 var fixture = 'video_short.webm'
30 return utils.uploadVideo(urls[pod_number - 1], name, description, fixture, callback)
33 function getVideos (pod_number, callback) {
34 return utils.getVideosList(urls[pod_number - 1], callback)
37 // ---------------------------------------------------------------
39 before(function (done) {
41 utils.flushAndRunMultipleServers(6, function (apps_run, urls_run) {
48 it('Should make friends with two pod each in a different group', function (done) {
52 // Pod 3 makes friend with the first one
56 // Pod 4 makes friend with the second one
60 // Now if the fifth wants to make friends with the third et the first
65 setTimeout(next, 11000)
70 // It should have 0 friends
71 getFriendsList(5, function (err, res) {
74 expect(res.body.length).to.equal(0)
82 it('Should quit all friends', function (done) {
95 async.each([ 1, 2, 3, 4, 5, 6 ], function (i, callback) {
96 getFriendsList(i, function (err, res) {
99 expect(res.body.length).to.equal(0)
108 it('Should make friends with the pods 1, 2, 3', function (done) {
112 // Pods 1, 2, 3 and 4 become friends
127 // Expulse pod 4 from pod 1 and 2
135 setTimeout(next, 11000)
144 setTimeout(next, 20000)
148 utils.runServer(4, function (app, url) {
154 getFriendsList(4, function (err, res) {
157 // Pod 4 didn't know pod 1 and 2 removed it
158 expect(res.body.length).to.equal(3)
163 // Pod 6 ask pod 1, 2 and 3
170 getFriendsList(6, function (err, res) {
173 // Pod 4 should not be our friend
174 var result = res.body
175 expect(result.length).to.equal(3)
176 for (var pod of result) {
177 expect(pod.url).not.equal(urls[3])
186 it('Should pod 1 quit friends', function (done) {
190 // Upload a video on server 3 for aditionnal tests
195 setTimeout(next, 15000)
200 // Remove pod 1 from pod 2
202 getVideos(1, function (err, res) {
204 expect(res.body).to.be.an('array')
205 expect(res.body.length).to.equal(2)
213 getVideos(2, function (err, res) {
215 expect(res.body).to.be.an('array')
216 expect(res.body.length).to.equal(3)
223 it('Should make friends between pod 1 and 2 and exchange their videos', function (done) {
225 makeFriends(1, function () {
226 setTimeout(function () {
227 getVideos(1, function (err, res) {
230 expect(res.body).to.be.an('array')
231 expect(res.body.length).to.equal(5)
239 after(function (done) {
240 apps.forEach(function (app) {
241 process.kill(-app.pid)
245 utils.flushTests(done)