Skip to content

Commit

Permalink
move discover emit into own test
Browse files Browse the repository at this point in the history
  • Loading branch information
nomilous committed Jul 1, 2016
1 parent bc9f201 commit 8b0d204
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 43 deletions.
43 changes: 0 additions & 43 deletions test/test-benchmark/9_multiple_subscribers_benchmarks.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,47 +284,4 @@ describe(name, function() {

// require('benchmarket').stop();

context('discover', function() {

createServerAndSubscribers(1, 'info');

before('subscribe to events', function(done) {
var _this = this;
var client = this.subscribers[0];

// client.onAll(
// function handler(data, meta) {
// process.nextTick(function() {
// debug('XXX -- END TEST -- received emit()');
// _this.endTest();
// });
// },
// function ok() {
// done();
// }
// );

// client.on('*', function handler(data, meta) {
// client.on('/some/path', function handler(data, meta) {
client.on('/some/*', function handler(data, meta) {
// client.on('/some/*', {event_type: 'set'}, function handler(data, meta) {
process.nextTick(function() {
debug('XXX -- END TEST -- received emit()');
_this.endTest();
});
}).then(function(){
done();
}).catch(done);
});

it('emits 1 event', function(done) {

debug('XXX -- START TEST -- calling set()');
this.endTest = done;
this.publisher.set('/some/path', {da: 'ta'});

});

});

});
95 changes: 95 additions & 0 deletions test/test-discover/1_subscribe_to_events.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
var path = require('path');
var name = path.basename(__filename);
var happn = require('../../lib/index');
var service = happn.service;
var client = happn.client;
var Promise = require('bluebird');
var debug = require('debug')('TEST');

describe(name, function() {

function createServerAndSubscribers(subscriberCount, loglevel) {

before('start happn server', function(done) {
this.timeout(0);
var _this = this;
service.create({
utils: {
logLevel: loglevel || 'warn'
}
}).then(function(server) {
_this.happnServer = server;
done();
}).catch(done);
});

after('stop happn server', function(done) {
this.timeout(0);
if (this.happnServer) {
return this.happnServer.stop(done);
}
done();
});

before('start subscribers', function(done) {
this.timeout(0);
var _this = this;
Promise.resolve(new Array( subscriberCount )).map(
function() {
return client.create({
plugin: happn.client_plugins.intra_process,
context: _this.happnServer
})
}
).then(function(subscribersArray) {
_this.subscribers = subscribersArray;
_this.publisher = subscribersArray[0]; // first subscriber also publisher
done();
}).catch(done);
});
}

context('discover', function() {

createServerAndSubscribers(1, 'info');

before('subscribe to events', function(done) {
var _this = this;
var client = this.subscribers[0];

// client.onAll(
// function handler(data, meta) {
// process.nextTick(function() {
// debug('XXX -- END TEST -- received emit()');
// _this.endTest();
// });
// },
// function ok() {
// done();
// }
// );

// client.on('*', function handler(data, meta) {
// client.on('/some/path', function handler(data, meta) {
client.on('/some/*', function handler(data, meta) {
// client.on('/some/*', {event_type: 'set'}, function handler(data, meta) {
process.nextTick(function() {
debug('XXX -- END TEST -- received emit()');
_this.endTest();
});
}).then(function(){
done();
}).catch(done);
});

it('emits 1 event', function(done) {

debug('XXX -- START TEST -- calling set()');
this.endTest = done;
this.publisher.set('/some/path', {da: 'ta'});

});

});

});

0 comments on commit 8b0d204

Please sign in to comment.