Merge github.com:google/grpc into async-api

Conflicts:
	test/core/echo/echo_test.c
pull/357/head
Craig Tiller 10 years ago
commit 44c02738ed
  1. 14
      Makefile
  2. 2
      include/grpc/byte_buffer_reader.h
  3. 2
      include/grpc/support/port_platform.h
  4. 2
      include/grpc/support/slice_buffer.h
  5. 2
      src/core/channel/channel_args.c
  6. 3
      src/core/channel/channel_stack.c
  7. 2
      src/core/channel/http_client_filter.c
  8. 2
      src/core/iomgr/tcp_server.h
  9. 6
      src/core/iomgr/tcp_server_posix.c
  10. 2
      src/core/json/json_writer.c
  11. 3
      src/core/security/base64.c
  12. 8
      src/core/security/credentials.c
  13. 6
      src/core/security/json_token.c
  14. 4
      src/core/security/secure_endpoint.c
  15. 3
      src/core/security/server_secure_chttp2.c
  16. 4
      src/core/statistics/census_log.c
  17. 2
      src/core/statistics/census_rpc_stats.c
  18. 2
      src/core/statistics/hash_table.c
  19. 2
      src/core/statistics/window_stats.c
  20. 4
      src/core/support/cpu.h
  21. 5
      src/core/support/cpu_linux.c
  22. 4
      src/core/support/cpu_posix.c
  23. 1
      src/core/support/histogram.c
  24. 4
      src/core/support/slice_buffer.c
  25. 4
      src/core/support/string_posix.c
  26. 1
      src/core/support/thd_posix.c
  27. 2
      src/core/surface/server_chttp2.c
  28. 3
      src/core/tsi/fake_transport_security.c
  29. 7
      src/core/tsi/ssl_transport_security.c
  30. 59
      src/node/ext/call.cc
  31. 61
      src/node/ext/event.cc
  32. 43
      src/node/interop/interop_client.js
  33. 2
      src/node/interop/interop_server.js
  34. 10
      src/node/src/server.js
  35. 43
      src/node/src/surface_server.js
  36. 24
      src/node/test/call_test.js
  37. 28
      src/node/test/client_server_test.js
  38. 59
      src/node/test/end_to_end_test.js
  39. 8
      src/node/test/interop_sanity_test.js
  40. 4
      src/node/test/server_test.js
  41. 2
      src/node/test/surface_test.js
  42. 7
      src/php/ext/grpc/byte_buffer.c
  43. 16
      src/ruby/Rakefile
  44. 42
      src/ruby/spec/completion_queue_spec.rb
  45. 8
      src/ruby/spec/generic/rpc_server_spec.rb
  46. 11
      templates/Makefile.template
  47. 2
      test/core/channel/channel_stack_test.c
  48. 4
      test/core/channel/metadata_buffer_test.c
  49. 2
      test/core/compression/message_compress_test.c
  50. 2
      test/core/echo/client.c
  51. 31
      test/core/echo/echo_test.c
  52. 2
      test/core/echo/server.c
  53. 2
      test/core/end2end/tests/cancel_after_accept.c
  54. 2
      test/core/end2end/tests/cancel_after_accept_and_writes_closed.c
  55. 2
      test/core/end2end/tests/cancel_after_invoke.c
  56. 2
      test/core/end2end/tests/cancel_in_a_vacuum.c
  57. 2
      test/core/fling/client.c
  58. 6
      test/core/iomgr/resolve_address_test.c
  59. 7
      test/core/iomgr/sockaddr_utils_test.c
  60. 10
      test/core/iomgr/tcp_posix_test.c
  61. 2
      test/core/json/json_rewrite.c
  62. 4
      test/core/json/json_rewrite_test.c
  63. 2
      test/core/json/json_test.c
  64. 7
      test/core/security/secure_endpoint_test.c
  65. 6
      test/core/statistics/census_log_tests.c
  66. 2
      test/core/statistics/hash_table_test.c
  67. 3
      test/core/support/host_port_test.c
  68. 6
      test/core/support/slice_test.c
  69. 2
      test/core/surface/completion_queue_test.c
  70. 2
      test/core/transport/chttp2/timeout_encoding_test.c
  71. 2
      test/core/transport/stream_op_test.c
  72. 2
      test/core/transport/transport_end2end_tests.c
  73. 2
      tools/dockerfile/grpc_cxx/Dockerfile
  74. 10
      tools/dockerfile/grpc_java/Dockerfile
  75. 43
      tools/dockerfile/grpc_java_base/Dockerfile
  76. 10
      tools/dockerfile/grpc_ruby/Dockerfile
  77. 1
      tools/dockerfile/grpc_ruby_base/Dockerfile
  78. 127
      tools/gce_setup/grpc_docker.sh
  79. 1
      tools/gce_setup/new_grpc_docker_builder.sh
  80. 31
      tools/gce_setup/shared_startup_funcs.sh
  81. 13
      vsprojects/vs2013/ssl.props
  82. 12
      vsprojects/vs2013/winsock.props

@ -122,7 +122,7 @@ LDFLAGS += $(LDFLAGS_$(CONFIG))
CFLAGS += -std=c89 -pedantic
CXXFLAGS += -std=c++11
CPPFLAGS += -g -fPIC -Wall -Werror -Wno-long-long
CPPFLAGS += -g -fPIC -Wall -Wextra -Werror -Wno-long-long -Wno-unused-parameter
LDFLAGS += -g -fPIC
INCLUDES = . include gens
@ -1006,28 +1006,36 @@ strip-shared: strip-shared_c strip-shared_cxx
# This prevents proper debugging after running make install.
strip-static_c: static_c
ifeq ($(CONFIG),opt)
$(E) "[STRIP] Stripping libgpr.a"
$(Q) $(STRIP) libs/$(CONFIG)/libgpr.a
$(E) "[STRIP] Stripping libgrpc.a"
$(Q) $(STRIP) libs/$(CONFIG)/libgrpc.a
$(E) "[STRIP] Stripping libgrpc_unsecure.a"
$(Q) $(STRIP) libs/$(CONFIG)/libgrpc_unsecure.a
endif
strip-static_cxx: static_cxx
ifeq ($(CONFIG),opt)
$(E) "[STRIP] Stripping libgrpc++.a"
$(Q) $(STRIP) libs/$(CONFIG)/libgrpc++.a
endif
strip-shared_c: shared_c
ifeq ($(CONFIG),opt)
$(E) "[STRIP] Stripping libgpr.so"
$(Q) $(STRIP) libs/$(CONFIG)/libgpr.$(SHARED_EXT)
$(E) "[STRIP] Stripping libgrpc.so"
$(Q) $(STRIP) libs/$(CONFIG)/libgrpc.$(SHARED_EXT)
$(E) "[STRIP] Stripping libgrpc_unsecure.so"
$(Q) $(STRIP) libs/$(CONFIG)/libgrpc_unsecure.$(SHARED_EXT)
endif
strip-shared_cxx: shared_cxx
ifeq ($(CONFIG),opt)
$(E) "[STRIP] Stripping libgrpc++.so"
$(Q) $(STRIP) libs/$(CONFIG)/libgrpc++.$(SHARED_EXT)
endif
gens/examples/tips/empty.pb.cc: examples/tips/empty.proto $(PROTOC_PLUGINS)
$(E) "[PROTOC] Generating protobuf CC file from $<"
@ -1276,6 +1284,7 @@ ifeq ($(SYSTEM),Darwin)
$(Q) $(LD) $(LDFLAGS) -Llibs/$(CONFIG) -dynamiclib -o libs/$(CONFIG)/libgpr.$(SHARED_EXT) $(LIBGPR_OBJS) $(LDLIBS)
else
$(Q) $(LD) $(LDFLAGS) -Llibs/$(CONFIG) -shared -Wl,-soname,libgpr.so.0 -o libs/$(CONFIG)/libgpr.$(SHARED_EXT) $(LIBGPR_OBJS) $(LDLIBS)
$(Q) ln -sf libgpr.$(SHARED_EXT) libs/$(CONFIG)/libgpr.so.0
$(Q) ln -sf libgpr.$(SHARED_EXT) libs/$(CONFIG)/libgpr.so
endif
endif
@ -1617,6 +1626,7 @@ ifeq ($(SYSTEM),Darwin)
$(Q) $(LD) $(LDFLAGS) -Llibs/$(CONFIG) -dynamiclib -o libs/$(CONFIG)/libgrpc.$(SHARED_EXT) $(LIBGRPC_OBJS) $(LDLIBS) $(LDLIBS_SECURE) $(OPENSSL_MERGE_LIBS) -lgpr
else
$(Q) $(LD) $(LDFLAGS) -Llibs/$(CONFIG) -shared -Wl,-soname,libgrpc.so.0 -o libs/$(CONFIG)/libgrpc.$(SHARED_EXT) $(LIBGRPC_OBJS) $(LDLIBS) $(LDLIBS_SECURE) $(OPENSSL_MERGE_LIBS) -lgpr
$(Q) ln -sf libgrpc.$(SHARED_EXT) libs/$(CONFIG)/libgrpc.so.0
$(Q) ln -sf libgrpc.$(SHARED_EXT) libs/$(CONFIG)/libgrpc.so
endif
endif
@ -1931,6 +1941,7 @@ ifeq ($(SYSTEM),Darwin)
$(Q) $(LD) $(LDFLAGS) -Llibs/$(CONFIG) -dynamiclib -o libs/$(CONFIG)/libgrpc_unsecure.$(SHARED_EXT) $(LIBGRPC_UNSECURE_OBJS) $(LDLIBS) -lgpr
else
$(Q) $(LD) $(LDFLAGS) -Llibs/$(CONFIG) -shared -Wl,-soname,libgrpc_unsecure.so.0 -o libs/$(CONFIG)/libgrpc_unsecure.$(SHARED_EXT) $(LIBGRPC_UNSECURE_OBJS) $(LDLIBS) -lgpr
$(Q) ln -sf libgrpc_unsecure.$(SHARED_EXT) libs/$(CONFIG)/libgrpc_unsecure.so.0
$(Q) ln -sf libgrpc_unsecure.$(SHARED_EXT) libs/$(CONFIG)/libgrpc_unsecure.so
endif
endif
@ -2136,6 +2147,7 @@ ifeq ($(SYSTEM),Darwin)
$(Q) $(LDXX) $(LDFLAGS) -Llibs/$(CONFIG) -dynamiclib -o libs/$(CONFIG)/libgrpc++.$(SHARED_EXT) $(LIBGRPC++_OBJS) $(LDLIBS) $(LDLIBS_SECURE) $(OPENSSL_MERGE_LIBS) -lgrpc
else
$(Q) $(LDXX) $(LDFLAGS) -Llibs/$(CONFIG) -shared -Wl,-soname,libgrpc++.so.0 -o libs/$(CONFIG)/libgrpc++.$(SHARED_EXT) $(LIBGRPC++_OBJS) $(LDLIBS) $(LDLIBS_SECURE) $(OPENSSL_MERGE_LIBS) -lgrpc
$(Q) ln -sf libgrpc++.$(SHARED_EXT) libs/$(CONFIG)/libgrpc++.so.0
$(Q) ln -sf libgrpc++.$(SHARED_EXT) libs/$(CONFIG)/libgrpc++.so
endif
endif

