Skip to content

Commit

Permalink
Closing issue zeromq#248 : Added unit tests on socket.pub-sub to test…
Browse files Browse the repository at this point in the history
… and demonstrate the use of subscriber message filtering with complex string and binary arities
  • Loading branch information
xelinorg authored and lgeiger committed Jul 17, 2018
1 parent ecd158a commit 216e334
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions test/socket.pub-sub.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,61 @@ describe('socket.pub-sub', function(){
});
});

it('should subscribe to character arguments', function(done){

sub.subscribe('ABC012');

sub.on('message', function (msg) {

msg.should.be.an.instanceof(Buffer);
msg.toString().should.equal('ABC012');
sub.close();
return done();
});

var addr = "inproc://stuff_sspsfa";

sub.bind(addr, function (error) {
if (error) throw error;
pub.connect(addr);

setTimeout(function() {
pub.send('012');
pub.send('ABC');
pub.send('MSG');
pub.send('ABC012');
}, 100.0);

});
})

it('should subscribe to binary argument', function(done){


sub.subscribe(Buffer.from(new Uint8Array([65, 66, 67, 48, 49, 50])));

sub.on('message', function (msg) {
msg.should.be.an.instanceof(Buffer);
msg.toString().should.equal('ABC0123');
sub.close();
return done();

});

var addr = "inproc://stuff_sspsfb";

sub.bind(addr, function (error) {
if (error) throw error;
pub.connect(addr);

setTimeout(function() {
pub.send('ABC');
pub.send('MSG');
pub.send('MSG1');
pub.send(Buffer.from(new Uint8Array([65, 66, 67, 48, 49, 50, 51])));
}, 100.0);

});

})
});

0 comments on commit 216e334

Please sign in to comment.