diff options
author | Tim Emiola <tbetbetbe@users.noreply.github.com> | 2015-01-29 15:06:20 -0800 |
---|---|---|
committer | Tim Emiola <tbetbetbe@users.noreply.github.com> | 2015-01-29 15:06:20 -0800 |
commit | c4e09f667b0f58821ce137761deb4a62f8b5a3f0 (patch) | |
tree | 66f56cc92b48e479ae6a0daa3a48dc30d58a81e2 | |
parent | 3726a4d4770896892eda72fd0786d12245109527 (diff) | |
parent | bca2f955bad6b86bf220d9f565fbfa213350c911 (diff) |
Merge pull request #292 from murgatroid99/node_cancellation_interop_tests
Added cancellation interop tests to Node interop client
-rw-r--r-- | src/node/interop/interop_client.js | 43 | ||||
-rw-r--r-- | src/node/test/interop_sanity_test.js | 8 |
2 files changed, 49 insertions, 2 deletions
diff --git a/src/node/interop/interop_client.js b/src/node/interop/interop_client.js index 9306317b68..ce18f77fe7 100644 --- a/src/node/interop/interop_client.js +++ b/src/node/interop/interop_client.js @@ -199,7 +199,6 @@ function pingPong(client, done) { /** * Run the empty_stream test. - * NOTE: This does not work, but should with the new invoke API * @param {Client} client The client to test against * @param {function} done Callback to call when the test is completed. Included * primarily for use with mocha @@ -219,6 +218,44 @@ function emptyStream(client, done) { } /** + * Run the cancel_after_begin test. + * @param {Client} client The client to test against + * @param {function} done Callback to call when the test is completed. Included + * primarily for use with mocha + */ +function cancelAfterBegin(client, done) { + var call = client.streamingInputCall(function(err, resp) { + assert.strictEqual(err.code, grpc.status.CANCELLED); + done(); + }); + call.cancel(); +} + +/** + * Run the cancel_after_first_response test. + * @param {Client} client The client to test against + * @param {function} done Callback to call when the test is completed. Included + * primarily for use with mocha + */ +function cancelAfterFirstResponse(client, done) { + var call = client.fullDuplexCall(); + call.write({ + response_type: testProto.PayloadType.COMPRESSABLE, + response_parameters: [ + {size: 31415} + ], + payload: {body: zeroBuffer(27182)} + }); + call.on('data', function(data) { + call.cancel(); + }); + call.on('status', function(status) { + assert.strictEqual(status.code, grpc.status.CANCELLED); + done(); + }); +} + +/** * Map from test case names to test functions */ var test_cases = { @@ -227,7 +264,9 @@ var test_cases = { client_streaming: clientStreaming, server_streaming: serverStreaming, ping_pong: pingPong, - empty_stream: emptyStream + empty_stream: emptyStream, + cancel_after_begin: cancelAfterBegin, + cancel_after_first_response: cancelAfterFirstResponse }; /** diff --git a/src/node/test/interop_sanity_test.js b/src/node/test/interop_sanity_test.js index 6cc7d444cd..7ecaad833d 100644 --- a/src/node/test/interop_sanity_test.js +++ b/src/node/test/interop_sanity_test.js @@ -71,4 +71,12 @@ describe('Interop tests', function() { it('should pass empty_stream', function(done) { interop_client.runTest(port, name_override, 'empty_stream', true, done); }); + it('should pass cancel_after_begin', function(done) { + interop_client.runTest(port, name_override, 'cancel_after_begin', true, + done); + }); + it('should pass cancel_after_first_response', function(done) { + interop_client.runTest(port, name_override, 'cancel_after_first_response', + true, done); + }); }); |