Skip to content

Commit

Permalink
Improved test, fixed callback name
Browse files Browse the repository at this point in the history
  • Loading branch information
x25 committed Aug 10, 2014
1 parent ebf79db commit b0bdcb7
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 6 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ var publisher = new Pub();
publisher.listen(8002);

setInterval(function () {

publisher.publish('channel_one', 'message_one');
publisher.publish('channel_two', {message: 'two'});
publisher.publish('channel_three', ['message', 'three']);

}, 1000);
```

Expand All @@ -38,6 +40,7 @@ subscriber.connect(8002, '127.0.0.1');
subscriber.subscribe('channel_two');

subscriber.on('message', function (channel, data) {

console.log(channel, data);
});
```
Expand Down
4 changes: 2 additions & 2 deletions lib/publisher.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Publisher.prototype.connect = function (port, host) {

socket.on('error', function (e) {

console.error(e);
self.emit('log', 'debug', 'publisher.error', e);
});

socket.on('connect', function () {
Expand Down Expand Up @@ -107,7 +107,7 @@ Publisher.prototype.connect = function (port, host) {

};

setTimeout(f, 1000);
setTimeout(r, 1000);

} else {

Expand Down
2 changes: 1 addition & 1 deletion lib/subscriber.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Subscriber.prototype.connect = function (port, host) {

socket.on('error', function (e) {

console.error(e);
self.emit('log', 'debug', 'subscriber.error', e);
});

socket.on('connect', function () {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pub-sub-js",
"version": "1.0.1",
"version": "1.1.0",
"description": "Distributed publish/subscribe messaging system",
"main": "index.js",
"scripts": {
Expand Down
33 changes: 31 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ module.exports = {

testSubToPub: function (test) {

test.expect(4);
test.expect(5);

var publisher = new PubSub.Publisher();

Expand All @@ -75,9 +75,24 @@ module.exports = {

subscriber.subscribe('channel_one');

subscriber.subscribe('channel_two');

subscriber.connect(8002, '127.0.0.1');

subscriber.subscribe('channel_two');
subscriber.connect(8002, '127.0.0.1');

subscriber.connect(8003, '127.0.0.1');

subscriber.subscribe('channel_one');

try {

subscriber.subscribe('a\nb');

} catch (e) {

test.ok(true);
}

var n = 1;

Expand Down Expand Up @@ -115,8 +130,14 @@ module.exports = {

subscriber.unsubscribe('channel_two');

subscriber.unsubscribe('channel_two');

subscriber.unsubscribe('channel_x');

subscriber.disconnect(8002, '127.0.0.1');

subscriber.disconnect(8003, '127.0.0.1');

publisher.close();

setTimeout(function () {
Expand All @@ -138,6 +159,10 @@ module.exports = {

publisher.connect(8002, '127.0.0.1');

publisher.connect(8002, '127.0.0.1');

publisher.connect(8003, '127.0.0.1');

setTimeout(function () {

publisher.publish('channel_one', 'message_one');
Expand Down Expand Up @@ -190,8 +215,12 @@ module.exports = {

subscriber.unsubscribe('channel_two');

subscriber.unsubscribe('channel_undefined');

publisher.disconnect(8002, '127.0.0.1');

publisher.disconnect(8003, '127.0.0.1');

subscriber.close();

setTimeout(function () {
Expand Down

0 comments on commit b0bdcb7

Please sign in to comment.