diff options
Diffstat (limited to 'test/api/friendsBasic.js')
-rw-r--r-- | test/api/friendsBasic.js | 161 |
1 files changed, 85 insertions, 76 deletions
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 | } |