Skip to content

Instantly share code, notes, and snippets.

@JefClaes
Created January 30, 2014 15:38
Show Gist options
  • Select an option

  • Save JefClaes/8711243 to your computer and use it in GitHub Desktop.

Select an option

Save JefClaes/8711243 to your computer and use it in GitHub Desktop.
Why would events be published more than once?
var Config = require('../config.js').Config;
var eventstore = require('eventstore');
var storage = require('eventstore.mongodb');
var es;
var S4 = function() {
return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
};
var guid = function() {
return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
}
var publisher = {
publish : function(event) {
console.log(event);
}
};
module.exports = {
setUp: function (callback) {
es = eventstore.createStore();
storage.createStorage({ host: 'localhost', port: 27017, dbName: 'eventstore', eventsCollectionName: 'events', snapshotsCollectionName: 'snapshots' }, function(err, store) {
es.configure(function() {
es.use(store);
es.use(publisher);
});
es.start(callback);
});
},
tearDown: function (callback) {
callback();
},
when_creating_a_stream_it_is_created: function (test) {
var id = guid();
es.getEventStream(id, function(err, stream) {
if (err) throw err;
stream.addEvent({ 'name' : 'account_debited', 'accountNumber' : 'XXXAAA', 'timestamp' : new Date() });
stream.commit(function() {
es.getEventStream(id, 0, -1, function(err, stream) {
if (err) throw err;
test.equal(stream.events.length, 1);
test.done();
});
});
});
},
/* when_adding_an_event_to_an_existing_stream_it_is_added: function (test) {
var id = guid();
es.getEventStream(id, function(err, stream) {
if (err) throw err;
stream.addEvent({ 'name' : 'account_debited', 'accountNumber' : 'XXXAAA', 'timestamp' : new Date() });
stream.commit(function() {
es.getEventStream(id, function(err, stream) {
if (err) throw err;
stream.addEvent({ 'name' : 'account_credited', 'accountNumber' : 'XXXAAAA', 'timestamp' : new Date() });
stream.commit(function() {
es.getEventStream(id, 0, -1, function(err, stream) {
if (err) throw err;
test.equal(stream.events.length, 2);
test.done();
});
});
});
});
});
}, */
};
@adrai
Copy link

adrai commented Jan 30, 2014

can you try with the inMemory db or with

var es = eventstore.createStore({
forkDispatching: true
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment