-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from pioardi/develop
Start integration tests implementation
- Loading branch information
Showing
6 changed files
with
95 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#!/bin/bash | ||
echo "Node start up" | ||
npm run start-leader | ||
npm run start |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
To run integration tests. | ||
|
||
sh integration.sh | ||
wait... | ||
npm run integration-test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
'use strict'; | ||
//ring-election_node-0_1 | ||
const expect = require('expect'); | ||
const request = require('request'); | ||
var exec = require('child_process').exec; | ||
|
||
let shouldStartWell = (err, response, body , done , nodeNumber) => { | ||
expect(response.statusCode).toBe(200); | ||
expect(body).toBeDefined(); | ||
let resp = JSON.parse(body); | ||
expect(resp.length).toBe(3); | ||
// actually the leader has not assigned to any partition. | ||
let leader = resp.find(node => node.partitions.length == 0); | ||
expect(leader).toBeDefined(); | ||
// expect other two nodes to have 5 partitions assigned per each. | ||
resp | ||
.filter(node => node.partitions.length > 0) | ||
.forEach(n => { | ||
expect(n.partitions.length).toBe(5); | ||
}); | ||
if(nodeNumber == 3) | ||
done(); | ||
}; | ||
|
||
describe('Integration test', () => { | ||
|
||
it('Should start well', done => { | ||
request('http://localhost:9000/status', (err,resp,body) => { | ||
shouldStartWell(err,resp,body,done,1); | ||
}); | ||
request('http://localhost:9001/status', (err,resp,body) => { | ||
shouldStartWell(err,resp,body,done,2); | ||
}); | ||
request('http://localhost:9002/status', (err,resp,body) => { | ||
shouldStartWell(err,resp,body,done,3); | ||
}); | ||
}); | ||
|
||
|
||
|
||
it('Should reassign partitions when a node is down', done => { | ||
|
||
exec('docker container stop ring-election_node-2_1', err => { | ||
expect(err).toBeFalsy(); | ||
setTimeout(() => { | ||
request('http://localhost:9000/status', (err, response, body) => { | ||
expect(response.statusCode).toBe(200); | ||
expect(body).toBeDefined(); | ||
let resp = JSON.parse(body); | ||
expect(resp.length).toBe(2); | ||
// actually the leader has not assigned to any partition. | ||
let leader = resp.find((node) => node.partitions.length == 0); | ||
expect(leader).toBeDefined(); | ||
// expect other node to have 5 partitions assigned per each. | ||
resp.filter(node => node.partitions.length > 0).forEach(n => { | ||
expect(n.partitions.length).toBe(10); | ||
}); | ||
exec('docker container restart ring-election_node-2_1', err => { | ||
if(!err) | ||
done(); | ||
else | ||
console.error(err); | ||
}); | ||
}); | ||
}, 15000); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/bash | ||
|
||
cd .. | ||
cd .. | ||
echo "Deleting ring election image" | ||
docker image rm -f pioardi/ring-election:1.0 | ||
docker-compose down | ||
docker-compose rm -f | ||
echo "\nRebuild docker image" | ||
docker image build -t pioardi/ring-election:1.0 . | ||
echo "\nDocker image built , start cluster..." | ||
docker-compose up -d | ||
echo "Waiting" | ||
sleep 15 | ||
|
||
|