aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorGravatar Vijay Pai <vpai@google.com>2016-02-22 16:30:18 -0800
committerGravatar Vijay Pai <vpai@google.com>2016-02-22 16:30:18 -0800
commit349bba9179f27a058470de3c2fd2ac6c9ccb80b5 (patch)
tree0c28db3a3b6948d98ffc96a8217d36e58a2fdf35 /test
parentbfc7adaa714b5d8a3b0dca4a25d572dbd92039be (diff)
parent23a329838588eb3dc7bcfee365007c5194288912 (diff)
Merge pull request #5257 from ctiller/cleaner-posix
Separate timer checking from pollsets
Diffstat (limited to 'test')
-rw-r--r--test/core/iomgr/tcp_client_posix_test.c26
-rw-r--r--test/core/iomgr/timer_list_test.c31
2 files changed, 32 insertions, 25 deletions
diff --git a/test/core/iomgr/tcp_client_posix_test.c b/test/core/iomgr/tcp_client_posix_test.c
index 9725d8a3b6..b57478059f 100644
--- a/test/core/iomgr/tcp_client_posix_test.c
+++ b/test/core/iomgr/tcp_client_posix_test.c
@@ -45,6 +45,7 @@
#include "src/core/iomgr/iomgr.h"
#include "src/core/iomgr/socket_utils_posix.h"
+#include "src/core/iomgr/timer.h"
#include "test/core/util/test_config.h"
static grpc_pollset_set g_pollset_set;
@@ -125,11 +126,13 @@ void test_succeeds(void) {
gpr_now(GPR_CLOCK_MONOTONIC),
GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5));
gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
- grpc_exec_ctx_finish(&exec_ctx);
+ grpc_exec_ctx_flush(&exec_ctx);
gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
}
gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+
+ grpc_exec_ctx_finish(&exec_ctx);
}
void test_fails(void) {
@@ -159,14 +162,18 @@ void test_fails(void) {
/* wait for the connection callback to finish */
while (g_connections_complete == connections_complete_before) {
grpc_pollset_worker worker;
- grpc_pollset_work(&exec_ctx, &g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC), test_deadline());
+ gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC);
+ gpr_timespec polling_deadline = test_deadline();
+ if (!grpc_timer_check(&exec_ctx, now, &polling_deadline)) {
+ grpc_pollset_work(&exec_ctx, &g_pollset, &worker, now, polling_deadline);
+ }
gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
- grpc_exec_ctx_finish(&exec_ctx);
+ grpc_exec_ctx_flush(&exec_ctx);
gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
}
gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ grpc_exec_ctx_finish(&exec_ctx);
}
void test_times_out(void) {
@@ -243,15 +250,18 @@ void test_times_out(void) {
GPR_ASSERT(g_connections_complete ==
connections_complete_before + is_after_deadline);
}
- grpc_pollset_work(&exec_ctx, &g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC),
- GRPC_TIMEOUT_MILLIS_TO_DEADLINE(10));
+ gpr_timespec polling_deadline = GRPC_TIMEOUT_MILLIS_TO_DEADLINE(10);
+ if (!grpc_timer_check(&exec_ctx, now, &polling_deadline)) {
+ grpc_pollset_work(&exec_ctx, &g_pollset, &worker, now, polling_deadline);
+ }
gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
- grpc_exec_ctx_finish(&exec_ctx);
+ grpc_exec_ctx_flush(&exec_ctx);
gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
}
gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ grpc_exec_ctx_finish(&exec_ctx);
+
close(svr_fd);
for (i = 0; i < NUM_CLIENT_CONNECTS; ++i) {
close(client_fd[i]);
diff --git a/test/core/iomgr/timer_list_test.c b/test/core/iomgr/timer_list_test.c
index 15de87c5a1..7a21fdd5c1 100644
--- a/test/core/iomgr/timer_list_test.c
+++ b/test/core/iomgr/timer_list_test.c
@@ -35,7 +35,6 @@
#include <string.h>
-#include "src/core/iomgr/timer_internal.h"
#include <grpc/support/log.h>
#include "test/core/util/test_config.h"
@@ -72,20 +71,19 @@ static void add_test(void) {
}
/* collect timers. Only the first batch should be ready. */
- GPR_ASSERT(10 == grpc_timer_check(&exec_ctx,
- gpr_time_add(start, gpr_time_from_millis(
- 500, GPR_TIMESPAN)),
- NULL));
+ GPR_ASSERT(grpc_timer_check(
+ &exec_ctx, gpr_time_add(start, gpr_time_from_millis(500, GPR_TIMESPAN)),
+ NULL));
grpc_exec_ctx_finish(&exec_ctx);
for (i = 0; i < 20; i++) {
GPR_ASSERT(cb_called[i][1] == (i < 10));
GPR_ASSERT(cb_called[i][0] == 0);
}
- GPR_ASSERT(0 == grpc_timer_check(&exec_ctx,
- gpr_time_add(start, gpr_time_from_millis(
- 600, GPR_TIMESPAN)),
- NULL));
+ GPR_ASSERT(!grpc_timer_check(
+ &exec_ctx,
+ gpr_time_add(start, gpr_time_from_millis(600, GPR_TIMESPAN)),
+ NULL));
grpc_exec_ctx_finish(&exec_ctx);
for (i = 0; i < 30; i++) {
GPR_ASSERT(cb_called[i][1] == (i < 10));
@@ -93,20 +91,19 @@ static void add_test(void) {
}
/* collect the rest of the timers */
- GPR_ASSERT(10 == grpc_timer_check(
- &exec_ctx, gpr_time_add(start, gpr_time_from_millis(
- 1500, GPR_TIMESPAN)),
- NULL));
+ GPR_ASSERT(grpc_timer_check(
+ &exec_ctx, gpr_time_add(start, gpr_time_from_millis(1500, GPR_TIMESPAN)),
+ NULL));
grpc_exec_ctx_finish(&exec_ctx);
for (i = 0; i < 30; i++) {
GPR_ASSERT(cb_called[i][1] == (i < 20));
GPR_ASSERT(cb_called[i][0] == 0);
}
- GPR_ASSERT(0 == grpc_timer_check(&exec_ctx,
- gpr_time_add(start, gpr_time_from_millis(
- 1600, GPR_TIMESPAN)),
- NULL));
+ GPR_ASSERT(!grpc_timer_check(
+ &exec_ctx,
+ gpr_time_add(start, gpr_time_from_millis(1600, GPR_TIMESPAN)),
+ NULL));
for (i = 0; i < 30; i++) {
GPR_ASSERT(cb_called[i][1] == (i < 20));
GPR_ASSERT(cb_called[i][0] == 0);