From 016bb50e763978b27ddf73612f65fdd84b89f478 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Mon, 9 Feb 2015 15:55:10 -0800 Subject: Extension module now compiles and some tests pass --- src/node/test/call_test.js | 128 ++++++++++++++++++--------------------------- 1 file changed, 52 insertions(+), 76 deletions(-) (limited to 'src/node/test/call_test.js') diff --git a/src/node/test/call_test.js b/src/node/test/call_test.js index dfa9aaa1a7..e341092ff8 100644 --- a/src/node/test/call_test.js +++ b/src/node/test/call_test.js @@ -98,104 +98,80 @@ describe('call', function() { }, TypeError); }); }); - describe('addMetadata', function() { - it('should succeed with a map from strings to string arrays', function() { + describe('startBatch', function() { + it('should fail without an object and a function', function() { var call = new grpc.Call(channel, 'method', getDeadline(1)); - assert.doesNotThrow(function() { - call.addMetadata({'key': ['value']}); + assert.throws(function() { + call.startBatch(); }); - assert.doesNotThrow(function() { - call.addMetadata({'key1': ['value1'], 'key2': ['value2']}); + assert.throws(function() { + call.startBatch({}); + }); + assert.throws(function() { + call.startBatch(null, function(){}); }); }); - it('should succeed with a map from strings to buffer arrays', function() { + it.skip('should succeed with an empty object', function(done) { var call = new grpc.Call(channel, 'method', getDeadline(1)); assert.doesNotThrow(function() { - call.addMetadata({'key': [new Buffer('value')]}); - }); - assert.doesNotThrow(function() { - call.addMetadata({'key1': [new Buffer('value1')], - 'key2': [new Buffer('value2')]}); + call.startBatch({}, function(err) { + assert.ifError(err); + done(); + }); }); }); - it('should fail with other parameter types', function() { + }); + describe('startBatch with metadata', function() { + it('should succeed with a map of strings to string arrays', function(done) { var call = new grpc.Call(channel, 'method', getDeadline(1)); - assert.throws(function() { - call.addMetadata(); + assert.doesNotThrow(function() { + var batch = {}; + batch[grpc.opType.SEND_INITIAL_METADATA] = {'key1': ['value1'], + 'key2': ['value2']}; + call.startBatch(batch, function(err, resp) { + assert.ifError(err); + assert.deepEqual(resp, {'send metadata': true}); + done(); + }); }); - assert.throws(function() { - call.addMetadata(null); - }, TypeError); - assert.throws(function() { - call.addMetadata('value'); - }, TypeError); - assert.throws(function() { - call.addMetadata(5); - }, TypeError); }); - it('should fail if invoke was already called', function(done) { + it('should succeed with a map of strings to buffer arrays', function(done) { var call = new grpc.Call(channel, 'method', getDeadline(1)); - call.invoke(function() {}, - function() {done();}, - 0); - assert.throws(function() { - call.addMetadata({'key': ['value']}); - }, function(err) { - return err.code === grpc.callError.ALREADY_INVOKED; + assert.doesNotThrow(function() { + var batch = {}; + batch[grpc.opType.SEND_INITIAL_METADATA] = { + 'key1': [new Buffer('value1')], + 'key2': [new Buffer('value2')] + }; + call.startBatch(batch, function(err, resp) { + assert.ifError(err); + assert.deepEqual(resp, {'send metadata': true}); + done(); + }); }); - // Cancel to speed up the test - call.cancel(); }); - }); - describe('invoke', function() { - it('should fail with fewer than 3 arguments', function() { + it('should fail with other parameter types', function() { var call = new grpc.Call(channel, 'method', getDeadline(1)); assert.throws(function() { - call.invoke(); - }, TypeError); - assert.throws(function() { - call.invoke(function() {}); - }, TypeError); - assert.throws(function() { - call.invoke(function() {}, - function() {}); - }, TypeError); - }); - it('should work with 2 args and an int', function(done) { - assert.doesNotThrow(function() { - var call = new grpc.Call(channel, 'method', getDeadline(1)); - call.invoke(function() {}, - function() {done();}, - 0); - // Cancel to speed up the test - call.cancel(); + var batch = {}; + batch[grpc.opType.SEND_INITIAL_METADATA] = undefined; + call.startBatch(batch, function(){}); }); - }); - it('should reject incorrectly typed arguments', function() { - var call = new grpc.Call(channel, 'method', getDeadline(1)); assert.throws(function() { - call.invoke(0, 0, 0); + var batch = {}; + batch[grpc.opType.SEND_INITIAL_METADATA] = null; + call.startBatch(batch, function(){}); }, TypeError); assert.throws(function() { - call.invoke(function() {}, - function() {}, 'test'); - }); - }); - }); - describe('serverAccept', function() { - it('should fail with fewer than 1 argument1', function() { - var call = new grpc.Call(channel, 'method', getDeadline(1)); - assert.throws(function() { - call.serverAccept(); + var batch = {}; + batch[grpc.opType.SEND_INITIAL_METADATA] = 'value'; + call.startBatch(batch, function(){}); }, TypeError); - }); - it('should return an error when called on a client Call', function() { - var call = new grpc.Call(channel, 'method', getDeadline(1)); assert.throws(function() { - call.serverAccept(function() {}); - }, function(err) { - return err.code === grpc.callError.NOT_ON_CLIENT; - }); + var batch = {}; + batch[grpc.opType.SEND_INITIAL_METADATA] = 5; + call.startBatch(batch, function(){}); + }, TypeError); }); }); describe('cancel', function() { -- cgit v1.2.3 From 1578c6a4ab91aed70b4c2c271249ec82e2f95d7f Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Wed, 11 Feb 2015 16:19:55 -0800 Subject: Fixed end to end tests --- src/node/ext/call.cc | 8 ++++++-- src/node/ext/call.h | 2 +- src/node/ext/completion_queue_async_worker.cc | 8 ++++---- src/node/test/call_test.js | 2 +- src/node/test/end_to_end_test.js | 2 +- 5 files changed, 13 insertions(+), 9 deletions(-) (limited to 'src/node/test/call_test.js') diff --git a/src/node/ext/call.cc b/src/node/ext/call.cc index 3452af943d..cdc34b52a7 100644 --- a/src/node/ext/call.cc +++ b/src/node/ext/call.cc @@ -98,6 +98,9 @@ bool CreateMetadataArray( string_handles->push_back(unique_ptr(utf8_key)); Handle values = Local::Cast(metadata->Get(current_key)); for (unsigned int j = 0; j < values->Length(); j++) { + if (array->count >= array->capacity) { + gpr_log(GPR_ERROR, "Metadata array grew past capacity"); + } Handle value = values->Get(j); grpc_metadata *current = &array->metadata[array->count]; current->key = **utf8_key; @@ -433,9 +436,9 @@ Handle GetTagNodeValue(void *tag) { return NanEscapeScope(tag_obj); } -NanCallback GetTagCallback(void *tag) { +NanCallback *GetTagCallback(void *tag) { struct tag *tag_struct = reinterpret_cast(tag); - return *tag_struct->callback; + return tag_struct->callback; } void DestroyTag(void *tag) { @@ -598,6 +601,7 @@ NAN_METHOD(Call::StartBatch) { grpc_call_error error = grpc_call_start_batch( call->wrapped_call, ops, nops, new struct tag( callback, op_vector, handles, strings)); + delete ops; if (error != GRPC_CALL_OK) { return NanThrowError("startBatch failed", error); } diff --git a/src/node/ext/call.h b/src/node/ext/call.h index b8792713da..f443a04637 100644 --- a/src/node/ext/call.h +++ b/src/node/ext/call.h @@ -89,7 +89,7 @@ struct tag { v8::Handle GetTagNodeValue(void *tag); -NanCallback GetTagCallback(void *tag); +NanCallback *GetTagCallback(void *tag); void DestroyTag(void *tag); diff --git a/src/node/ext/completion_queue_async_worker.cc b/src/node/ext/completion_queue_async_worker.cc index dbacdf034e..3c32b07ca3 100644 --- a/src/node/ext/completion_queue_async_worker.cc +++ b/src/node/ext/completion_queue_async_worker.cc @@ -80,10 +80,10 @@ void CompletionQueueAsyncWorker::Init(Handle exports) { void CompletionQueueAsyncWorker::HandleOKCallback() { NanScope(); gpr_log(GPR_DEBUG, "Handling response on call %p", result->call); - NanCallback callback = GetTagCallback(result->tag); + NanCallback *callback = GetTagCallback(result->tag); Handle argv[] = {NanNull(), GetTagNodeValue(result->tag)}; - callback.Call(2, argv); + callback->Call(2, argv); DestroyTag(result->tag); grpc_event_finish(result); @@ -92,10 +92,10 @@ void CompletionQueueAsyncWorker::HandleOKCallback() { void CompletionQueueAsyncWorker::HandleErrorCallback() { NanScope(); - NanCallback callback = GetTagCallback(result->tag); + NanCallback *callback = GetTagCallback(result->tag); Handle argv[] = {NanError(ErrorMessage())}; - callback.Call(1, argv); + callback->Call(1, argv); DestroyTag(result->tag); grpc_event_finish(result); diff --git a/src/node/test/call_test.js b/src/node/test/call_test.js index e341092ff8..1cbfc2280c 100644 --- a/src/node/test/call_test.js +++ b/src/node/test/call_test.js @@ -1,6 +1,6 @@ /* * - * Copyright 2014, Google Inc. + * Copyright 2015, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/node/test/end_to_end_test.js b/src/node/test/end_to_end_test.js index d43446084c..34ce2500f6 100644 --- a/src/node/test/end_to_end_test.js +++ b/src/node/test/end_to_end_test.js @@ -67,7 +67,7 @@ describe('end-to-end', function() { after(function() { server.shutdown(); }); - it.skip('should start and end a request without error', function(complete) { + it('should start and end a request without error', function(complete) { var done = multiDone(complete, 2); var deadline = new Date(); deadline.setSeconds(deadline.getSeconds() + 3); -- cgit v1.2.3 From c55ee616b58ce06916661ddaf585711a987a2da2 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Thu, 12 Feb 2015 13:58:24 -0800 Subject: Last test now passes --- src/node/test/call_test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/node/test/call_test.js') diff --git a/src/node/test/call_test.js b/src/node/test/call_test.js index 1cbfc2280c..c1a7e95fa0 100644 --- a/src/node/test/call_test.js +++ b/src/node/test/call_test.js @@ -111,7 +111,7 @@ describe('call', function() { call.startBatch(null, function(){}); }); }); - it.skip('should succeed with an empty object', function(done) { + it('should succeed with an empty object', function(done) { var call = new grpc.Call(channel, 'method', getDeadline(1)); assert.doesNotThrow(function() { call.startBatch({}, function(err) { -- cgit v1.2.3