Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

zerorpc

Package Overview
Dependencies
Maintainers
2
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zerorpc - npm Package Compare versions

Comparing version 0.9.4 to 0.9.5

.travis.yml

2

index.js
// Open Source Initiative OSI - The MIT License (MIT):Licensing
//
// The MIT License (MIT)
// Copyright (c) 2012 DotCloud Inc (opensource@dotcloud.com)
// Copyright (c) 2015 François-Xavier Bourlet (bombela+zerorpc@gmail.com)
//

@@ -6,0 +6,0 @@ // Permission is hereby granted, free of charge, to any person obtaining a

// Open Source Initiative OSI - The MIT License (MIT):Licensing
//
// The MIT License (MIT)
// Copyright (c) 2012 DotCloud Inc (opensource@dotcloud.com)
// Copyright (c) 2015 François-Xavier Bourlet (bombela+zerorpc@gmail.com)
//

@@ -6,0 +6,0 @@ // Permission is hereby granted, free of charge, to any person obtaining a

// Open Source Initiative OSI - The MIT License (MIT):Licensing
//
// The MIT License (MIT)
// Copyright (c) 2012 DotCloud Inc (opensource@dotcloud.com)
// Copyright (c) 2015 François-Xavier Bourlet (bombela+zerorpc@gmail.com)
//

@@ -100,3 +100,3 @@ // Permission is hereby granted, free of charge, to any person obtaining a

self.emit("protocol-error", "Invalid event: Bad buffer message");
self.close();
self.destroy();
}

@@ -139,3 +139,2 @@ } else if(event.name == "_zpc_hb") {

Channel.prototype.close = function() {
clearTimeout(this._heartbeatRunner);
this._state = CHANNEL_CLOSING;

@@ -146,2 +145,10 @@ this.emit("closing");

//Close and destroy channel
Channel.prototype.destroy = function() {
this._state = CHANNEL_CLOSED;
this.emit("closed");
clearTimeout(this._heartbeatRunner);
delete this._socket.channels[this.id];
}
//Sends as many outbound messages as possible

@@ -155,5 +162,3 @@ Channel.prototype.flush = function() {

if(this._state == CHANNEL_CLOSING && this._outBuffer.length() == 0) {
this._state = CHANNEL_CLOSED;
delete this._socket.channels[this.id];
this.emit("closed");
this.destroy();
}

@@ -198,3 +203,3 @@ };

self.emit("heartbeat-error", "Lost remote after " + (self._heartbeatInterval * 2) + "ms");
self.close();
self.destroy();
}

@@ -201,0 +206,0 @@

// Open Source Initiative OSI - The MIT License (MIT):Licensing
//
// The MIT License (MIT)
// Copyright (c) 2012 DotCloud Inc (opensource@dotcloud.com)
// Copyright (c) 2015 François-Xavier Bourlet (bombela+zerorpc@gmail.com)
//

@@ -47,5 +47,5 @@ // Permission is hereby granted, free of charge, to any person obtaining a

this._timeout = options.timeout || DEFAULT_TIMEOUT;
this._socket = socket.client(heartbeat);
this._socket = socket.client(heartbeat);
util.eventProxy(this._socket, this, "error");
//util.eventProxy(this._socket, this, "error");
}

@@ -74,2 +74,6 @@

Client.prototype.closed = function() {
return this._socket.closed();
};
//Calls a remote method

@@ -131,3 +135,3 @@ //method : String

//never happen
var error = util.createErrorResponse("ProtocolError", "Invalid event: Unknown event name", "");
var error = util.createErrorResponse("ProtocolError", "Invalid event: Unknown event name");
callbackErrorWrapper(error);

@@ -140,3 +144,3 @@ ch.close();

ch.on("protocol-error", function(error) {
var error = util.createErrorResponse("ProtocolError", error, "");
var error = util.createErrorResponse("ProtocolError", error);
callbackErrorWrapper(error);

@@ -147,3 +151,3 @@ });

ch.on("heartbeat-error", function(error) {
var error = util.createErrorResponse("HeartbeatError", error, "");
var error = util.createErrorResponse("HeartbeatError", error);
callbackErrorWrapper(error);

@@ -150,0 +154,0 @@ });

