diff --git a/src/node/interop/interop_client.js b/src/node/interop/interop_client.js index 9306317b68f..ce18f77fe71 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 @@ -218,6 +217,44 @@ function emptyStream(client, done) { call.end(); } +/** + * 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 */ @@ -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 6cc7d444cdc..7ecaad833d4 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); + }); });