Skip to content

Commit

Permalink
Merge pull request #121 from happner/confirm-custom-flag
Browse files Browse the repository at this point in the history
test create and destroy element
  • Loading branch information
nomilous authored Mar 21, 2017
2 parents 54ccc39 + c00f27d commit f02ae0a
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 6 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "happner-cluster",
"version": "1.2.2",
"version": "1.2.3",
"description": "Extends happner with clustering capabilities",
"main": "index.js",
"scripts": {
Expand All @@ -27,9 +27,9 @@
},
"dependencies": {
"bluebird": "^3.4.7",
"happn-cluster": "2.5.4",
"happner-2": "2.5.5",
"happner-client": "1.1.5",
"happn-cluster": "2.5.6",
"happner-2": "2.6.4",
"happner-client": "1.1.7",
"semver": "^5.3.0"
}
}
4 changes: 2 additions & 2 deletions test/_lib/base-config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = function (seq) {
module.exports = function (seq, minPeers) {
return {
name: 'MESH_' + seq,
domain: 'DOMAIN_NAME',
Expand All @@ -24,7 +24,7 @@ module.exports = function (seq) {
},
orchestrator: {
config: {
minimumPeers: 3
minimumPeers: minPeers || 3
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions test/_lib/func-04-component/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = Component;

function Component() {}
18 changes: 18 additions & 0 deletions test/_lib/func-04-component/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "component",
"version": "1.0.0",
"happner": {
"dependencies": {
"component": {
"dependency1": {
"version": "^2.0.0",
"methods": {}
},
"dependency2": {
"version": "^2.0.0",
"methods": {}
}
}
}
}
}
136 changes: 136 additions & 0 deletions test/func/04-func-create-and-destroy-components.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
var path = require('path');
var HappnerCluster = require('../..');
var Promise = require('bluebird');
var expect = require('expect.js');

var libDir = require('../_lib/lib-dir');
var baseConfig = require('../_lib/base-config');
var stopCluster = require('../_lib/stop-cluster');
var minPeers = 1;

describe('03 - func - create and destroy components', function () {

var servers, localInstance;

function localInstanceConfig(seq) {
var config = baseConfig(seq, minPeers);
config.modules = {
'dependency1': {
instance: {}
},
'component': {
path: libDir + 'func-04-component'
}
};
config.components = {
'dependency1': {},
'component': {}
};
return config;
}

beforeEach('start cluster', function (done) {
this.timeout(4000);

Promise.all([
HappnerCluster.create(localInstanceConfig(1))
])
.then(function (_servers) {
servers = _servers;
localInstance = servers[0];
done();
})
.catch(done);
});

afterEach('stop cluster', function (done) {
if (!servers) return done();
stopCluster(servers, done);
});

context('_createElement', function () {

it('does not overwrite components from cluster', function (done) {
var componentInstance = localInstance._mesh.elements['component'].component.instance;
var exchange = componentInstance.exchange;

// both dependencies are from cluster
expect(exchange.dependency1).to.eql({
__version: '^2.0.0',
__custom: true
});
expect(exchange.dependency2).to.eql({
__version: '^2.0.0',
__custom: true
});

localInstance._createElement({
module: {
name: 'dependency2',
config: {
instance: {}
}
},
component: {
name: 'dependency2',
config: {}
}

})

.then(function () {
// both dependencies are STILL from cluster (not overwritten)
expect(exchange.dependency1).to.eql({
__version: '^2.0.0',
__custom: true
});
expect(exchange.dependency2).to.eql({
__version: '^2.0.0',
__custom: true
});
})

.then(done).catch(done);
});

});

context('_destroyElement', function () {

it('does not remove components from cluster', function (done) {

var componentInstance = localInstance._mesh.elements['component'].component.instance;
var exchange = componentInstance.exchange;

// both dependencies are from cluster
expect(exchange.dependency1).to.eql({
__version: '^2.0.0',
__custom: true
});
expect(exchange.dependency2).to.eql({
__version: '^2.0.0',
__custom: true
});

localInstance._destroyElement('dependency1')

.then(function () {
// both dependencies are STILL from cluster (not removed)
expect(exchange.dependency1).to.eql({
__version: '^2.0.0',
__custom: true
});
expect(exchange.dependency2).to.eql({
__version: '^2.0.0',
__custom: true
});
})

.then(done).catch(done);

});

});


});

0 comments on commit f02ae0a

Please sign in to comment.