@ -42,7 +42,7 @@ struct grpc_byte_buffer_reader {
/* Different current objects correspond to different types of byte buffers */
union {
/* Index into a slice buffer's array of slices */
int index;
unsigned index;
} current;
};

@ -155,7 +155,7 @@ typedef uintmax_t gpr_uintmax;
typedef uintptr_t gpr_uintptr;
/* INT64_MAX is unavailable on some platforms. */
#define GPR_INT64_MAX (~(gpr_uint64)0 >> 1)
#define GPR_INT64_MAX (gpr_int64)(~(gpr_uint64)0 >> 1)
/* maximum alignment needed for any type on this platform, rounded up to a
power of two */

@ -73,7 +73,7 @@ size_t gpr_slice_buffer_add_indexed(gpr_slice_buffer *sb, gpr_slice slice);
void gpr_slice_buffer_addn(gpr_slice_buffer *sb, gpr_slice *slices, size_t n);
/* add a very small (less than 8 bytes) amount of data to the end of a slice
buffer: returns a pointer into which to add the data */
gpr_uint8 *gpr_slice_buffer_tiny_add(gpr_slice_buffer *sb, int len);
gpr_uint8 *gpr_slice_buffer_tiny_add(gpr_slice_buffer *sb, unsigned len);
/* clear a slice buffer, unref all elements */
void gpr_slice_buffer_reset_and_unref(gpr_slice_buffer *sb);

