aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core
diff options
context:
space:
mode:
authorGravatar David Klempner <klempner@google.com>2016-05-13 13:24:48 -0700
committerGravatar David Klempner <klempner@google.com>2016-05-13 13:24:48 -0700
commit2ecb08f5a76f97443deae01befdfee679a5c9b6d (patch)
tree456a719ca15d23bb03e1a7df0949a414b4f0803b /test/core
parent2754c91fee5cbe57cee540e08f72e111a80911e0 (diff)
parenteffd74c3cc307c67059e30fa47359f9ca7d6d672 (diff)
Merge branch 'master' into return_unused_port
Diffstat (limited to 'test/core')
-rw-r--r--test/core/channel/channel_args_test.c3
-rw-r--r--test/core/client_config/set_initial_connect_string_test.c44
-rw-r--r--test/core/iomgr/udp_server_test.c12
-rw-r--r--test/core/iomgr/workqueue_test.c13
4 files changed, 51 insertions, 21 deletions
diff --git a/test/core/channel/channel_args_test.c b/test/core/channel/channel_args_test.c
index c7fc25960c..c2fc05095a 100644
--- a/test/core/channel/channel_args_test.c
+++ b/test/core/channel/channel_args_test.c
@@ -77,7 +77,8 @@ static void test_set_compression_algorithm(void) {
ch_args =
grpc_channel_args_set_compression_algorithm(NULL, GRPC_COMPRESS_GZIP);
GPR_ASSERT(ch_args->num_args == 1);
- GPR_ASSERT(strcmp(ch_args->args[0].key, GRPC_COMPRESSION_ALGORITHM_ARG) == 0);
+ GPR_ASSERT(strcmp(ch_args->args[0].key,
+ GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM) == 0);
GPR_ASSERT(ch_args->args[0].type == GRPC_ARG_INTEGER);
grpc_channel_args_destroy(ch_args);
diff --git a/test/core/client_config/set_initial_connect_string_test.c b/test/core/client_config/set_initial_connect_string_test.c
index 83058d9b2c..c1b8452866 100644
--- a/test/core/client_config/set_initial_connect_string_test.c
+++ b/test/core/client_config/set_initial_connect_string_test.c
@@ -37,6 +37,7 @@
#include <grpc/support/host_port.h>
#include <grpc/support/log.h>
#include <grpc/support/slice.h>
+#include <grpc/support/thd.h>
#include "src/core/ext/client_config/initial_connect_string.h"
#include "src/core/lib/iomgr/sockaddr.h"
@@ -56,7 +57,7 @@ struct rpc_state {
gpr_slice_buffer incoming_buffer;
gpr_slice_buffer temp_incoming_buffer;
grpc_endpoint *tcp;
- int done;
+ gpr_atm done_atm;
};
static const char *magic_connect_string = "magic initial string";
@@ -69,7 +70,7 @@ static void handle_read(grpc_exec_ctx *exec_ctx, void *arg, bool success) {
gpr_slice_buffer_move_into(&state.temp_incoming_buffer,
&state.incoming_buffer);
if (state.incoming_buffer.length > strlen(magic_connect_string)) {
- state.done = 1;
+ gpr_atm_rel_store(&state.done_atm, 1);
grpc_endpoint_shutdown(exec_ctx, state.tcp);
grpc_endpoint_destroy(exec_ctx, state.tcp);
} else {
@@ -116,7 +117,7 @@ static gpr_timespec n_sec_deadline(int seconds) {
}
static void start_rpc(int use_creds, int target_port) {
- state.done = 0;
+ gpr_atm_rel_store(&state.done_atm, 0);
state.cq = grpc_completion_queue_create(NULL);
if (use_creds) {
state.creds = grpc_fake_transport_security_credentials_create();
@@ -139,7 +140,7 @@ static void start_rpc(int use_creds, int target_port) {
state.op.reserved = NULL;
GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(state.call, &state.op,
(size_t)(1), NULL, NULL));
- grpc_completion_queue_next(state.cq, n_sec_deadline(1), NULL);
+ grpc_completion_queue_next(state.cq, n_sec_deadline(5), NULL);
}
static void cleanup_rpc(void) {
@@ -157,12 +158,29 @@ static void cleanup_rpc(void) {
gpr_free(state.target);
}
-static void poll_server_until_read_done(test_tcp_server *server) {
- gpr_timespec deadline = n_sec_deadline(5);
- while (state.done == 0 &&
+typedef struct {
+ test_tcp_server *server;
+ gpr_event *signal_when_done;
+} poll_args;
+
+static void actually_poll_server(void *arg) {
+ poll_args *pa = arg;
+ gpr_timespec deadline = n_sec_deadline(10);
+ while (gpr_atm_acq_load(&state.done_atm) == 0 &&
gpr_time_cmp(gpr_now(GPR_CLOCK_REALTIME), deadline) < 0) {
- test_tcp_server_poll(server, 1);
+ test_tcp_server_poll(pa->server, 1);
}
+ gpr_event_set(pa->signal_when_done, (void *)1);
+ gpr_free(pa);
+}
+
+static void poll_server_until_read_done(test_tcp_server *server,
+ gpr_event *signal_when_done) {
+ gpr_thd_id id;
+ poll_args *pa = gpr_malloc(sizeof(*pa));
+ pa->server = server;
+ pa->signal_when_done = signal_when_done;
+ gpr_thd_new(&id, actually_poll_server, pa, NULL);
}
static void match_initial_magic_string(gpr_slice_buffer *buffer) {
@@ -180,20 +198,26 @@ static void match_initial_magic_string(gpr_slice_buffer *buffer) {
}
static void test_initial_string(test_tcp_server *server, int secure) {
+ gpr_event ev;
+ gpr_event_init(&ev);
grpc_test_set_initial_connect_string_function(set_magic_initial_string);
+ poll_server_until_read_done(server, &ev);
start_rpc(secure, server_port);
- poll_server_until_read_done(server);
+ gpr_event_wait(&ev, gpr_inf_future(GPR_CLOCK_REALTIME));
match_initial_magic_string(&state.incoming_buffer);
cleanup_rpc();
}
static void test_initial_string_with_redirect(test_tcp_server *server,
int secure) {
+ gpr_event ev;
+ gpr_event_init(&ev);
int another_port = grpc_pick_unused_port_or_die();
grpc_test_set_initial_connect_string_function(
reset_addr_and_set_magic_string);
+ poll_server_until_read_done(server, &ev);
start_rpc(secure, another_port);
- poll_server_until_read_done(server);
+ gpr_event_wait(&ev, gpr_inf_future(GPR_CLOCK_REALTIME));
match_initial_magic_string(&state.incoming_buffer);
cleanup_rpc();
}
diff --git a/test/core/iomgr/udp_server_test.c b/test/core/iomgr/udp_server_test.c
index a29a68eb33..1e7e4fad63 100644
--- a/test/core/iomgr/udp_server_test.c
+++ b/test/core/iomgr/udp_server_test.c
@@ -32,20 +32,22 @@
*/
#include "src/core/lib/iomgr/udp_server.h"
+
+#include <netinet/in.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <unistd.h>
+
#include <grpc/grpc.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/sync.h>
#include <grpc/support/time.h>
+
#include "src/core/lib/iomgr/ev_posix.h"
#include "src/core/lib/iomgr/iomgr.h"
#include "test/core/util/test_config.h"
-#include <netinet/in.h>
-#include <string.h>
-#include <sys/socket.h>
-#include <unistd.h>
-
#ifdef GRPC_NEED_UDP
#define LOG_TEST(x) gpr_log(GPR_INFO, "%s", #x)
diff --git a/test/core/iomgr/workqueue_test.c b/test/core/iomgr/workqueue_test.c
index 874e696fc2..953cc35ee6 100644
--- a/test/core/iomgr/workqueue_test.c
+++ b/test/core/iomgr/workqueue_test.c
@@ -73,8 +73,10 @@ static void test_add_closure(void) {
gpr_mu_lock(g_mu);
GPR_ASSERT(!done);
- grpc_pollset_work(&exec_ctx, g_pollset, &worker, gpr_now(deadline.clock_type),
- deadline);
+ while (!done) {
+ grpc_pollset_work(&exec_ctx, g_pollset, &worker,
+ gpr_now(deadline.clock_type), deadline);
+ }
gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
GPR_ASSERT(done);
@@ -97,9 +99,10 @@ static void test_flush(void) {
grpc_workqueue_add_to_pollset(&exec_ctx, wq, g_pollset);
gpr_mu_lock(g_mu);
- GPR_ASSERT(!done);
- grpc_pollset_work(&exec_ctx, g_pollset, &worker, gpr_now(deadline.clock_type),
- deadline);
+ while (!done) {
+ grpc_pollset_work(&exec_ctx, g_pollset, &worker,
+ gpr_now(deadline.clock_type), deadline);
+ }
gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
GPR_ASSERT(done);