Skip to content

Commit

Permalink
Merge pull request #26 from happner/release/2.3.3
Browse files Browse the repository at this point in the history
Release/2.3.3
  • Loading branch information
JensEggers committed Apr 4, 2016
2 parents bbdf759 + bbdbcdf commit abc1869
Show file tree
Hide file tree
Showing 7 changed files with 252 additions and 48 deletions.
5 changes: 5 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,8 @@
- fixed '/' webmethod exclusion was effectively '/*', allowing entire site without authentication
- added username to session token
- fixed unmounted connect app when https

2.3.3 2016-04-04
----------------

- Pull fixes from 2.5.16 (#22 & #23)
1 change: 1 addition & 0 deletions lib/client/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ HappnClient.prototype.performRequest = function(path, action, data, parameters,

callbackHandler.handleResponse = function(e, response){
clearTimeout(this.timedout);
delete this.client.requestEvents[this.eventId];
return this.handler(e, response);
}.bind(callbackHandler);

Expand Down
3 changes: 1 addition & 2 deletions lib/services/pubsub/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ PubSubService.prototype.createResponse = function(e, message, response, local) {
}

if (['set', 'remove'].indexOf(message.action) > -1) {

if (!message.parameters || !message.parameters.options || !message.parameters.options.noPublish) {
if (!message.parameters || !message.parameters.noPublish) {
this.publish(message, response);
}

Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"name": "happn",
"description": "pub/sub api as a service using primus and mongo & redis or nedb, can work as cluster, single process or embedded using nedb, use in production at your own risk",
"version": "2.3.2",
"version": "2.3.3",
"main": "./lib/index",
"scripts": {
"test": "mocha silence.js test",
"test-cover": "istanbul cover _mocha -- silence.js test"
"test-cover": "istanbul cover _mocha -- silence.js test",
"test-memory": "mocha --expose-gc test/test-memory"
},
"keywords": [
"mongo",
Expand Down Expand Up @@ -48,7 +49,7 @@
"ws": "0.7.2"
},
"devDependencies": {
"chai": "^3.2.0",
"chai": "^3.5.0",
"coveralls": "^2.11.6",
"expect.js": "*",
"istanbul": "^0.4.1",
Expand Down
130 changes: 87 additions & 43 deletions test/1_eventemitter_embedded_sanity.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
describe('1_eventemitter_embedded_sanity', function () {

var expect = require('expect.js');
var happn = require('../lib/index')
var happn = require('../lib/index');
var service = happn.service;
var happn_client = happn.client;
var async = require('async');
var testport = 8000;
var test_secret = 'test_secret';
var mode = "embedded";
var default_timeout = 10000;
Expand Down Expand Up @@ -62,16 +61,16 @@ describe('1_eventemitter_embedded_sanity', function () {
}
});

after(function(done) {
after(function (done) {
happnInstance.stop(done);
});


var publisherclient;
var listenerclient;

/*
We are initializing 2 clients to test saving data against the database, one client will push data into the
/*
We are initializing 2 clients to test saving data against the database, one client will push data into the
database whilst another listens for changes.
*/
before('should initialize the clients', function (callback) {
Expand Down Expand Up @@ -107,15 +106,17 @@ describe('1_eventemitter_embedded_sanity', function () {
});



it('the listener should pick up a single wildcard event', function (callback) {

this.timeout(default_timeout);

try {

//first listen for the change
listenerclient.on('/1_eventemitter_embedded_sanity/' + test_id + '/testsubscribe/data/event/*', {event_type: 'set', count: 1}, function (message) {
listenerclient.on('/1_eventemitter_embedded_sanity/' + test_id + '/testsubscribe/data/event/*', {
event_type: 'set',
count: 1
}, function (message) {

expect(listenerclient.events['/SET@/1_eventemitter_embedded_sanity/' + test_id + '/testsubscribe/data/event/*'].length).to.be(0);
callback();
Expand Down Expand Up @@ -203,40 +204,40 @@ describe('1_eventemitter_embedded_sanity', function () {

try {

async.times(timesCount,
function(n, timesCallback){
async.times(timesCount,
function (n, timesCallback) {

var test_random_path2 = require('shortid').generate();
var test_random_path2 = require('shortid').generate();

publisherclient.set(testBasePath + '/' + test_random_path2, {
property1: 'property1',
property2: 'property2',
property3: 'property3'
}, {noPublish: true}, timesCallback);
publisherclient.set(testBasePath + '/' + test_random_path2, {
property1: 'property1',
property2: 'property2',
property3: 'property3'
}, {noPublish: true}, timesCallback);

},
function(e){
},
function (e) {

if (e) return callback(e);
if (e) return callback(e);

listenerclient.get(testBasePath + '/' + '*', null, function (e, results) {

if (e) return callback(e);

expect(results.length).to.be(timesCount);

results.every(function(result){
results.every(function (result) {

/*
RESULT SHOULD LOOK LIKE THIS
{ property1: 'property1',
property2: 'property2',
property3: 'property3',
_meta:
{ modified: 1443606046766,
created: 1443606046766,
path: '/1_eventemitter_embedded_sanity/1443606046555_VkyH6cE1l/set_multiple/E17kSpqE1l' } }
*/
RESULT SHOULD LOOK LIKE THIS
{ property1: 'property1',
property2: 'property2',
property3: 'property3',
_meta:
{ modified: 1443606046766,
created: 1443606046766,
path: '/1_eventemitter_embedded_sanity/1443606046555_VkyH6cE1l/set_multiple/E17kSpqE1l' } }
*/

expect(result._meta.path.indexOf(testBasePath) == 0).to.be(true);

Expand All @@ -248,16 +249,15 @@ describe('1_eventemitter_embedded_sanity', function () {

});

});
});



} catch (e) {
callback(e);
}
});



it('should set data, and then merge a new document into the data without overwriting old fields', function (callback) {

this.timeout(default_timeout);
Expand Down Expand Up @@ -307,7 +307,7 @@ describe('1_eventemitter_embedded_sanity', function () {
}
});

it('should contain the same payload between 2 non-merging consecutive stores', function (done) {
it('should contain the same payload between 2 non-merging consecutive stores', function (done) {
var object = {param1: 10, param2: 20};
var firstTimeNonMergeConsecutive;

Expand All @@ -321,7 +321,7 @@ describe('1_eventemitter_embedded_sanity', function () {
done();
}
}, function (err) {
expect(err).to.not.be.ok();
expect(err).to.not.exist;
publisherclient.set('setTest/nonMergeConsecutive', object, {}, function (err) {
expect(err).to.not.be.ok();
publisherclient.set('setTest/nonMergeConsecutive', object, {}, function (err) {
Expand Down Expand Up @@ -572,7 +572,10 @@ describe('1_eventemitter_embedded_sanity', function () {
try {

//first listen for the change
listenerclient.on('/1_eventemitter_embedded_sanity/' + test_id + '/testsubscribe/data/event', {event_type: 'set', count: 1}, function (message) {
listenerclient.on('/1_eventemitter_embedded_sanity/' + test_id + '/testsubscribe/data/event', {
event_type: 'set',
count: 1
}, function (message) {

expect(listenerclient.events['/SET@/1_eventemitter_embedded_sanity/' + test_id + '/testsubscribe/data/event'].length).to.be(0);
callback();
Expand Down Expand Up @@ -726,7 +729,10 @@ describe('1_eventemitter_embedded_sanity', function () {
try {

//first listen for the change
listenerclient.on('/1_eventemitter_embedded_sanity/' + test_id + '/testsubscribe/data/event', {event_type: 'set', count: 1}, function (message) {
listenerclient.on('/1_eventemitter_embedded_sanity/' + test_id + '/testsubscribe/data/event', {
event_type: 'set',
count: 1
}, function (message) {

expect(listenerclient.events['/SET@/1_eventemitter_embedded_sanity/' + test_id + '/testsubscribe/data/event'].length).to.be(0);
callback();
Expand Down Expand Up @@ -884,14 +890,16 @@ describe('1_eventemitter_embedded_sanity', function () {
});



});

it('should unsubscribe from an event', function (callback) {

var currentListenerId;

listenerclient.on('/1_eventemitter_embedded_sanity/' + test_id + '/testsubscribe/data/on_off_test', {event_type: 'set', count: 0}, function (message) {
listenerclient.on('/1_eventemitter_embedded_sanity/' + test_id + '/testsubscribe/data/on_off_test', {
event_type: 'set',
count: 0
}, function (message) {

//we detach all listeners from the path here
////console.log('ABOUT OFF PATH');
Expand All @@ -900,7 +908,10 @@ describe('1_eventemitter_embedded_sanity', function () {
if (e)
return callback(new Error(e));

listenerclient.on('/1_eventemitter_embedded_sanity/' + test_id + '/testsubscribe/data/on_off_test', {event_type: 'set', count: 0},
listenerclient.on('/1_eventemitter_embedded_sanity/' + test_id + '/testsubscribe/data/on_off_test', {
event_type: 'set',
count: 0
},
function (message) {

////console.log('ON RAN');
Expand Down Expand Up @@ -960,8 +971,8 @@ describe('1_eventemitter_embedded_sanity', function () {

listenerclient.onAll(function (eventData, meta) {

if (meta.action == '/REMOVE@/1_eventemitter_embedded_sanity/' + test_id + '/testsubscribe/data/catch_all' ||
meta.action == '/SET@/1_eventemitter_embedded_sanity/' + test_id + '/testsubscribe/data/catch_all')
if (meta.action == '/REMOVE@/1_eventemitter_embedded_sanity/' + test_id + '/testsubscribe/data/catch_all' ||
meta.action == '/SET@/1_eventemitter_embedded_sanity/' + test_id + '/testsubscribe/data/catch_all')
caughtCount++;

if (caughtCount == 2)
Expand Down Expand Up @@ -1002,7 +1013,10 @@ describe('1_eventemitter_embedded_sanity', function () {

if (e) return callback(e);

listenerclient.on('/1_eventemitter_embedded_sanity/' + test_id + '/testsubscribe/data/off_all_test', {event_type: 'set', count: 0},
listenerclient.on('/1_eventemitter_embedded_sanity/' + test_id + '/testsubscribe/data/off_all_test', {
event_type: 'set',
count: 0
},
function (message) {
onHappened = true;
callback(new Error('this wasnt meant to happen'));
Expand Down Expand Up @@ -1033,5 +1047,35 @@ describe('1_eventemitter_embedded_sanity', function () {
});
});

})
;
it('should not publish with noPublish set', function (done) {
this.timeout(default_timeout);

var timeout;
//first listen for the change
listenerclient.on('/1_eventemitter_embedded_sanity/' + test_id + '/testNoPublish', {
event_type: 'set',
count: 1
}, function (message) {
clearTimeout(timeout);
setImmediate(function() {
expect(message).to.not.be.ok();
});
}, function (e) {
expect(e).to.not.be.ok();

timeout = setTimeout(function () {
listenerclient.off('/1_eventemitter_embedded_sanity/' + test_id + '/testNoPublish', function () {
done();
})
}, 1000);
publisherclient.set('/1_eventemitter_embedded_sanity/' + test_id + '/testNoPublish', {
property1: 'property1',
property2: 'property2',
property3: 'property3'
}, {noPublish: true}, function (e, result) {
expect(e).to.not.be.ok();
});
});

});
});
Loading

0 comments on commit abc1869

Please sign in to comment.