Skip to content

Commit

Permalink
Merge pull request #36 from pioardi/develop
Browse files Browse the repository at this point in the history
Start integration tests implementation
  • Loading branch information
pioardi authored Nov 15, 2019
2 parents 7d56f38 + 3424ddf commit 3ba943c
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 4 deletions.
2 changes: 1 addition & 1 deletion entrypoint.sh
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
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ring-election",
"version": "0.0.15",
"version": "0.0.16",
"description": "Leader and followers algorithm to make partitioning easy.",
"main": "index.js",
"engines": {
Expand All @@ -22,6 +22,7 @@
"start": "node start.js",
"build": "npm install",
"test": "nyc mocha --exit --timeout 10000 **/*test.js",
"integration-test": "nyc mocha --exit --timeout 300000 **/*/integration/*.js",
"demontest": "nodemon --exec \"npm test\"",
"coverage": "nyc report --reporter=text-lcov --timeout 5000 **/*test.js | coveralls"
},
Expand Down Expand Up @@ -50,6 +51,7 @@
"mock-require": "^3.0.3",
"nyc": "^14.0.0",
"supertest": "^4.0.2",
"lodash": "^4.17.11"
"lodash": "^4.17.11",
"request": "2.88.0"
}
}
5 changes: 5 additions & 0 deletions test/integration/README.MD
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
68 changes: 68 additions & 0 deletions test/integration/integration.js
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);
});
});
});
16 changes: 16 additions & 0 deletions test/integration/integration.sh
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


0 comments on commit 3ba943c

Please sign in to comment.