// Open Source Initiative OSI - The MIT License (MIT):Licensing
//
// The MIT License (MIT)
// Copyright (c) 2012 DotCloud Inc (opensource@dotcloud.com)
// Copyright (c) 2015 François-Xavier Bourlet (bombela+zerorpc@gmail.com)
//

@@ -6,0 +6,0 @@ // Permission is hereby granted, free of charge, to any person obtaining a

// Open Source Initiative OSI - The MIT License (MIT):Licensing
//
// The MIT License (MIT)
// Copyright (c) 2012 DotCloud Inc (opensource@dotcloud.com)
// Copyright (c) 2015 François-Xavier Bourlet (bombela+zerorpc@gmail.com)
//

@@ -41,3 +41,3 @@ // Permission is hereby granted, free of charge, to any person obtaining a

//Clear the timeout when the channel is closed
channel.on("closing", function() {
channel.on("closed", function() {
clearTimeout(runner);

@@ -47,2 +47,2 @@ });

exports.addTimeout = addTimeout;
exports.addTimeout = addTimeout;
// Open Source Initiative OSI - The MIT License (MIT):Licensing
//
// The MIT License (MIT)
// Copyright (c) 2012 DotCloud Inc (opensource@dotcloud.com)
// Copyright (c) 2015 François-Xavier Bourlet (bombela+zerorpc@gmail.com)
//

@@ -106,2 +106,5 @@ // Permission is hereby granted, free of charge, to any person obtaining a

for(var name in this._methods) {
if (name.indexOf('_') === 0) {
continue;
}
methods[name] = {

@@ -133,3 +136,3 @@ doc: "",

var sendError = function(error) {
var args = [error.type || "Error", error.message, error.stack];
var args = [error.name || "Error", error.message, error.stack];
ch.send("ERR", args);

@@ -213,2 +216,6 @@ ch.close();

Server.prototype.closed = function() {
return this._socket.closed();
};
exports.Server = Server;
// Open Source Initiative OSI - The MIT License (MIT):Licensing
//
// The MIT License (MIT)
// Copyright (c) 2012 DotCloud Inc (opensource@dotcloud.com)
// Copyright (c) 2015 François-Xavier Bourlet (bombela+zerorpc@gmail.com)
//

@@ -98,3 +98,4 @@ // Permission is hereby granted, free of charge, to any person obtaining a

self.channels = {};
self._heartbeatInterval = heartbeat
self._heartbeatInterval = heartbeat;
self._closed = false;

@@ -132,2 +133,5 @@ //Route events to a channel if possible; otherwise emit the event

MultiplexingSocket.prototype.close = function(linger) {
if (this.closed()) {
throw Error("Socket already closed");
}
if (linger !== undefined) {

@@ -138,5 +142,10 @@ this._zmqSocket.setsockopt(zmq.options.linger, linger);

this._zmqSocket.close();
for(var id in this.channels) this.channels[id].close();
for(var id in this.channels) this.channels[id].destroy();
this._closed = true;
};
MultiplexingSocket.prototype.closed = function() {
return this._closed;
};
MultiplexingSocket.prototype.setTimeout = function(timeout) {

@@ -143,0 +152,0 @@ };

// Open Source Initiative OSI - The MIT License (MIT):Licensing
//
// The MIT License (MIT)
// Copyright (c) 2012 DotCloud Inc (opensource@dotcloud.com)
// Copyright (c) 2015 François-Xavier Bourlet (bombela+zerorpc@gmail.com)
//

@@ -52,4 +52,9 @@ // Permission is hereby granted, free of charge, to any person obtaining a

// An error object
function createErrorResponse(name, message, traceback) {
return { name: name, message: message, traceback: traceback };
function createErrorResponse(name, message, stack) {
var e = Error(message);
e.name = name;
if (stack !== undefined) {
e.stack = stack;
}
return e;
}

@@ -59,2 +64,2 @@

exports.curTime = curTime;
exports.createErrorResponse = createErrorResponse;
exports.createErrorResponse = createErrorResponse;
{
"name": "zerorpc",
"version": "0.9.4",
"version": "0.9.5",
"main": "./index.js",
"author": "dotCloud <opensource@dotcloud.com>",
"author": "François-Xavier Bourlet <bombela+zerorpc@gmail.com>",
"description": "A port of ZeroRPC to node.js",

@@ -10,6 +10,6 @@

"name": "Francois-Xavier Bourlet",
"email": "fx@dotcloud.com"
"email": "bombela@gmail.com"
},{
"name": "Yusuf Simonson",
"email": "yusuf@dotcloud.com"
"email": "simonson@gmail.com"
}],

@@ -21,3 +21,3 @@ "scripts": {

"type": "git",
"url": "https://github.com/dotcloud/zerorpc-node"
"url": "https://github.com/0rpc/zerorpc-node"
},

@@ -40,6 +40,7 @@

"devDependencies": {
"nodeunit": "0.9.1"
},
"nodeunit": "0.9.1",
"temp": "0.8.1"
},
"license": "MIT"
}
zerorpc-node
============
ZeroRPC is a communication layer for distributed systems. zerorpc-node is a port of the original [ZeroRPC](https://github.com/dotcloud/zerorpc-python) for node.js. We have full client and server support for version 3 of the protocol, and clients/servers written in the Python version can communicate transparently with those written in node.js. This project is in alpha.
ZeroRPC is a communication layer for distributed systems. zerorpc-node is a port of the original [ZeroRPC](https://github.com/0rpc/zerorpc-python) for node.js. We have full client and server support for version 3 of the protocol, and clients/servers written in the Python version can communicate transparently with those written in node.js. This project is in alpha.

@@ -6,0 +6,0 @@ To install the package:

// Open Source Initiative OSI - The MIT License (MIT):Licensing
//
// The MIT License (MIT)
// Copyright (c) 2012 DotCloud Inc (opensource@dotcloud.com)
// Copyright (c) 2015 François-Xavier Bourlet (bombela+zerorpc@gmail.com)
//

@@ -25,37 +25,44 @@ // Permission is hereby granted, free of charge, to any person obtaining a

var zerorpc = require(".."),
_ = require("underscore");
tutil = require("./lib/testutil");
var rpcServer = new zerorpc.Server({
iter: function(from, to, step, reply) {
for(var i=from; i<to; i+=step) {
reply(null, i, true);
}
module.exports = {
setUp: function(cb) {
var endpoint = tutil.random_ipc_endpoint();
this.srv = new zerorpc.Server({
iter: function(from, to, step, reply) {
for(var i=from; i<to; i+=step) {
reply(null, i, true);
}
reply();
}
});
reply();
}
});
this.srv.bind(endpoint);
this.cli = new zerorpc.Client({ timeout: 5 });
this.cli.connect(endpoint);
cb();
},
tearDown: function(cb) {
this.cli.close();
this.srv.close();
cb();
},
testStreamingMethodWithBufferResets: function(test) {
test.expect(3000);
var nextExpected = 1;
rpcServer.bind("tcp://0.0.0.0:4242");
this.cli.invoke("iter", 1, 1000, 1, function(error, res, more) {
test.ifError(error);
var rpcClient = new zerorpc.Client({ timeout: 5 });
rpcClient.connect("tcp://localhost:4242");
exports.testStreamingMethodWithBufferResets = function(test) {
test.expect(3000);
var nextExpected = 1;
rpcClient.invoke("iter", 1, 1000, 1, function(error, res, more) {
test.ifError(error);
if(nextExpected == 1000) {
test.equal(res, undefined);
test.equal(more, false);
rpcServer.close();
test.done();
} else {
test.equal(res, nextExpected);
test.equal(more, true);
nextExpected += 1;
}
});
};
if(nextExpected == 1000) {
test.equal(res, undefined);
test.equal(more, false);
test.done();
} else {
test.equal(res, nextExpected);
test.equal(more, true);
nextExpected += 1;
}
});
}
};
// Open Source Initiative OSI - The MIT License (MIT):Licensing
//
// The MIT License (MIT)
// Copyright (c) 2012 DotCloud Inc (opensource@dotcloud.com)
// Copyright (c) 2015 François-Xavier Bourlet (bombela+zerorpc@gmail.com)
//

@@ -25,67 +25,78 @@ // Permission is hereby granted, free of charge, to any person obtaining a

var zerorpc = require(".."),
_ = require("underscore");
util = require("util");
tutil = require("./lib/testutil");
var rpcServer = new zerorpc.Server({
simpleError: function(reply) {
reply("This is an error, man!", undefined, false);
},
module.exports = {
setUp: function(cb) {
var endpoint = tutil.random_ipc_endpoint();
this.srv = new zerorpc.Server({
simpleError: function(reply) {
reply("This is an error, man!", undefined, false);
},
objectError: function(reply) {
reply(new Error("This is an error object, man!"), undefined, false);
},
objectError: function(reply) {
reply(new Error("This is an error object, man!"), undefined,
false);
},
streamError: function(reply) {
reply("This is a stream error, man!", undefined, false);
streamError: function(reply) {
reply("This is a stream error, man!", undefined, false);
var error = false;
var error = false;
try {
reply(null, "Should not happen");
} catch(e) {
error = true;
}
try {
reply(null, "Should not happen");
} catch(e) {
error = true;
}
if(!error) {
throw new Error("An error should have been thrown");
}
}
});
if(!error) {
throw new Error("An error should have been thrown");
}
}
});
rpcServer.bind("tcp://0.0.0.0:4243");
this.srv.bind(endpoint);
this.cli = new zerorpc.Client({ timeout: 5 });
this.cli.connect(endpoint);
cb();
},
tearDown: function(cb) {
this.cli.close();
this.srv.close();
cb();
},
testSimpleError: function(test) {
test.expect(4);
var rpcClient = new zerorpc.Client();
rpcClient.connect("tcp://localhost:4243");
this.cli.invoke("simpleError", function(error, res, more) {
test.equal(util.isError(error), true);
test.equal(error.message, "This is an error, man!");
test.equal(res, null);
test.equal(more, false);
test.done();
});
},
testObjectError: function(test) {
test.expect(4);
exports.testSimpleError = function(test) {
test.expect(3);
this.cli.invoke("objectError", function(error, res, more) {
test.equal(util.isError(error), true);
test.equal(error.message, "This is an error object, man!");
test.equal(res, null);
test.equal(more, false);
test.done();
});
},
testStreamError: function(test) {
test.expect(4);
rpcClient.invoke("simpleError", function(error, res, more) {
test.equal(error.message, "This is an error, man!");
test.equal(res, null);
test.equal(more, false);
test.done();
});
this.cli.invoke("streamError", function(error, res, more) {
test.equal(util.isError(error), true);
test.equal(error.message, "This is a stream error, man!");
test.equal(res, null);
test.equal(more, false);
test.done();
});
}
};
exports.testObjectError = function(test) {
test.expect(3);
rpcClient.invoke("objectError", function(error, res, more) {
test.equal(error.message, "This is an error object, man!");
test.equal(res, null);
test.equal(more, false);
test.done();
});
};
exports.testStreamError = function(test) {
test.expect(3);
rpcClient.invoke("streamError", function(error, res, more) {
test.equal(error.message, "This is a stream error, man!");
test.equal(res, null);
test.equal(more, false);
rpcServer.close();
test.done();
});
};
// Open Source Initiative OSI - The MIT License (MIT):Licensing
//
// The MIT License (MIT)
// Copyright (c) 2012 DotCloud Inc (opensource@dotcloud.com)
// Copyright (c) 2015 François-Xavier Bourlet (bombela+zerorpc@gmail.com)
//

@@ -25,60 +25,69 @@ // Permission is hereby granted, free of charge, to any person obtaining a

var zerorpc = require(".."),
_ = require("underscore");
tutil = require("./lib/testutil");
var killed = false;
module.exports = {
setUp: function(cb) {
var self = this;
var heartbeat = 1000;
var endpoint = tutil.random_ipc_endpoint();
this.srv = new zerorpc.Server({
lazyErrorableIter: function(reply) {
var counter = 0;
var rpcServer = new zerorpc.Server({
lazyErrorableIter: function(reply) {
var counter = 0;
var interval = setInterval(function() {
try {
reply(null, counter, true);
} catch(e) {
self.killed = true;
clearTimeout(interval);
}
var interval = setInterval(function() {
try {
reply(null, counter, true);
} catch(e) {
killed = true;
clearTimeout(interval);
}
counter++;
}, 250);
}
}, heartbeat);
this.srv.bind(endpoint);
this.srv.on('error', function(err) {
//console.log('on error', err);
});
this.cli = new zerorpc.Client({ timeout: 11000, heartbeat: heartbeat });
this.cli.connect(endpoint);
this.killed = false;
cb();
},
tearDown: function(cb) {
if (!this.cli.closed()) {
this.cli.close();
}
this.srv.close();
cb();
},
testClose: function(test) {
var self = this;
test.expect(1);
counter++;
}, 3000);
}
});
var hit = false;
this.cli.invoke("lazyErrorableIter", function(error, res, more) {
if(hit) {
test.ok(false,
"lazyErrorableIter() should not have been called more than once");
return;
}
hit = true;
test.ifError(error);
self.cli.close();
rpcServer.on("error", function(error) {});
rpcServer.bind("tcp://0.0.0.0:4244");
var rpcClient = new zerorpc.Client({ timeout: 11000 });
rpcClient.connect("tcp://localhost:4244");
exports.testClose = function(test) {
test.expect(1);
var hit = false;
rpcClient.invoke("lazyErrorableIter", function(error, res, more) {
if(hit) {
test.ok(false, "lazyErrorableIter() should not have been called more than once");
} else {
hit = true;
test.ifError(error);
rpcClient.close();
//Repeatedly poll for a closed connection - if after 20 seconds
//(2 heartbeats) the connection isn't closed, throw an error
var numChecks = 0;
var checkTimeout = setInterval(function() {
if(killed) {
clearTimeout(checkTimeout);
rpcServer.close();
test.done();
return;
}
if(numChecks++ == 20) {
test.ok(false, "Connection not closed on the remote end");
}
}, 1000);
}
});
////Repeatedly poll for a closed connection - if after 20 seconds
////(2 heartbeats) the connection isn't closed, throw an error
var numChecks = 0;
var checkTimeout = setInterval(function() {
if(self.killed) {
clearTimeout(checkTimeout);
test.done();
} else if(numChecks++ == 20) {
test.ok(false, "Connection not closed on the remote end");
}
}, 1000);
});
},
};
// Open Source Initiative OSI - The MIT License (MIT):Licensing
//
// The MIT License (MIT)
// Copyright (c) 2012 DotCloud Inc (opensource@dotcloud.com)
// Copyright (c) 2015 François-Xavier Bourlet (bombela+zerorpc@gmail.com)
//

@@ -25,85 +25,91 @@ // Permission is hereby granted, free of charge, to any person obtaining a

var zerorpc = require(".."),
_ = require("underscore");
_ = require("underscore");
tutil = require("./lib/testutil");
var rpcServer = new zerorpc.Server({
addMan: function(sentence, reply) {
reply(null, sentence + ", man!", false);
},
module.exports = {
setUp: function(cb) {
var endpoint = tutil.random_ipc_endpoint();
this.srv = new zerorpc.Server({
addMan: function(sentence, reply) {
reply(null, sentence + ", man!", false);
},
add42: function(n, reply) {
reply(null, n + 42, false);
}
});
add42: function(n, reply) {
reply(null, n + 42, false);
}
});
this.srv.bind(endpoint);
this.cli = new zerorpc.Client({ timeout: 5 });
this.cli.connect(endpoint);
cb();
},
tearDown: function(cb) {
this.cli.close();
this.srv.close();
cb();
},
testNormalStringMethod: function(test) {
test.expect(3);
rpcServer.bind("tcp://0.0.0.0:4245");
this.cli.invoke("addMan", "This is not an error",
function(error, res, more) {
test.ifError(error);
test.deepEqual(res, "This is not an error, man!");
test.equal(more, false);
test.done();
});
},
testNormalIntMethod: function(test) {
test.expect(3);
var rpcClient = new zerorpc.Client({ timeout: 5 });
rpcClient.connect("tcp://localhost:4245");
this.cli.invoke("add42", 30, function(error, res, more) {
test.ifError(error);
test.deepEqual(res, 72);
test.equal(more, false);
test.done();
});
},
testIntrospector: function(test) {
test.expect(8);
exports.testNormalStringMethod = function(test) {
test.expect(3);
this.cli.invoke("_zerorpc_inspect", function(error, res, more) {
test.ifError(error);
rpcClient.invoke("addMan", "This is not an error", function(error, res, more) {
test.ifError(error);
test.deepEqual(res, "This is not an error, man!");
test.equal(more, false);
test.done();
});
};
test.equal(typeof(res.name), "string");
test.equal(_.keys(res.methods).length, 2);
exports.testNormalIntMethod = function(test) {
test.expect(3);
for(var key in res.methods) {
test.equal(res.methods[key].doc, "");
}
rpcClient.invoke("add42", 30, function(error, res, more) {
test.ifError(error);
test.deepEqual(res, 72);
test.equal(more, false);
test.done();
});
};
test.deepEqual(res.methods.add42.args.length, 1);
test.deepEqual(res.methods.add42.args[0].name, "n");
test.equal(more, false);
test.done();
});
},
testNonExistentMethod: function(test) {
test.expect(3);
exports.testIntrospector = function(test) {
test.expect(8);
this.cli.invoke("non_existent", function(error, res, more) {
test.ok(error);
test.equal(res, null);
test.equal(more, false);
test.done();
});
},
testBadClient: function(test) {
test.expect(3);
rpcClient.invoke("_zerorpc_inspect", function(error, res, more) {
test.ifError(error);
var badRpcClient = new zerorpc.Client({ timeout: 5 });
badRpcClient.connect(tutil.random_ipc_endpoint());
test.equal(typeof(res.name), "string");
test.equal(_.keys(res.methods).length, 2);
for(var key in res.methods) {
test.equal(res.methods[key].doc, "");
}
test.deepEqual(res.methods.add42.args.length, 1);
test.deepEqual(res.methods.add42.args[0].name, "n");
test.equal(more, false);
test.done();
});
badRpcClient.invoke("add42", 30, function(error, res, more) {
test.ok(error);
test.equal(res, null);
test.equal(more, false);
badRpcClient.close();
test.done();
});
}
};
exports.testNonExistentMethod = function(test) {
test.expect(3);
rpcClient.invoke("non_existent", function(error, res, more) {
test.ok(error);
test.equal(res, null);
test.equal(more, false);
test.done();
});
};
exports.testBadClient = function(test) {
test.expect(3);
var badRpcClient = new zerorpc.Client();
badRpcClient.connect("tcp://localhost:4040");
badRpcClient.invoke("add42", 30, function(error, res, more) {
test.ok(error);
test.equal(res, null);
test.equal(more, false);
rpcServer.close();
test.done();
});
};
// Open Source Initiative OSI - The MIT License (MIT):Licensing
//
// The MIT License (MIT)
// Copyright (c) 2012 DotCloud Inc (opensource@dotcloud.com)
// Copyright (c) 2015 François-Xavier Bourlet (bombela+zerorpc@gmail.com)
//

@@ -27,24 +27,28 @@ // Permission is hereby granted, free of charge, to any person obtaining a

var zerorpc = require(".."),
_ = require("underscore");
tutil = require("./lib/testutil");
var rpcServer = new zerorpc.Server({
helloWorld: function(reply) {
reply(null, "Hello World!")
}
});
module.exports = {
testRepro10: function(test) {
var endpoint = tutil.random_ipc_endpoint();
srv = new zerorpc.Server({
helloWorld: function(reply) {
reply(null, "Hello World!")
}
});
rpcServer.bind("tcp://0.0.0.0:4247");
srv.bind(endpoint);
cli = new zerorpc.Client({ timeout: 5 });
var rpcClient = new zerorpc.Client({ timeout: 5 });
exports.testRepro10 = function(test) {
setTimeout(function() {
rpcClient.connect("tcp://localhost:4247");
rpcClient.invoke("helloWorld", function(error, res, more) {
test.equal(error, null);
test.equal(res, "Hello World!");
test.equal(more, false);
rpcServer.close();
test.done();
});
}, 10000);
};
setTimeout(function() {
cli.connect(endpoint);
cli.invoke("helloWorld", function(error, res, more) {
test.equal(error, null);
test.equal(res, "Hello World!");
test.equal(more, false);
cli.close();
srv.close();
test.done();
});
}, 10000);
}
};
// Open Source Initiative OSI - The MIT License (MIT):Licensing
//
// The MIT License (MIT)
// Copyright (c) 2012 DotCloud Inc (opensource@dotcloud.com)
// Copyright (c) 2015 François-Xavier Bourlet (bombela+zerorpc@gmail.com)
//

@@ -25,57 +25,64 @@ // Permission is hereby granted, free of charge, to any person obtaining a

var zerorpc = require(".."),
_ = require("underscore");
tutil = require("./lib/testutil");
var rpcServer = new zerorpc.Server({
lazyIter: function(from, to, step, reply) {
var counter = from;
function lazyIterRunner(test, cli, callback) {
var nextExpected = 10;
var interval = setInterval(function() {
if(counter < to) {
reply(null, counter, true);
counter += step;
} else {
reply();
clearTimeout(interval);
}
}, 3000);
}
});
cli.invoke("lazyIter", 10, 20, 2, function(error, res, more) {
test.ifError(error);
rpcServer.bind("tcp://0.0.0.0:4246");
if(nextExpected == 20) {
test.equal(res, null);
test.equal(more, false);
callback();
} else {
test.equal(res, nextExpected);
test.equal(more, true);
nextExpected += 2;
}
});
};
var rpcClient = new zerorpc.Client({ timeout: 5 });
rpcClient.connect("tcp://localhost:4246");
module.exports = {
setUp: function(cb) {
var endpoint = tutil.random_ipc_endpoint();
this.srv = new zerorpc.Server({
lazyIter: function(from, to, step, reply) {
var counter = from;
function lazyIterRunner(test, callback) {
var nextExpected = 10;
var interval = setInterval(function() {
if(counter < to) {
reply(null, counter, true);
counter += step;
} else {
reply();
clearTimeout(interval);
}
}, 1000);
}
});
this.srv.bind(endpoint);
this.cli = new zerorpc.Client({ timeout: 5 });
this.cli.connect(endpoint);
cb();
},
tearDown: function(cb) {
this.cli.close();
this.srv.close();
cb();
},
testConcurrentRequests: function(test) {
test.expect(90);
rpcClient.invoke("lazyIter", 10, 20, 2, function(error, res, more) {
test.ifError(error);
var results = 0;
if(nextExpected == 20) {
test.equal(res, null);
test.equal(more, false);
callback();
} else {
test.equal(res, nextExpected);
test.equal(more, true);
nextExpected += 2;
}
});
}
exports.testConcurrentRequests = function(test) {
test.expect(90);
var results = 0;
for(var i=0; i<5; i++) {
lazyIterRunner(test, function() {
results++;
if(results === 5) {
rpcServer.close();
test.done();
}
});
}
for(var i=0; i<5; i++) {
lazyIterRunner(test, this.cli, function() {
results++;
if(results === 5) {
test.done();
}
});
}
}
};
// Open Source Initiative OSI - The MIT License (MIT):Licensing
//
// The MIT License (MIT)
// Copyright (c) 2012 DotCloud Inc (opensource@dotcloud.com)
// Copyright (c) 2015 François-Xavier Bourlet (bombela+zerorpc@gmail.com)
//

@@ -25,30 +25,36 @@ // Permission is hereby granted, free of charge, to any person obtaining a

var zerorpc = require(".."),
_ = require("underscore");
tutil = require("./lib/testutil");
var rpcServer = new zerorpc.Server({
quiet: function(reply) {
setTimeout(function() {
try {
reply(null, "Should not happen", false);
} catch (e) { /* expected */ }
}, 6 * 1000);
}
});
module.exports = {
setUp: function(cb) {
var endpoint = tutil.random_ipc_endpoint();
this.srv = new zerorpc.Server({
quiet: function(reply) {
setTimeout(function() {
try {
reply(null, "Should not happen", false);
} catch (e) { /* expected */ }
}, 6 * 1000);
}
});
this.srv.bind(endpoint);
this.cli = new zerorpc.Client({ timeout: 5 });
this.cli.connect(endpoint);
cb();
},
tearDown: function(cb) {
this.cli.close();
this.srv.close();
cb();
},
testQuiet: function(test) {
test.expect(3);
rpcServer.bind("tcp://0.0.0.0:4248");
var rpcClient = new zerorpc.Client({ timeout: 5 });
rpcClient.connect("tcp://localhost:4248");
exports.testQuiet = function(test) {
test.expect(3);
rpcClient.invoke("quiet", function(error, res, more) {
test.equal(error.name, "TimeoutExpired");
test.equal(res, null);
test.equal(more, false);
rpcServer.close();
rpcClient.close();
test.done();
});
};
this.cli.invoke("quiet", function(error, res, more) {
test.equal(error.name, "TimeoutExpired");
test.equal(res, null);
test.equal(more, false);
test.done();
});
}
};

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc