This repository has been archived by the owner on Jan 31, 2018. It is now read-only.
forked from dfellis/multitransport-jsonrpc
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix compressed transport data passing, and add tests.
- Loading branch information
David Ellis
committed
May 18, 2015
1 parent
0f061c2
commit 2bcd4d5
Showing
4 changed files
with
48 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
var jsonrpc = require('../../lib/index'); | ||
var JsonRpcServer = jsonrpc.server; | ||
var JsonRpcChildProcTransport = jsonrpc.transports.server.childProcess; | ||
|
||
var server = new JsonRpcServer(new JsonRpcChildProcTransport({ compressed: true }), { | ||
loopback: function(obj, callback) { | ||
callback(null, obj); | ||
}, | ||
failure: function(obj, callback) { | ||
var error = new Error("Whatchoo talkin' 'bout, Willis?"); | ||
error.prop = 1; | ||
callback(error); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
var jsonrpc = require('../lib/index'); | ||
var ChildProcessTransport = jsonrpc.transports.client.childProcess; | ||
var JsonRpcClient = jsonrpc.client; | ||
var childProcess = require('child_process'); | ||
|
||
var child = childProcess.fork(__dirname + '/child/child-compressed.js'); | ||
var jsonRpcClient = new JsonRpcClient(new ChildProcessTransport(child, { compressed: true })); | ||
jsonRpcClient.register(['loopback', 'failure']); | ||
|
||
exports.loopback = function(test) { | ||
test.expect(2); | ||
jsonRpcClient.loopback({foo: 'bar'}, function(err, result) { | ||
test.ok(!!result, 'result exists'); | ||
test.equal(result.foo, 'bar', 'Looped back correctly'); | ||
test.done(); | ||
}); | ||
}; | ||
|
||
exports.failureTcp = function(test) { | ||
test.expect(3); | ||
jsonRpcClient.failure({foo: 'bar'}, function(err) { | ||
test.ok(!!err, 'error exists'); | ||
test.equal("Whatchoo talkin' 'bout, Willis?", err.message, 'The error message was received correctly'); | ||
test.equal(1, err.prop, 'The error message was received correctly'); | ||
child.kill(); | ||
test.done(); | ||
}); | ||
}; |