You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
1.8 KiB

var steed = require("steed")();
describeAscoltatore("zeromq", function() {
var toClose = null;
beforeEach(function() {
toClose = [this.instance];
});
afterEach(function(done) {
steed.each(toClose, function(i, cb) {
i.close(cb);
}, setImmediate.bind(null, done));
});
it("should sync two instances", function(done) {
var instance = this.instance;
var other = new ascoltatori.ZeromqAscoltatore(zeromqSettings());
steed.series([
function(cb) {
other.on("ready", cb);
},
function(cb) {
toClose.push(other);
// we connect to the other instance control channel
other.connect(instance._opts.controlPort, cb);
},
function(cb) {
instance.subscribe("world", wrap(done), cb);
},
function(cb) {
other.publish("world", null, cb);
}
]);
});
it("should sync three instances", function(done) {
var instance = this.instance;
var other = new ascoltatori.ZeromqAscoltatore(zeromqSettings());
var other2 = new ascoltatori.ZeromqAscoltatore(zeromqSettings());
var count = 2;
var donner = function() {
if (--count === 0)  {
done();
}
};
steed.series([
function(cb) {
other.on("ready", cb);
},
function(cb) {
toClose.push(other);
other2.on("ready", cb);
},
function(cb) {
toClose.push(other2);
other.connect(instance._opts.controlPort);
other2.connect(instance._opts.controlPort);
setTimeout(cb, 500);
},
function(cb) {
other2.subscribe("world", donner, cb);
},
function(cb) {
other.subscribe("world", donner, cb);
},
function(cb) {
instance.publish("world", null, cb);
}
]);
});
});