@ -105,7 +105,7 @@ void grpc_channel_args_destroy(grpc_channel_args *a) {
}
int grpc_channel_args_is_census_enabled(const grpc_channel_args *a) {
int i;
unsigned i;
if (a == NULL) return 0;
for (i = 0; i < a->num_args; i++) {
if (0 == strcmp(a->args[i].key, GRPC_ARG_ENABLE_CENSUS)) {

@ -125,7 +125,8 @@ void grpc_channel_stack_init(const grpc_channel_filter **filters,
call_size += ROUND_UP_TO_ALIGNMENT_SIZE(filters[i]->sizeof_call_data);
}
GPR_ASSERT(user_data - (char *)stack ==
GPR_ASSERT(user_data > (char *)stack);
GPR_ASSERT((gpr_uintptr)(user_data - (char *)stack) ==
grpc_channel_stack_size(filters, filter_count));
stack->call_stack_size = call_size;

@ -134,7 +134,7 @@ static void destroy_call_elem(grpc_call_element *elem) {
}
static const char *scheme_from_args(const grpc_channel_args *args) {
int i;
unsigned i;
if (args != NULL) {
for (i = 0; i < args->num_args; ++i) {
if (args->args[i].type == GRPC_ARG_STRING &&

@ -68,7 +68,7 @@ int grpc_tcp_server_add_port(grpc_tcp_server *s, const void *addr,
The file descriptor remains owned by the server, and will be cleaned
up when grpc_tcp_server_destroy is called. */
int grpc_tcp_server_get_fd(grpc_tcp_server *s, int index);
int grpc_tcp_server_get_fd(grpc_tcp_server *s, unsigned index);
void grpc_tcp_server_destroy(grpc_tcp_server *server);

@ -272,7 +272,7 @@ int grpc_tcp_server_add_port(grpc_tcp_server *s, const void *addr,
int addr_len) {
int allocated_port1 = -1;
int allocated_port2 = -1;
int i;
unsigned i;
int fd;
grpc_dualstack_mode dsmode;
struct sockaddr_in6 addr6_v4mapped;
@ -345,8 +345,8 @@ done:
return allocated_port1 >= 0 ? allocated_port1 : allocated_port2;
}
int grpc_tcp_server_get_fd(grpc_tcp_server *s, int index) {
return (0 <= index && index < s->nports) ? s->ports[index].fd : -1;
int grpc_tcp_server_get_fd(grpc_tcp_server *s, unsigned index) {
return (index < s->nports) ? s->ports[index].fd : -1;
}
void grpc_tcp_server_start(grpc_tcp_server *s, grpc_pollset *pollset,

@ -66,7 +66,7 @@ static void json_writer_output_indent(
" "
" ";
int spaces = writer->depth * writer->indent;
unsigned spaces = writer->depth * writer->indent;
if (writer->indent == 0) return;

@ -113,7 +113,8 @@ char *grpc_base64_encode(const void *vdata, size_t data_size, int url_safe,
*current++ = GRPC_BASE64_PAD_CHAR;
}
GPR_ASSERT((current - result) < result_projected_size);
GPR_ASSERT(current >= result);
GPR_ASSERT((gpr_uintptr)(current - result) < result_projected_size);
result[current - result] = '\0';
return result;
}

@ -173,7 +173,9 @@ static void ssl_server_destroy(grpc_server_credentials *creds) {
gpr_free(creds);
}
static int ssl_has_request_metadata(const grpc_credentials *creds) { return 0; }
static int ssl_has_request_metadata(const grpc_credentials *creds) {
return 0;
}
static int ssl_has_request_metadata_only(const grpc_credentials *creds) {
return 0;
@ -903,7 +905,9 @@ static void iam_destroy(grpc_credentials *creds) {
gpr_free(c);
}
static int iam_has_request_metadata(const grpc_credentials *creds) { return 1; }
static int iam_has_request_metadata(const grpc_credentials *creds) {
return 1;
}
static int iam_has_request_metadata_only(const grpc_credentials *creds) {
return 1;

@ -127,7 +127,8 @@ grpc_auth_json_key grpc_auth_json_key_create_from_string(
goto end;
}
bio = BIO_new(BIO_s_mem());
if (BIO_puts(bio, prop_value) != strlen(prop_value)) {
success = BIO_puts(bio, prop_value);
if ((success < 0) || ((size_t)success != strlen(prop_value))) {
gpr_log(GPR_ERROR, "Could not write into openssl BIO.");
goto end;
}
@ -240,7 +241,8 @@ static char *dot_concat_and_free_strings(char *str1, char *str2) {
*(current++) = '.';
memcpy(current, str2, str2_len);
current += str2_len;
GPR_ASSERT((current - result) == result_len);
GPR_ASSERT(current >= result);
GPR_ASSERT((gpr_uintptr)(current - result) == result_len);
*current = '\0';
gpr_free(str1);
gpr_free(str2);

@ -111,7 +111,7 @@ static void call_read_cb(secure_endpoint *ep, gpr_slice *slices, size_t nslices,
static void on_read(void *user_data, gpr_slice *slices, size_t nslices,
grpc_endpoint_cb_status error) {
int i = 0;
unsigned i;
gpr_uint8 keep_looping = 0;
int input_buffer_count = 0;
tsi_result result = TSI_OK;
@ -221,7 +221,7 @@ static grpc_endpoint_write_status endpoint_write(grpc_endpoint *secure_ep,
size_t nslices,
grpc_endpoint_write_cb cb,
void *user_data) {
int i = 0;
unsigned i;
int output_buffer_count = 0;
tsi_result result = TSI_OK;
secure_endpoint *ep = (secure_endpoint *)secure_ep;

@ -92,7 +92,7 @@ int grpc_server_add_secure_http2_port(grpc_server *server, const char *addr) {
grpc_resolved_addresses *resolved = NULL;
grpc_tcp_server *tcp = NULL;
size_t i;
int count = 0;
unsigned count = 0;
int port_num = -1;
int port_temp;
@ -127,6 +127,7 @@ int grpc_server_add_secure_http2_port(grpc_server *server, const char *addr) {
if (count != resolved->naddrs) {
gpr_log(GPR_ERROR, "Only %d addresses added out of total %d resolved",
count, resolved->naddrs);
/* if it's an error, don't we want to goto error; here ? */
}
grpc_resolved_addresses_destroy(resolved);

@ -173,7 +173,7 @@ typedef struct census_log_core_local_block {
struct census_log {
int discard_old_records;
/* Number of cores (aka hardware-contexts) */
int num_cores;
unsigned num_cores;
/* number of CENSUS_LOG_2_MAX_RECORD_SIZE blocks in log */
gpr_int32 num_blocks;
cl_block* blocks; /* Block metadata. */
@ -183,7 +183,7 @@ struct census_log {
/* Keeps the state of the reader iterator. A value of 0 indicates that
iterator has reached the end. census_log_init_reader() resets the
value to num_core to restart iteration. */
gpr_int32 read_iterator_state;
gpr_uint32 read_iterator_state;
/* Points to the block being read. If non-NULL, the block is locked for
reading (block_being_read_->reader_lock is held). */
cl_block* block_being_read;

@ -184,7 +184,7 @@ static void get_stats(census_ht* store, census_aggregated_rpc_stats* data) {
gpr_mu_lock(&g_mu);
if (store != NULL) {
size_t n;
int i, j;
unsigned i, j;
gpr_timespec now = gpr_now();
census_ht_kv* kv = census_ht_get_all_elements(store, &n);
if (kv != NULL) {

@ -292,7 +292,7 @@ static void ht_delete_entry_chain(const census_ht_option* options,
}
void census_ht_destroy(census_ht* ht) {
int i;
unsigned i;
for (i = 0; i < ht->num_buckets; ++i) {
ht_delete_entry_chain(&ht->options, ht->buckets[i].next);
}

@ -150,7 +150,7 @@ window_stats* census_window_stats_create(int nintervals,
is->width = size_ns / granularity;
/* Check for possible overflow issues, and maximize interval size if the
user requested something large enough. */
if (GPR_INT64_MAX - is->width > size_ns) {
if ((GPR_INT64_MAX - is->width) > size_ns) {
is->top = size_ns + is->width;
} else {
is->top = GPR_INT64_MAX;

@ -38,12 +38,12 @@
/* Return the number of CPU cores on the current system. Will return 0 if
if information is not available. */
int gpr_cpu_num_cores(void);
unsigned gpr_cpu_num_cores(void);
/* Return the CPU on which the current thread is executing; N.B. This should
be considered advisory only - it is possible that the thread is switched
to a different CPU at any time. Returns a value in range
[0, gpr_cpu_num_cores() - 1] */
int gpr_cpu_current_cpu(void);
unsigned gpr_cpu_current_cpu(void);
#endif /* __GRPC_INTERNAL_SUPPORT_CPU_H__ */

@ -75,8 +75,9 @@
#include <grpc/support/log.h>
int gpr_cpu_num_cores(void) {
unsigned gpr_cpu_num_cores(void) {
static int ncpus = 0;
/* FIXME: !threadsafe */
if (ncpus == 0) {
ncpus = sysconf(_SC_NPROCESSORS_ONLN);
if (ncpus < 1) {
@ -87,7 +88,7 @@ int gpr_cpu_num_cores(void) {
return ncpus;
}
int gpr_cpu_current_cpu(void) {
unsigned gpr_cpu_current_cpu(void) {
int cpu = sched_getcpu();
if (cpu < 0) {
gpr_log(GPR_ERROR, "Error determining current CPU: %s\n", strerror(errno));

@ -45,7 +45,7 @@
static __thread char magic_thread_local;
int gpr_cpu_num_cores(void) {
unsigned gpr_cpu_num_cores(void) {
static int ncpus = 0;
if (ncpus == 0) {
ncpus = sysconf(_SC_NPROCESSORS_ONLN);
@ -63,7 +63,7 @@ static size_t shard_ptr(const void *info) {
return ((x >> 4) ^ (x >> 9) ^ (x >> 14)) % gpr_cpu_num_cores();
}
int gpr_cpu_current_cpu(void) {
unsigned gpr_cpu_current_cpu(void) {
/* NOTE: there's no way I know to return the actual cpu index portably...
most code that's using this is using it to shard across work queues though,
so here we use thread identity instead to achieve a similar though not

@ -77,7 +77,6 @@ static size_t bucket_for_unchecked(gpr_histogram *h, double x) {
/* bounds checked version of the above */
static size_t bucket_for(gpr_histogram *h, double x) {
size_t bucket = bucket_for_unchecked(h, GPR_CLAMP(x, 0, h->max_possible));
GPR_ASSERT(bucket >= 0);
GPR_ASSERT(bucket < h->num_buckets);
return bucket;
}

@ -55,7 +55,7 @@ void gpr_slice_buffer_destroy(gpr_slice_buffer *sb) {
gpr_free(sb->slices);
}
gpr_uint8 *gpr_slice_buffer_tiny_add(gpr_slice_buffer *sb, int n) {
gpr_uint8 *gpr_slice_buffer_tiny_add(gpr_slice_buffer *sb, unsigned n) {
gpr_slice *back;
gpr_uint8 *out;
@ -64,7 +64,7 @@ gpr_uint8 *gpr_slice_buffer_tiny_add(gpr_slice_buffer *sb, int n) {
if (sb->count == 0) goto add_new;
back = &sb->slices[sb->count - 1];
if (back->refcount) goto add_new;
if (back->data.inlined.length + n > sizeof(back->data.inlined.bytes))
if ((back->data.inlined.length + n) > sizeof(back->data.inlined.bytes))
goto add_new;
out = back->data.inlined.bytes + back->data.inlined.length;
back->data.inlined.length += n;

@ -57,7 +57,7 @@ int gpr_asprintf(char **strp, const char *format, ...) {
va_start(args, format);
ret = vsnprintf(buf, sizeof(buf), format, args);
va_end(args);
if (!(0 <= ret && ret < ~(size_t)0)) {
if (!(0 <= ret)) {
*strp = NULL;
return -1;
}
@ -79,7 +79,7 @@ int gpr_asprintf(char **strp, const char *format, ...) {
va_start(args, format);
ret = vsnprintf(*strp, strp_buflen, format, args);
va_end(args);
if (ret == strp_buflen - 1) {
if ((size_t)ret == strp_buflen - 1) {
return ret;
}

@ -43,6 +43,7 @@
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/thd.h>
#include <grpc/support/useful.h>
struct thd_arg {
void (*body)(void *arg); /* body of a thread */

@ -75,7 +75,7 @@ int grpc_server_add_http2_port(grpc_server *server, const char *addr) {
grpc_resolved_addresses *resolved = NULL;
grpc_tcp_server *tcp = NULL;
size_t i;
int count = 0;
unsigned count = 0;
int port_num = -1;
int port_temp;

@ -38,6 +38,7 @@
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
#include <grpc/support/useful.h>
#include "src/core/tsi/transport_security.h"
/* --- Constants. ---*/
@ -412,7 +413,7 @@ static tsi_result fake_handshaker_process_bytes_from_peer(
tsi_handshaker* self, const unsigned char* bytes, size_t* bytes_size) {
tsi_result result = TSI_OK;
tsi_fake_handshaker* impl = (tsi_fake_handshaker*)self;
int expected_msg = impl->next_message_to_send - 1;
tsi_fake_handshake_message expected_msg = impl->next_message_to_send - 1;
tsi_fake_handshake_message received_msg;
if (!impl->needs_incoming_message || impl->result == TSI_OK) {

@ -37,6 +37,7 @@
#include <grpc/support/log.h>
#include <grpc/support/sync.h>
#include <grpc/support/useful.h>
#include "src/core/tsi/transport_security.h"
#include <openssl/bio.h>
@ -565,7 +566,8 @@ static tsi_result build_alpn_protocol_name_list(
current += alpn_protocols_lengths[i];
}
/* Safety check. */
if ((current - *protocol_name_list) != *protocol_name_list_length) {
if ((current < *protocol_name_list) ||
((gpr_uintptr)(current - *protocol_name_list) != *protocol_name_list_length)) {
return TSI_INTERNAL_ERROR;
}
return TSI_OK;
@ -1063,7 +1065,8 @@ static int server_handshaker_factory_alpn_callback(
while ((client_current - in) < inlen) {
unsigned char client_current_len = *(client_current++);
const unsigned char* server_current = factory->alpn_protocol_list;
while ((server_current - factory->alpn_protocol_list) <
while ((server_current >= factory->alpn_protocol_list) &&
(gpr_uintptr)(server_current - factory->alpn_protocol_list) <
factory->alpn_protocol_list_length) {
unsigned char server_current_len = *(server_current++);
if ((client_current_len == server_current_len) &&

@ -33,6 +33,7 @@
#include <node.h>
#include "grpc/support/log.h"
#include "grpc/grpc.h"
#include "grpc/support/time.h"
#include "byte_buffer.h"
@ -173,31 +174,43 @@ NAN_METHOD(Call::AddMetadata) {
return NanThrowTypeError("addMetadata can only be called on Call objects");
}
Call *call = ObjectWrap::Unwrap<Call>(args.This());
for (int i = 0; !args[i]->IsUndefined(); i++) {
if (!args[i]->IsObject()) {
if (!args[0]->IsObject()) {
return NanThrowTypeError("addMetadata's first argument must be an object");
}
Handle<Object> metadata = args[0]->ToObject();
Handle<Array> keys(metadata->GetOwnPropertyNames());
for (unsigned int i = 0; i < keys->Length(); i++) {
Handle<String> current_key(keys->Get(i)->ToString());
if (!metadata->Get(current_key)->IsArray()) {
return NanThrowTypeError(
"addMetadata arguments must be objects with key and value");
"addMetadata's first argument's values must be arrays");
}
Handle<Object> item = args[i]->ToObject();
Handle<Value> key = item->Get(NanNew("key"));
if (!key->IsString()) {
return NanThrowTypeError(
"objects passed to addMetadata must have key->string");
}
Handle<Value> value = item->Get(NanNew("value"));
if (!Buffer::HasInstance(value)) {
return NanThrowTypeError(
"objects passed to addMetadata must have value->Buffer");
}
grpc_metadata metadata;
NanUtf8String utf8_key(key);
metadata.key = *utf8_key;
metadata.value = Buffer::Data(value);
metadata.value_length = Buffer::Length(value);
grpc_call_error error =
grpc_call_add_metadata(call->wrapped_call, &metadata, 0);
if (error != GRPC_CALL_OK) {
return NanThrowError("addMetadata failed", error);
NanUtf8String utf8_key(current_key);
Handle<Array> values = Local<Array>::Cast(metadata->Get(current_key));
for (unsigned int j = 0; j < values->Length(); j++) {
Handle<Value> value = values->Get(j);
grpc_metadata metadata;
grpc_call_error error;
metadata.key = *utf8_key;
if (Buffer::HasInstance(value)) {
metadata.value = Buffer::Data(value);
metadata.value_length = Buffer::Length(value);
error = grpc_call_add_metadata(call->wrapped_call, &metadata, 0);
} else if (value->IsString()) {
Handle<String> string_value = value->ToString();
NanUtf8String utf8_value(string_value);
metadata.value = *utf8_value;
metadata.value_length = string_value->Length();
gpr_log(GPR_DEBUG, "adding metadata: %s, %s, %d", metadata.key,
metadata.value, metadata.value_length);
error = grpc_call_add_metadata(call->wrapped_call, &metadata, 0);
} else {
return NanThrowTypeError(
"addMetadata values must be strings or buffers");
}
if (error != GRPC_CALL_OK) {
return NanThrowError("addMetadata failed", error);
}
}
}
NanReturnUndefined();

@ -31,6 +31,8 @@
*
*/
#include <map>
#include <node.h>
#include <nan.h>
#include "grpc/grpc.h"
@ -43,6 +45,7 @@
namespace grpc {
namespace node {
using ::node::Buffer;
using v8::Array;
using v8::Date;
using v8::Handle;
@ -53,6 +56,36 @@ using v8::Persistent;
using v8::String;
using v8::Value;
Handle<Value> ParseMetadata(grpc_metadata *metadata_elements, size_t length) {
NanEscapableScope();
std::map<char*, size_t> size_map;
std::map<char*, size_t> index_map;
for (unsigned int i = 0; i < length; i++) {
char *key = metadata_elements[i].key;
if (size_map.count(key)) {
size_map[key] += 1;
}
index_map[key] = 0;
}
Handle<Object> metadata_object = NanNew<Object>();
for (unsigned int i = 0; i < length; i++) {
grpc_metadata* elem = &metadata_elements[i];
Handle<String> key_string = String::New(elem->key);
Handle<Array> array;
if (metadata_object->Has(key_string)) {
array = Handle<Array>::Cast(metadata_object->Get(key_string));
} else {
array = NanNew<Array>(size_map[elem->key]);
metadata_object->Set(key_string, array);
}
array->Set(index_map[elem->key],
NanNewBufferHandle(elem->value, elem->value_length));
index_map[elem->key] += 1;
}
return NanEscapeScope(metadata_object);
}
Handle<Value> GetEventData(grpc_event *event) {
NanEscapableScope();
size_t count;
@ -72,18 +105,7 @@ Handle<Value> GetEventData(grpc_event *event) {
case GRPC_CLIENT_METADATA_READ:
count = event->data.client_metadata_read.count;
items = event->data.client_metadata_read.elements;
metadata = NanNew<Array>(static_cast<int>(count));
for (unsigned int i = 0; i < count; i++) {
Handle<Object> item_obj = NanNew<Object>();
item_obj->Set(NanNew<String, const char *>("key"),
NanNew<String, char *>(items[i].key));
item_obj->Set(
NanNew<String, const char *>("value"),
NanNew<String, char *>(items[i].value,
static_cast<int>(items[i].value_length)));
metadata->Set(i, item_obj);
}
return NanEscapeScope(metadata);
return NanEscapeScope(ParseMetadata(items, count));
case GRPC_FINISHED:
status = NanNew<Object>();
status->Set(NanNew("code"), NanNew<Number>(event->data.finished.status));
@ -93,18 +115,7 @@ Handle<Value> GetEventData(grpc_event *event) {
}
count = event->data.finished.metadata_count;
items = event->data.finished.metadata_elements;
metadata = NanNew<Array>(static_cast<int>(count));
for (unsigned int i = 0; i < count; i++) {
Handle<Object> item_obj = NanNew<Object>();
item_obj->Set(NanNew<String, const char *>("key"),
NanNew<String, char *>(items[i].key));
item_obj->Set(
NanNew<String, const char *>("value"),
NanNew<String, char *>(items[i].value,
static_cast<int>(items[i].value_length)));
metadata->Set(i, item_obj);
}
status->Set(NanNew("metadata"), metadata);
status->Set(NanNew("metadata"), ParseMetadata(items, count));
return NanEscapeScope(status);
case GRPC_SERVER_RPC_NEW:
rpc_new = NanNew<Object>();
@ -133,7 +144,7 @@ Handle<Value> GetEventData(grpc_event *event) {
static_cast<int>(items[i].value_length)));
metadata->Set(i, item_obj);
}
rpc_new->Set(NanNew<String, const char *>("metadata"), metadata);
rpc_new->Set(NanNew("metadata"), ParseMetadata(items, count));
return NanEscapeScope(rpc_new);
default:
return NanEscapeScope(NanNull());

@ -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
};
/**

@ -183,7 +183,7 @@ function getServer(port, tls) {
fullDuplexCall: handleFullDuplex,
halfDuplexCall: handleHalfDuplex
}
}, options);
}, null, options);
var port_num = server.bind('0.0.0.0:' + port, tls);
return {server: server, port: port_num};
}

@ -202,10 +202,13 @@ GrpcServerStream.prototype._write = function(chunk, encoding, callback) {
* Constructs a server object that stores request handlers and delegates
* incoming requests to those handlers
* @constructor
* @param {Array} options Options that should be passed to the internal server
* @param {function(string, Object<string, Array<Buffer>>):
Object<string, Array<Buffer|string>>=} getMetadata Callback that gets
* metatada for a given method
* @param {Object=} options Options that should be passed to the internal server
* implementation
*/
function Server(options) {
function Server(getMetadata, options) {
this.handlers = {};
var handlers = this.handlers;
var server = new grpc.Server(options);
@ -249,6 +252,9 @@ function Server(options) {
stream.emit('cancelled');
}
}, 0);
if (getMetadata) {
call.addMetadata(getMetadata(data.method, data.metadata));
}
call.serverEndInitialMetadata(0);
var stream = new GrpcServerStream(call, handler.serialize,
handler.deserialize);

@ -129,16 +129,18 @@ ServerWritableObjectStream.prototype._write = _write;
/**
* Creates a binary stream handler function from a unary handler function
* @param {function(Object, function(Error, *))} handler Unary call handler
* @return {function(stream)} Binary stream handler
* @param {function(Object, function(Error, *), metadata=)} handler Unary call
* handler
* @return {function(stream, metadata=)} Binary stream handler
*/
function makeUnaryHandler(handler) {
/**
* Handles a stream by reading a single data value, passing it to the handler,
* and writing the response back to the stream.
* @param {stream} stream Binary data stream
* @param {metadata=} metadata Incoming metadata array
*/
return function handleUnaryCall(stream) {
return function handleUnaryCall(stream, metadata) {
stream.on('data', function handleUnaryData(value) {
var call = {request: value};
Object.defineProperty(call, 'cancelled', {
@ -154,7 +156,7 @@ function makeUnaryHandler(handler) {
stream.write(value);
stream.end();
}
});
}, metadata);
});
};
}
@ -162,17 +164,18 @@ function makeUnaryHandler(handler) {
/**
* Creates a binary stream handler function from a client stream handler
* function
* @param {function(Readable, function(Error, *))} handler Client stream call
* handler
* @return {function(stream)} Binary stream handler
* @param {function(Readable, function(Error, *), metadata=)} handler Client
* stream call handler
* @return {function(stream, metadata=)} Binary stream handler
*/
function makeClientStreamHandler(handler) {
/**
* Handles a stream by passing a deserializing stream to the handler and
* writing the response back to the stream.
* @param {stream} stream Binary data stream
* @param {metadata=} metadata Incoming metadata array
*/
return function handleClientStreamCall(stream) {
return function handleClientStreamCall(stream, metadata) {
var object_stream = new ServerReadableObjectStream(stream);
handler(object_stream, function sendClientStreamData(err, value) {
if (err) {
@ -181,35 +184,36 @@ function makeClientStreamHandler(handler) {
stream.write(value);
stream.end();
}
});
}, metadata);
};
}
/**
* Creates a binary stream handler function from a server stream handler
* function
* @param {function(Writable)} handler Server stream call handler
* @return {function(stream)} Binary stream handler
* @param {function(Writable, metadata=)} handler Server stream call handler
* @return {function(stream, metadata=)} Binary stream handler
*/
function makeServerStreamHandler(handler) {
/**
* Handles a stream by attaching it to a serializing stream, and passing it to
* the handler.
* @param {stream} stream Binary data stream
* @param {metadata=} metadata Incoming metadata array
*/
return function handleServerStreamCall(stream) {
return function handleServerStreamCall(stream, metadata) {
stream.on('data', function handleClientData(value) {
var object_stream = new ServerWritableObjectStream(stream);
object_stream.request = value;
handler(object_stream);
handler(object_stream, metadata);
});
};
}
/**
* Creates a binary stream handler function from a bidi stream handler function
* @param {function(Duplex)} handler Unary call handler
* @return {function(stream)} Binary stream handler
* @param {function(Duplex, metadata=)} handler Unary call handler
* @return {function(stream, metadata=)} Binary stream handler
*/
function makeBidiStreamHandler(handler) {
return handler;
@ -252,10 +256,13 @@ function makeServerConstructor(services) {
* @constructor
* @param {Object} service_handlers Map from service names to map from method
* names to handlers
* @param {Object} options Options to pass to the underlying server
* @param {function(string, Object<string, Array<Buffer>>):
Object<string, Array<Buffer|string>>=} getMetadata Callback that
* gets metatada for a given method
* @param {Object=} options Options to pass to the underlying server
*/
function SurfaceServer(service_handlers, options) {
var server = new Server(options);
function SurfaceServer(service_handlers, getMetadata, options) {
var server = new Server(getMetadata, options);
this.inner_server = server;
_.each(services, function(service) {
var service_name = common.fullyQualifiedName(service);

@ -99,24 +99,30 @@ describe('call', function() {
});
});
describe('addMetadata', function() {
it('should succeed with objects containing keys and values', function() {
it('should succeed with a map from strings to string arrays', function() {
var call = new grpc.Call(channel, 'method', getDeadline(1));
assert.doesNotThrow(function() {
call.addMetadata();
call.addMetadata({'key': ['value']});
});
assert.doesNotThrow(function() {
call.addMetadata({'key1': ['value1'], 'key2': ['value2']});
});
});
it('should succeed with a map from strings to buffer arrays', function() {
var call = new grpc.Call(channel, 'method', getDeadline(1));
assert.doesNotThrow(function() {
call.addMetadata({'key' : 'key',
'value' : new Buffer('value')});
call.addMetadata({'key': [new Buffer('value')]});
});
assert.doesNotThrow(function() {
call.addMetadata({'key' : 'key1',
'value' : new Buffer('value1')},
{'key' : 'key2',
'value' : new Buffer('value2')});
call.addMetadata({'key1': [new Buffer('value1')],
'key2': [new Buffer('value2')]});
});
});
it('should fail with other parameter types', function() {
var call = new grpc.Call(channel, 'method', getDeadline(1));
assert.throws(function() {
call.addMetadata();
});
assert.throws(function() {
call.addMetadata(null);
}, TypeError);
@ -133,7 +139,7 @@ describe('call', function() {
function() {done();},
0);
assert.throws(function() {
call.addMetadata({'key' : 'key', 'value' : new Buffer('value') });
call.addMetadata({'key': ['value']});
}, function(err) {
return err.code === grpc.callError.ALREADY_INVOKED;
});

@ -84,6 +84,10 @@ function cancelHandler(stream) {
// do nothing
}
function metadataHandler(stream, metadata) {
stream.end();
}
/**
* Serialize a string to a Buffer
* @param {string} value The string to serialize
@ -106,11 +110,14 @@ describe('echo client', function() {
var server;
var channel;
before(function() {
server = new Server();
server = new Server(function getMetadata(method, metadata) {
return {method: [method]};
});
var port_num = server.bind('0.0.0.0:0');
server.register('echo', echoHandler);
server.register('error', errorHandler);
server.register('cancellation', cancelHandler);
server.register('metadata', metadataHandler);
server.start();
channel = new grpc.Channel('localhost:' + port_num);
@ -142,12 +149,19 @@ describe('echo client', function() {
done();
});
});
it('should recieve metadata set by the server', function(done) {
var stream = client.makeRequest(channel, 'metadata');
stream.on('metadata', function(metadata) {
assert.strictEqual(metadata.method[0].toString(), 'metadata');
});
stream.on('status', function(status) {
assert.equal(status.code, client.status.OK);
done();
});
stream.end();
});
it('should get an error status that the server throws', function(done) {
var stream = client.makeRequest(
channel,
'error',
null,
getDeadline(1));
var stream = client.makeRequest(channel, 'error');
stream.on('data', function() {});
stream.write(new Buffer('test'));
@ -189,7 +203,7 @@ describe('secure echo client', function() {
key_data,
pem_data);
server = new Server({'credentials' : server_creds});
server = new Server(null, {'credentials' : server_creds});
var port_num = server.bind('0.0.0.0:0', true);
server.register('echo', echoHandler);
server.start();

@ -68,18 +68,61 @@ describe('end-to-end', function() {
server.shutdown();
});
it('should start and end a request without error', function(complete) {
var done = multiDone(function() {
complete();
}, 2);
var done = multiDone(complete, 2);
var deadline = new Date();
deadline.setSeconds(deadline.getSeconds() + 3);
var status_text = 'xyz';
var call = new grpc.Call(channel,
'dummy_method',
deadline);
call.invoke(function(event) {
call.invoke(function(event) {
assert.strictEqual(event.type,
grpc.completionType.CLIENT_METADATA_READ);
},function(event) {
assert.strictEqual(event.type, grpc.completionType.FINISHED);
var status = event.data;
assert.strictEqual(status.code, grpc.status.OK);
assert.strictEqual(status.details, status_text);
done();
}, 0);
server.requestCall(function(event) {
assert.strictEqual(event.type, grpc.completionType.SERVER_RPC_NEW);
var server_call = event.call;
assert.notEqual(server_call, null);
server_call.serverAccept(function(event) {
assert.strictEqual(event.type, grpc.completionType.FINISHED);
}, 0);
server_call.serverEndInitialMetadata(0);
server_call.startWriteStatus(
grpc.status.OK,
status_text,
function(event) {
assert.strictEqual(event.type,
grpc.completionType.FINISH_ACCEPTED);
assert.strictEqual(event.data, grpc.opError.OK);
done();
});
});
call.writesDone(function(event) {
assert.strictEqual(event.type,
grpc.completionType.FINISH_ACCEPTED);
assert.strictEqual(event.data, grpc.opError.OK);
});
});
it('should successfully send and receive metadata', function(complete) {
var done = multiDone(complete, 2);
var deadline = new Date();
deadline.setSeconds(deadline.getSeconds() + 3);
var status_text = 'xyz';
var call = new grpc.Call(channel,
'dummy_method',
deadline);
call.addMetadata({'client_key': ['client_value']});
call.invoke(function(event) {
assert.strictEqual(event.type,
grpc.completionType.CLIENT_METADATA_READ);
assert.strictEqual(event.data.server_key[0].toString(), 'server_value');
},function(event) {
assert.strictEqual(event.type, grpc.completionType.FINISHED);
var status = event.data;
@ -90,11 +133,14 @@ describe('end-to-end', function() {
server.requestCall(function(event) {
assert.strictEqual(event.type, grpc.completionType.SERVER_RPC_NEW);
assert.strictEqual(event.data.metadata.client_key[0].toString(),
'client_value');
var server_call = event.call;
assert.notEqual(server_call, null);
server_call.serverAccept(function(event) {
assert.strictEqual(event.type, grpc.completionType.FINISHED);
}, 0);
server_call.addMetadata({'server_key': ['server_value']});
server_call.serverEndInitialMetadata(0);
server_call.startWriteStatus(
grpc.status.OK,
@ -115,10 +161,7 @@ describe('end-to-end', function() {
it('should send and receive data without error', function(complete) {
var req_text = 'client_request';
var reply_text = 'server_response';
var done = multiDone(function() {
complete();
server.shutdown();
}, 6);
var done = multiDone(complete, 6);
var deadline = new Date();
deadline.setSeconds(deadline.getSeconds() + 3);
var status_text = 'success';

@ -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);
});
});

@ -75,6 +75,9 @@ describe('echo server', function() {
channel = new grpc.Channel('localhost:' + port_num);
});
after(function() {
server.shutdown();
});
it('should echo inputs as responses', function(done) {
done = multiDone(done, 4);
@ -95,7 +98,6 @@ describe('echo server', function() {
var status = event.data;
assert.strictEqual(status.code, grpc.status.OK);
assert.strictEqual(status.details, status_text);
server.shutdown();
done();
}, 0);
call.startWrite(

@ -75,7 +75,7 @@ describe('Surface server constructor', function() {
}, /math.Math/);
});
});
describe('Surface client', function() {
describe('Cancelling surface client', function() {
var client;
var server;
before(function() {

@ -16,9 +16,10 @@
#include "grpc/support/slice.h"
grpc_byte_buffer *string_to_byte_buffer(char *string, size_t length) {
gpr_slice slice = gpr_slice_malloc(length);
memcpy(GPR_SLICE_START_PTR(slice), string, length);
return grpc_byte_buffer_create(&slice, 1);
gpr_slice slice = gpr_slice_from_copied_buffer(string, length);
grpc_byte_buffer *buffer = grpc_byte_buffer_create(&slice, 1);
gpr_slice_unref(slice);
return buffer;
}
void byte_buffer_to_string(grpc_byte_buffer *buffer, char **out_string,

@ -13,9 +13,11 @@ end
SPEC_SUITES = [
{ id: :wrapper, title: 'wrapper layer', files: %w(spec/*.rb) },
{ id: :idiomatic, title: 'idiomatic layer', dir: %w(spec/generic),
tag: '~bidi' },
tags: ['~bidi', '~server'] },
{ id: :bidi, title: 'bidi tests', dir: %w(spec/generic),
tag: 'bidi' }
tag: 'bidi' },
{ id: :server, title: 'rpc server thread tests', dir: %w(spec/generic),
tag: 'server' }
]
desc 'Run all RSpec tests'
@ -33,12 +35,18 @@ namespace :spec do
t.pattern = spec_files
t.rspec_opts = "--tag #{suite[:tag]}" if suite[:tag]
t.rspec_opts = suite[:tags].map{ |t| "--tag #{t}" }.join(' ') if suite[:tags]
end
end
end
end
task default: 'spec:suite:idiomatic' # this should be spec:suite:bidi
desc 'Run compiles the extension, runs all the tests'
task :all
task default: :all
task 'spec:suite:wrapper' => :compile
task 'spec:suite:idiomatic' => 'spec:suite:wrapper'
task 'spec:suite:bidi' => 'spec:suite:idiomatic'
task 'spec:suite:bidi' => 'spec:suite:wrapper'
task 'spec:suite:server' => 'spec:suite:wrapper'
task :all => ['spec:suite:idiomatic', 'spec:suite:bidi', 'spec:suite:server']

@ -30,6 +30,10 @@
require 'grpc'
describe GRPC::Core::CompletionQueue do
before(:example) do
@cq = GRPC::Core::CompletionQueue.new
end
describe '#new' do
it 'is constructed successufully' do
expect { GRPC::Core::CompletionQueue.new }.not_to raise_error
@ -38,39 +42,33 @@ describe GRPC::Core::CompletionQueue do
describe '#next' do
it 'can be called without failing' do
ch = GRPC::Core::CompletionQueue.new
expect { ch.next(3) }.not_to raise_error
expect { @cq.next(3) }.not_to raise_error
end
it 'can be called with the time constants' do
ch = GRPC::Core::CompletionQueue.new
# don't use INFINITE_FUTURE, as there we have no events.
non_blocking_consts = [:ZERO, :INFINITE_PAST]
m = GRPC::Core::TimeConsts
non_blocking_consts.each do |c|
a_time = m.const_get(c)
expect { ch.next(a_time) }.not_to raise_error
end
it 'can be called with a time constant' do
# don't use INFINITE_FUTURE, as are no events and this blocks.
#
# don't use INFINITE_PAST, as this fails on docker, and does not need to
# be tested, as its not used anywhere in the ruby implementation
a_time = GRPC::Core::TimeConsts::ZERO
expect { @cq.next(a_time) }.not_to raise_error
end
end
describe '#pluck' do
it 'can be called without failing' do
ch = GRPC::Core::CompletionQueue.new
tag = Object.new
expect { ch.pluck(tag, 3) }.not_to raise_error
expect { @cq.pluck(tag, 3) }.not_to raise_error
end
it 'can be called with the time constants' do
ch = GRPC::Core::CompletionQueue.new
# don't use INFINITE_FUTURE, as there we have no events.
non_blocking_consts = [:ZERO, :INFINITE_PAST]
m = GRPC::Core::TimeConsts
it 'can be called with a time constant' do
# don't use INFINITE_FUTURE, as there no events and this blocks.
#
# don't use INFINITE_PAST, as this fails on docker, and does not need to
# be tested, as its not used anywhere in the ruby implementation
tag = Object.new
non_blocking_consts.each do |c|
a_time = m.const_get(c)
expect { ch.pluck(tag, a_time) }.not_to raise_error
end
a_time = GRPC::Core::TimeConsts::ZERO
expect { @cq.pluck(tag, a_time) }.not_to raise_error
end
end
end

@ -323,7 +323,7 @@ describe GRPC::RpcServer do
end
describe 'when running' do
it 'should return NOT_FOUND status for requests on unknown methods' do
it 'should return NOT_FOUND status on unknown methods', server: true do
@srv.handle(EchoService)
t = Thread.new { @srv.run }
@srv.wait_till_running
@ -338,7 +338,7 @@ describe GRPC::RpcServer do
t.join
end
it 'should obtain responses for multiple sequential requests' do
it 'should handle multiple sequential requests', server: true do
@srv.handle(EchoService)
t = Thread.new { @srv.run }
@srv.wait_till_running
@ -350,7 +350,7 @@ describe GRPC::RpcServer do
t.join
end
it 'should obtain responses for multiple parallel requests' do
it 'should handle multiple parallel requests', server: true do
@srv.handle(EchoService)
Thread.new { @srv.run }
@srv.wait_till_running
@ -368,7 +368,7 @@ describe GRPC::RpcServer do
threads.each(&:join)
end
it 'should return UNAVAILABLE status if there too many jobs' do
it 'should return UNAVAILABLE on too many jobs', server: true do
opts = {
a_channel_arg: 'an_arg',
server_override: @server,

@ -139,7 +139,7 @@ LDFLAGS += $(LDFLAGS_$(CONFIG))
CFLAGS += -std=c89 -pedantic
CXXFLAGS += -std=c++11
CPPFLAGS += -g -fPIC -Wall -Werror -Wno-long-long
CPPFLAGS += -g -fPIC -Wall -Wextra -Werror -Wno-long-long -Wno-unused-parameter
LDFLAGS += -g -fPIC
INCLUDES = . include gens
@ -481,6 +481,7 @@ strip-shared: strip-shared_c strip-shared_cxx
# This prevents proper debugging after running make install.
strip-static_c: static_c
ifeq ($(CONFIG),opt)
% for lib in libs:
% if lib.language == "c":
% if lib.build == "all":
@ -489,8 +490,10 @@ strip-static_c: static_c
% endif
% endif
% endfor
endif
strip-static_cxx: static_cxx
ifeq ($(CONFIG),opt)
% for lib in libs:
% if lib.language == "c++":
% if lib.build == "all":
@ -499,8 +502,10 @@ strip-static_cxx: static_cxx
% endif
% endif
% endfor
endif
strip-shared_c: shared_c
ifeq ($(CONFIG),opt)
% for lib in libs:
% if lib.language == "c":
% if lib.build == "all":
@ -509,8 +514,10 @@ strip-shared_c: shared_c
% endif
% endif
% endfor
endif
strip-shared_cxx: shared_cxx
ifeq ($(CONFIG),opt)
% for lib in libs:
% if lib.language == "c++":
% if lib.build == "all":
@ -519,6 +526,7 @@ strip-shared_cxx: shared_cxx
% endif
% endif
% endfor
endif
% for p in protos:
gens/${p}.pb.cc: ${p}.proto $(PROTOC_PLUGINS)
@ -765,6 +773,7 @@ ifeq ($(SYSTEM),Darwin)
$(Q) ${ld} $(LDFLAGS) -Llibs/$(CONFIG) -dynamiclib -o ${out_libbase}.$(SHARED_EXT) ${common}${libs}
else
$(Q) ${ld} $(LDFLAGS) -Llibs/$(CONFIG) -shared -Wl,-soname,lib${lib.name}.so.${settings.version.major} -o ${out_libbase}.$(SHARED_EXT) ${common}${libs}
$(Q) ln -sf lib${lib.name}.$(SHARED_EXT) ${out_libbase}.so.${settings.version.major}
$(Q) ln -sf lib${lib.name}.$(SHARED_EXT) ${out_libbase}.so
endif
endif

@ -80,7 +80,7 @@ static void test_create_channel_stack(void) {
const grpc_channel_filter
filter = {call_func, channel_func, sizeof(int),
call_init_func, call_destroy_func, sizeof(int),
channel_init_func, channel_destroy_func, };
channel_init_func, channel_destroy_func, "some_test_filter" };
const grpc_channel_filter *filters = &filter;
grpc_channel_stack *channel_stack;
grpc_call_stack *call_stack;

@ -112,12 +112,12 @@ static void destroy_channel_elem(grpc_channel_element *elem) {}
static const grpc_channel_filter top_filter = {
fail_call_op, fail_channel_op, sizeof(size_t),
init_call_elem, destroy_call_elem, sizeof(channel_data),
init_channel_elem, destroy_channel_elem};
init_channel_elem, destroy_channel_elem, "top_filter" };
static const grpc_channel_filter bottom_filter = {
expect_call_op, fail_channel_op, sizeof(size_t),
init_call_elem, destroy_call_elem, sizeof(channel_data),
init_channel_elem, destroy_channel_elem};
init_channel_elem, destroy_channel_elem, "bottom_filter" };
static const grpc_channel_filter *filters[2] = {&top_filter, &bottom_filter};

@ -166,7 +166,7 @@ static void test_bad_data(void) {
}
int main(int argc, char **argv) {
int i, j, k, m;
unsigned i, j, k, m;
grpc_slice_split_mode uncompressed_split_modes[] = {
GRPC_SLICE_SPLIT_IDENTITY, GRPC_SLICE_SPLIT_ONE_BYTE};
grpc_slice_split_mode compressed_split_modes[] = {GRPC_SLICE_SPLIT_MERGE_ALL,

@ -66,7 +66,7 @@ int main(int argc, char **argv) {
grpc_completion_queue *cq = NULL;
int bytes_written = 0;
int bytes_read = 0;
int i = 0;
unsigned i = 0;
int waiting_finishes;
gpr_slice read_slice;

@ -49,18 +49,19 @@
#include "test/core/util/port.h"
int test_client(const char *root, const char *host, int port) {
char *args[3];
int status;
pid_t cli;
cli = fork();
if (cli == 0) {
gpr_asprintf(&args[0], "%s/echo_client", root);
gpr_join_host_port(&args[1], host, port);
args[2] = 0;
execv(args[0], args);
char *binary_path;
char *binding;
gpr_asprintf(&binary_path, "%s/echo_client", root);
gpr_join_host_port(&binding, host, port);
gpr_free(args[0]);
gpr_free(args[1]);
execl(binary_path, binary_path, binding, NULL);
gpr_free(binary_path);
gpr_free(binding);
return 1;
}
/* wait for client */
@ -76,7 +77,6 @@ int main(int argc, char **argv) {
char *lslash = strrchr(me, '/');
char root[1024];
int port = grpc_pick_unused_port_or_die();
char *args[3];
int status;
pid_t svr;
int ret;
@ -98,14 +98,15 @@ int main(int argc, char **argv) {
/* start the server */
svr = fork();
if (svr == 0) {
gpr_asprintf(&args[0], "%s/echo_server", root);
args[1] = "-bind";
gpr_join_host_port(&args[2], "::", port);
args[3] = 0;
execv(args[0], args);
char *binary_path;
char *binding;
gpr_asprintf(&binary_path, "%s/echo_server", root);
gpr_join_host_port(&binding, "::", port);
execl(binary_path, binary_path, "-bind", binding, NULL);
gpr_free(args[0]);
gpr_free(args[2]);
gpr_free(binary_path);
gpr_free(binding);
return 1;
}
/* wait a little */

@ -70,7 +70,7 @@ static void request_call(void) {
static void assert_read_ok(call_state *s, grpc_byte_buffer *b) {
grpc_byte_buffer_reader *bb_reader = NULL;
gpr_slice read_slice;
int i;
unsigned i;
bb_reader = grpc_byte_buffer_reader_create(b);
while (grpc_byte_buffer_reader_next(bb_reader, &read_slice)) {

@ -150,7 +150,7 @@ static void test_cancel_after_accept(grpc_end2end_test_config config,
}
void grpc_end2end_tests(grpc_end2end_test_config config) {
int i;
unsigned i;
for (i = 0; i < GPR_ARRAY_SIZE(cancellation_modes); i++) {
test_cancel_after_accept(config, cancellation_modes[i]);

@ -158,7 +158,7 @@ static void test_cancel_after_accept_and_writes_closed(
}
void grpc_end2end_tests(grpc_end2end_test_config config) {
int i;
unsigned i;
for (i = 0; i < GPR_ARRAY_SIZE(cancellation_modes); i++) {
test_cancel_after_accept_and_writes_closed(config, cancellation_modes[i]);

@ -133,7 +133,7 @@ static void test_cancel_after_invoke(grpc_end2end_test_config config,
}
void grpc_end2end_tests(grpc_end2end_test_config config) {
int i;
unsigned i;
for (i = 0; i < GPR_ARRAY_SIZE(cancellation_modes); i++) {
test_cancel_after_invoke(config, cancellation_modes[i]);

@ -123,7 +123,7 @@ static void test_cancel_in_a_vacuum(grpc_end2end_test_config config,
}
void grpc_end2end_tests(grpc_end2end_test_config config) {
int i;
unsigned i;
for (i = 0; i < GPR_ARRAY_SIZE(cancellation_modes); i++) {
test_cancel_in_a_vacuum(config, cancellation_modes[i]);

@ -104,7 +104,7 @@ static const scenario scenarios[] = {
int main(int argc, char **argv) {
gpr_slice slice = gpr_slice_from_copied_string("x");
double start, stop;
int i;
unsigned i;
char *fake_argv[1];

@ -85,7 +85,7 @@ static void test_ipv6_with_port(void) {
static void test_ipv6_without_port(void) {
const char* const kCases[] = {"2001:db8::1", "2001:db8::1.2.3.4",
"[2001:db8::1]", };
int i;
unsigned i;
for (i = 0; i < sizeof(kCases) / sizeof(*kCases); i++) {
gpr_event ev;
gpr_event_init(&ev);
@ -96,7 +96,7 @@ static void test_ipv6_without_port(void) {
static void test_invalid_ip_addresses(void) {
const char* const kCases[] = {"293.283.1238.3:1", "[2001:db8::11111]:1", };
int i;
unsigned i;
for (i = 0; i < sizeof(kCases) / sizeof(*kCases); i++) {
gpr_event ev;
gpr_event_init(&ev);
@ -108,7 +108,7 @@ static void test_invalid_ip_addresses(void) {
static void test_unparseable_hostports(void) {
const char* const kCases[] = {"[", "[::1", "[::1]bad",
"[1.2.3.4]", "[localhost]", "[localhost]:1", };
int i;
unsigned i;
for (i = 0; i < sizeof(kCases) / sizeof(*kCases); i++) {
gpr_event ev;
gpr_event_init(&ev);

@ -182,7 +182,8 @@ static void expect_sockaddr_str(const char *expected, void *addr,
gpr_log(GPR_INFO, " expect_sockaddr_str(%s)", expected);
result = grpc_sockaddr_to_string(&str, (struct sockaddr *)addr, normalize);
GPR_ASSERT(str != NULL);
GPR_ASSERT(result == strlen(str));
GPR_ASSERT(result >= 0);
GPR_ASSERT((size_t)result == strlen(str));
GPR_ASSERT(strcmp(expected, str) == 0);
gpr_free(str);
}
@ -194,7 +195,7 @@ static void test_sockaddr_to_string(void) {
gpr_log(GPR_INFO, "%s", __FUNCTION__);
errno = 0xDEADBEEF;
errno = 0x7EADBEEF;
input4 = make_addr4(kIPv4, sizeof(kIPv4));
expect_sockaddr_str("192.0.2.1:12345", &input4, 0);
@ -217,7 +218,7 @@ static void test_sockaddr_to_string(void) {
expect_sockaddr_str("(sockaddr family=123)", &dummy, 0);
expect_sockaddr_str("(sockaddr family=123)", &dummy, 1);
GPR_ASSERT(errno == 0xDEADBEEF);
GPR_ASSERT(errno == 0x7EADBEEF);
}
int main(int argc, char **argv) {

@ -94,7 +94,7 @@ static size_t fill_socket_partial(int fd, size_t bytes) {
ssize_t write_bytes;
size_t total_bytes = 0;
unsigned char *buf = malloc(bytes);
int i;
unsigned i;
for (i = 0; i < bytes; ++i) {
buf[i] = i % 256;
}
@ -115,15 +115,14 @@ struct read_socket_state {
grpc_endpoint *ep;
gpr_mu mu;
gpr_cv cv;
size_t read_bytes;
ssize_t read_bytes;
ssize_t target_read_bytes;
};
static ssize_t count_and_unref_slices(gpr_slice *slices, size_t nslices,
int *current_data) {
ssize_t num_bytes = 0;
int i;
int j;
unsigned i, j;
unsigned char *buf;
for (i = 0; i < nslices; ++i) {
buf = GPR_SLICE_START_PTR(slices[i]);
@ -254,8 +253,7 @@ static gpr_slice *allocate_blocks(ssize_t num_bytes, ssize_t slice_size,
ssize_t nslices = num_bytes / slice_size + (num_bytes % slice_size ? 1 : 0);
gpr_slice *slices = gpr_malloc(sizeof(gpr_slice) * nslices);
ssize_t num_bytes_left = num_bytes;
int i;
int j;
unsigned i, j;
unsigned char *buf;
*num_blocks = nslices;

@ -131,7 +131,7 @@ static void json_reader_string_add_utf32(void* userdata, gpr_uint32 c) {
}
static gpr_uint32 json_reader_read_char(void* userdata) {
gpr_uint32 r;
int r;
json_reader_userdata* state = userdata;
r = fgetc(state->in);

@ -138,7 +138,7 @@ static void json_reader_string_add_utf32(void* userdata, gpr_uint32 c) {
}
static gpr_uint32 json_reader_read_char(void* userdata) {
gpr_uint32 r;
int r;
json_reader_userdata* state = userdata;
if (!state->did_eagain) {
@ -298,7 +298,7 @@ static test_file test_files[] = {
};
void test_rewrites() {
int i;
unsigned i;
for (i = 0; i < GPR_ARRAY_SIZE(test_files); i++) {
test_file* test = test_files + i;

@ -124,7 +124,7 @@ static testing_pair testing_pairs[] = {
};
static void test_pairs() {
int i;
unsigned i;
for (i = 0; i < GPR_ARRAY_SIZE(testing_pairs); i++) {
testing_pair* pair = testing_pairs + i;

@ -59,7 +59,7 @@ static grpc_endpoint_test_fixture secure_endpoint_create_fixture_tcp_socketpair(
f.client_ep =
grpc_secure_endpoint_create(fake_read_protector, tcp.client, NULL, 0);
} else {
int i;
unsigned i;
tsi_result result;
size_t still_pending_size;
size_t total_buffer_size = 8192;
@ -81,9 +81,8 @@ static grpc_endpoint_test_fixture secure_endpoint_create_fixture_tcp_socketpair(
message_bytes += processed_message_size;
message_size -= processed_message_size;
cur += protected_buffer_size_to_send;
GPR_ASSERT(buffer_size >= protected_buffer_size_to_send);
buffer_size -= protected_buffer_size_to_send;
GPR_ASSERT(buffer_size >= 0);
}
gpr_slice_unref(plain);
}
@ -94,8 +93,8 @@ static grpc_endpoint_test_fixture secure_endpoint_create_fixture_tcp_socketpair(
&still_pending_size);
GPR_ASSERT(result == TSI_OK);
cur += protected_buffer_size_to_send;
GPR_ASSERT(buffer_size >= protected_buffer_size_to_send);
buffer_size -= protected_buffer_size_to_send;
GPR_ASSERT(buffer_size >= 0);
} while (still_pending_size > 0);
encrypted_leftover = gpr_slice_from_copied_buffer(
(const char *)encrypted_buffer, total_buffer_size - buffer_size);

@ -415,8 +415,8 @@ void test_read_pending_record(void) {
/* Tries reading beyond pending write. */
void test_read_beyond_pending_record(void) {
/* Start a write. */
gpr_int32 incomplete_record_size = 10;
gpr_int32 complete_record_size = 20;
gpr_uint32 incomplete_record_size = 10;
gpr_uint32 complete_record_size = 20;
size_t bytes_available;
void* complete_record;
const void* record_read;
@ -457,7 +457,7 @@ void test_detached_while_reading(void) {
size_t bytes_available;
const void* record_read;
void* record_written;
gpr_int32 block_read = 0;
gpr_uint32 block_read = 0;
printf("Starting test: detached while reading\n");
setup_test(0);
/* Start a write. */

@ -190,7 +190,7 @@ static void test_insertion_and_deletion_with_high_collision_rate(void) {
census_ht* ht = census_ht_create(&opt);
char key_str[1000][GPR_LTOA_MIN_BUFSIZE];
gpr_uint64 val = 0;
int i = 0;
unsigned i = 0;
for (i = 0; i < 1000; i++) {
census_ht_key key;
key.ptr = key_str[i];

@ -43,7 +43,8 @@ static void join_host_port_expect(const char *host, int port,
char *buf;
int len;
len = gpr_join_host_port(&buf, host, port);
GPR_ASSERT(strlen(expected) == len);
GPR_ASSERT(len >= 0);
GPR_ASSERT(strlen(expected) == (size_t)len);
GPR_ASSERT(strcmp(expected, buf) == 0);
gpr_free(buf);
}

@ -103,10 +103,10 @@ static void test_slice_new_with_len_returns_something_sensible(void) {
GPR_ASSERT(do_nothing_with_len_1_calls == 1);
}
static void test_slice_sub_works(int length) {
static void test_slice_sub_works(unsigned length) {
gpr_slice slice;
gpr_slice sub;
int i, j, k;
unsigned i, j, k;
LOG_TEST_NAME();
gpr_log(GPR_INFO, "length=%d", length);
@ -212,7 +212,7 @@ static void test_slice_from_copied_string_works(void) {
}
int main(int argc, char **argv) {
int length;
unsigned length;
grpc_test_init(argc, argv);
test_slice_malloc_returns_something_sensible();
test_slice_new_returns_something_sensible();

@ -188,7 +188,7 @@ static void test_pluck(void) {
grpc_event *ev;
grpc_completion_queue *cc;
void *tags[128];
int i, j;
unsigned i, j;
int on_finish_called = 0;
LOG_TEST();

@ -94,7 +94,7 @@ void decode_suite(char ext, gpr_timespec (*answer)(long x)) {
long test_vals[] = {1, 12, 123, 1234, 12345, 123456,
1234567, 12345678, 123456789, 98765432, 9876543, 987654,
98765, 9876, 987, 98, 9};
int i;
unsigned i;
char *input;
for (i = 0; i < GPR_ARRAY_SIZE(test_vals); i++) {
gpr_asprintf(&input, "%ld%c", test_vals[i], ext);

@ -61,7 +61,7 @@ int main(int argc, char **argv) {
gpr_slice test_slice_3 = gpr_slice_malloc(3);
gpr_slice test_slice_4 = gpr_slice_malloc(4);
char x;
int i;
unsigned i;
grpc_stream_op_buffer buf;
grpc_stream_op_buffer buf2;

@ -913,7 +913,7 @@ static const size_t interesting_message_lengths[] = {1, 100, 10000,
100000, 1000000, };
void grpc_transport_end2end_tests(grpc_transport_test_config *config) {
int i;
unsigned i;
g_metadata_context = grpc_mdctx_create();

@ -21,4 +21,6 @@ RUN cd /var/local/git/grpc && ls \
&& make interop_client \
&& make interop_server
ADD service_account service_account
CMD ["/var/local/git/grpc/bins/opt/interop_server", "--enable_ssl", "--port=8010"]

@ -1,13 +1,11 @@
# Dockerfile for the gRPC Java dev image
FROM grpc/java_base
RUN cd /var/local/git/grpc-java/lib/okhttp && \
mvn -pl okhttp -am install
RUN cd /var/local/git/grpc-java/lib/netty && \
mvn -pl codec-http2 -am -DskipTests install
RUN git clone --recursive --depth 1 git@github.com:google/grpc-java.git /var/local/git/grpc-java
RUN cd /var/local/git/grpc-java/lib/netty && \
mvn -pl codec-http2 -am -DskipTests install clean
RUN cd /var/local/git/grpc-java && \
protoc --version>ver.txt && \
mvn install
./gradlew build
# Specify the default command such that the interop server runs on its known testing port
CMD ["/var/local/git/grpc-java/run-test-server.sh", "--use_tls=true", "--port=8030"]

@ -9,35 +9,36 @@ RUN echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true
RUN echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" | tee /etc/apt/sources.list.d/webupd8team-java.list
RUN echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" | tee -a /etc/apt/sources.list.d/webupd8team-java.list
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886
RUN apt-get update && apt-get -y install oracle-java8-installer
RUN apt-get update && apt-get -y install oracle-java8-installer && \
apt-get clean && rm -r /var/cache/oracle-jdk8-installer/
# Install maven
RUN wget http://mirror.olnevhost.net/pub/apache/maven/binaries/apache-maven-3.2.1-bin.tar.gz && \
tar xvf apache-maven-3.2.1-bin.tar.gz -C /var/local
RUN wget -O - http://mirror.olnevhost.net/pub/apache/maven/binaries/apache-maven-3.2.1-bin.tar.gz | \
tar xz -C /var/local
ENV JAVA_HOME /usr/lib/jvm/java-8-oracle
ENV M2_HOME /var/local/apache-maven-3.2.1
ENV PATH $PATH:$JAVA_HOME/bin:$M2_HOME/bin
ENV LD_LIBRARY_PATH /usr/local/lib
# Install a GitHub SSH service credential that gives access to the GitHub repo while it's private
# TODO: remove this once the repo is public
ADD .ssh .ssh
RUN chmod 600 .ssh/github.rsa
RUN mkdir -p $HOME/.ssh && echo 'Host github.com' > $HOME/.ssh/config
RUN echo " IdentityFile /.ssh/github.rsa" >> $HOME/.ssh/config
RUN echo 'StrictHostKeyChecking no' >> $HOME/.ssh/config
# Get the protobuf source from GitHub and install it
RUN git clone --recursive --branch v2.6.1 git@github.com:google/protobuf.git /var/local/git/protobuf
RUN cd /var/local/git/protobuf && \
./autogen.sh && \
RUN wget -O - https://github.com/google/protobuf/releases/download/v2.6.1/protobuf-2.6.1.tar.bz2 | \
tar xj && \
cd protobuf-2.6.1 && \
./configure --prefix=/usr && \
make -j12 && make check && make install && make clean
make -j12 && make check && make install && \
rm -r "$(pwd)"
# Install a GitHub SSH service credential that gives access to the GitHub repo while it's private
# TODO: remove this once the repo is public
COPY .ssh/github.rsa /root/.ssh/id_rsa
RUN echo 'Host github.com\nStrictHostKeyChecking no' > /root/.ssh/config
RUN cd /var/local/git/grpc-java/lib/okhttp && \
mvn -pl okhttp -am validate
RUN cd /var/local/git/grpc-java/lib/netty && \
mvn -pl codec-http2 -am validate
RUN cd /var/local/git/grpc-java && \
mvn validate
# Trigger download of as many Maven and Gradle artifacts as possible. We don't build grpc-java
# because we don't want to install netty
RUN git clone --recursive --depth 1 git@github.com:google/grpc-java.git && \
cd grpc-java/lib/netty && \
mvn -pl codec-http2 -am -DskipTests verify && \
cd ../.. && \
./gradlew && \
rm -r "$(pwd)"

@ -12,14 +12,8 @@ RUN touch /var/local/git/grpc/include/grpc/support/string.h
# Build the C core.
RUN make install_c -C /var/local/git/grpc
# Install the grpc gem locally with its dependencies and build the extension
RUN /bin/bash -l -c 'cd /var/local/git/grpc/src/ruby && bundle && rake compile:grpc && gem build grpc.gemspec && gem install grpc'
# TODO add a command to run the unittest tests when the bug below is fixed
# - the tests fail due to an error in the C threading library:
# they fail with 'ruby: __pthread_mutex_cond_lock_adjust for unknown reasons' at the end of a testcase
# - however, the interop server and client run OK, so this bug can be investigated
# RUN /bin/bash -l -c 'cd /var/local/git/grpc/src/ruby && bundle && rake'
# Build ruby gRPC and run its tests
RUN /bin/bash -l -c 'cd /var/local/git/grpc/src/ruby && bundle && rake'
# Add a cacerts directory containing the Google root pem file, allowing the ruby client to access the production test instance
ADD cacerts cacerts

@ -39,7 +39,6 @@ RUN /bin/bash -l -c "curl -L get.rvm.io | bash -s stable"
RUN /bin/bash -l -c "rvm install ruby-2.1"
RUN /bin/bash -l -c "rvm use --default ruby-2.1"
RUN /bin/bash -l -c "echo 'gem: --no-ri --no-rdoc' > ~/.gemrc"
RUN /bin/bash -l -c "echo 'source /home/grpc_ruby/.rvm/scripts/rvm' >> ~/.bashrc"
RUN /bin/bash -l -c "echo 'rvm --default use ruby-2.1' >> ~/.bashrc"
RUN /bin/bash -l -c "gem install bundler --no-ri --no-rdoc"

@ -440,6 +440,55 @@ grpc_cloud_prod_test_args() {
}
}
# checks the positional args and assigns them to variables visible in the caller
#
# these are the positional args passed to grpc_cloud_prod_auth_test after option flags
# are removed
#
# three args are expected, in order
# - test_case
# - host <the gce docker instance on which to run the test>
# - client to run
grpc_cloud_prod_auth_test_args() {
grpc_gen_test_cmd="grpc_cloud_prod_auth_"
[[ -n $1 ]] && { # test_case
test_case=$1
grpc_gen_test_cmd+="$1"
shift
} || {
echo "$FUNCNAME: missing arg: test_case" 1>&2
return 1
}
[[ -n $1 ]] && { # host
host=$1
shift
} || {
echo "$FUNCNAME: missing arg: host" 1>&2
return 1
}
[[ -n $1 ]] && { # client_type
case $1 in
cxx|go|java|nodejs|php|python|ruby)
grpc_gen_test_cmd+="_gen_$1_cmd"
declare -F $grpc_gen_test_cmd >> /dev/null || {
echo "-f: test_func for $1 => $grpc_gen_test_cmd is not defined" 1>&2
return 2
}
shift
;;
*)
echo "bad client_type: $1" 1>&2
return 1
;;
esac
} || {
echo "$FUNCNAME: missing arg: client_type" 1>&2
return 1
}
}
_grpc_sync_scripts_args() {
grpc_gce_script_root='tools/gce_setup'
@ -715,6 +764,52 @@ grpc_cloud_prod_test() {
gcloud compute $project_opt ssh $zone_opt $host --command "$cmd"
}
# Runs a test command on a docker instance.
#
# call-seq:
# grpc_cloud_prod_auth_test <test_name> <host> <client_type>
#
# requirements:
# host is a GCE instance running docker with access to the gRPC docker images
# test_name is one of the named gRPC tests [http://go/grpc_interop_tests]
# client_type is one of [cxx,go,java,php,python,ruby]
#
# it assumes:
# that each grpc-imp has a docker image named grpc/<imp>, e.g, grpc/java
# a test is run using $ docker run 'path/to/interop_test_bin --flags'
# the required images are available on <host>
#
# each client_type should have an associated bash func:
# grpc_cloud_prod_auth_<test_case>_gen_<client_type>_cmd
# the func provides the dockerized commmand for running client_type's test.
# If no such func is available, tests for that client type cannot be run.
grpc_cloud_prod_auth_test() {
_grpc_ensure_gcloud_ssh || return 1;
# declare vars local so that they don't pollute the shell environment
# where they this func is used.
local grpc_zone grpc_project dry_run # set by _grpc_set_project_and_zone
# grpc_cloud_prod_test_args
local test_case host grpc_gen_test_cmd
# set the project zone and check that all necessary args are provided
_grpc_set_project_and_zone -f grpc_cloud_prod_auth_test_args "$@" || return 1
gce_has_instance $grpc_project $host || return 1;
local test_case_flag=" --test_case=$test_case"
cmd=$($grpc_gen_test_cmd $test_case_flag)
[[ -n $cmd ]] || return 1
local project_opt="--project $grpc_project"
local zone_opt="--zone $grpc_zone"
local ssh_cmd="bash -l -c \"$cmd\""
echo "will run:"
echo " $ssh_cmd"
echo "on $host"
[[ $dry_run == 1 ]] && return 0 # don't run the command on a dry run
gcloud compute $project_opt ssh $zone_opt $host --command "$cmd"
}
# constructs the full dockerized ruby interop test cmd.
#
# call-seq:
@ -848,4 +943,34 @@ grpc_cloud_prod_gen_cxx_cmd() {
echo $the_cmd
}
# TODO(grpc-team): add grpc_interop_gen_python_cmd
# constructs the full dockerized cpp interop test cmd.
#
#
# call-seq:
# flags= .... # generic flags to include the command
# cmd=$($grpc_gen_test_cmd $flags)
grpc_cloud_prod_auth_service_account_creds_gen_cxx_cmd() {
local cmd_prefix="sudo docker run grpc/cxx";
local test_script="/var/local/git/grpc/bins/opt/interop_client --enable_ssl";
local gfe_flags=" --use_prod_roots --server_port=443 --server_host=grpc-test.sandbox.google.com --server_host_override=grpc-test.sandbox.google.com"
local added_gfe_flags=" --service_account_key_file=/service_account/stubbyCloudTestingTest-7dd63462c60c.json --oauth_scope=https://www.googleapis.com/auth/xapi.zoo"
local the_cmd="$cmd_prefix $test_script $gfe_flags $added_gfe_flags $@";
echo $the_cmd
}
# constructs the full dockerized cpp interop test cmd.
#
#
# call-seq:
# flags= .... # generic flags to include the command
# cmd=$($grpc_gen_test_cmd $flags)
grpc_cloud_prod_auth_compute_engine_creds_gen_cxx_cmd() {
local cmd_prefix="sudo docker run grpc/cxx";
local test_script="/var/local/git/grpc/bins/opt/interop_client --enable_ssl";
local gfe_flags=" --use_prod_roots --server_port=443 --server_host=grpc-test.sandbox.google.com --server_host_override=grpc-test.sandbox.google.com"
local added_gfe_flags=" --default_service_account=155450119199-r5aaqa2vqoa9g5mv2m6s3m1l293rlmel@developer.gserviceaccount.com --oauth_scope=https://www.googleapis.com/auth/xapi.zoo"
local the_cmd="$cmd_prefix $test_script $gfe_flags $added_gfe_flags $@";
echo $the_cmd
}
# TODO(grpc-team): add grpc_interop_gen_xxx_cmd for python|nodejs

@ -87,6 +87,7 @@ add_instance() {
local the_image='container-vm-v20140925'
local scopes='compute-rw storage-full'
scopes+=' https://www.googleapis.com/auth/gerritcodereview'
scopes+=' https://www.googleapis.com/auth/xapi.zoo'
gcloud --project $project compute instances create $instance \
$address_flag \
--image $the_image \

@ -416,6 +416,9 @@ grpc_dockerfile_install() {
[[ $image_label == "grpc/ruby" ]] && {
grpc_docker_sync_roots_pem $dockerfile_dir/cacerts || return 1;
}
[[ $image_label == "grpc/cxx" ]] && {
grpc_docker_sync_service_account $dockerfile_dir/service_account || return 1;
}
# TODO(temiola): maybe make cache/no-cache a func option?
@ -503,3 +506,31 @@ grpc_docker_sync_roots_pem() {
}
gsutil cp $src $gcs_certs_path $local_certs_path
}
# grpc_docker_sync_service_account.
#
# Copies the service account from GCS to the target dir
#
# call-seq:
# grpc_docker_sync_service_account <target_dir>
grpc_docker_sync_service_account() {
local target_dir=$1
[[ -n $target_dir ]] || { echo "$FUNCNAME: missing arg: target_dir" >&2; return 1; }
# determine the admin root; the parent of the dockerfile root,
local gs_dockerfile_root=$(load_metadata "attributes/gs_dockerfile_root")
[[ -n $gs_dockerfile_root ]] || {
echo "$FUNCNAME: missing metadata: gs_dockerfile_root" >&2
return 1
}
local gcs_admin_root=$(dirname $gs_dockerfile_root)
# cp the file from gsutil to a known local area
local gcs_acct_path=$gcs_admin_root/service_account/stubbyCloudTestingTest-7dd63462c60c.json
local local_acct_path=$target_dir/stubbyCloudTestingTest-7dd63462c60c.json
mkdir -p $target_dir || {
echo "$FUNCNAME: could not create dir: $target_dir" 1>&2
return 1
}
gsutil cp $src $gcs_acct_path $local_acct_path
}

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets" />
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<ItemDefinitionGroup>
<Link>
<AdditionalLibraryDirectories>..\..\third_party\openssl\out32;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>ssleay32.lib;libeay32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup />
</Project>

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets" />
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<ItemDefinitionGroup>
<Link>
<AdditionalDependencies>ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup />
</Project>
Loading…
Cancel
Save