Fix tcp_client_posix_test
diff --git a/src/core/iomgr/timer.c b/src/core/iomgr/timer.c
index 5e7fadb..8379fff 100644
--- a/src/core/iomgr/timer.c
+++ b/src/core/iomgr/timer.c
@@ -335,8 +335,8 @@
return (int)n;
}
-int grpc_timer_check(grpc_exec_ctx *exec_ctx, gpr_timespec now,
- gpr_timespec *next) {
+bool grpc_timer_check(grpc_exec_ctx *exec_ctx, gpr_timespec now,
+ gpr_timespec *next) {
GPR_ASSERT(now.clock_type == g_clock_type);
return run_some_expired_timers(
exec_ctx, now, next,
diff --git a/src/core/iomgr/timer.h b/src/core/iomgr/timer.h
index 2f74b6e..906255d 100644
--- a/src/core/iomgr/timer.h
+++ b/src/core/iomgr/timer.h
@@ -89,7 +89,7 @@
/* iomgr internal api for dealing with timers */
/* Check for timers to be run, and run them.
- Return non zero if timer callbacks were executed.
+ Return true if timer callbacks were executed.
Drops drop_mu if it is non-null before executing callbacks.
If next is non-null, TRY to update *next with the next running timer
IF that timer occurs before *next current value.
@@ -97,10 +97,10 @@
with high probability at least one thread in the system will see an update
at any time slice. */
-int grpc_timer_check(grpc_exec_ctx* exec_ctx, gpr_timespec now,
- gpr_timespec* next);
+bool grpc_timer_check(grpc_exec_ctx *exec_ctx, gpr_timespec now,
+ gpr_timespec *next);
void grpc_timer_list_init(gpr_timespec now);
-void grpc_timer_list_shutdown(grpc_exec_ctx* exec_ctx);
+void grpc_timer_list_shutdown(grpc_exec_ctx *exec_ctx);
/* the following must be implemented by each iomgr implementation */
diff --git a/src/core/surface/completion_queue.c b/src/core/surface/completion_queue.c
index 6597c83..de295ab 100644
--- a/src/core/surface/completion_queue.c
+++ b/src/core/surface/completion_queue.c
@@ -335,7 +335,8 @@
gpr_mu_lock(GRPC_POLLSET_MU(&cc->pollset));
continue;
}
- grpc_pollset_work(&exec_ctx, &cc->pollset, &worker, now, iteration_deadline);
+ grpc_pollset_work(&exec_ctx, &cc->pollset, &worker, now,
+ iteration_deadline);
}
GRPC_SURFACE_TRACE_RETURNED_EVENT(cc, &ret);
GRPC_CQ_INTERNAL_UNREF(cc, "next");
@@ -451,7 +452,8 @@
gpr_mu_lock(GRPC_POLLSET_MU(&cc->pollset));
continue;
}
- grpc_pollset_work(&exec_ctx, &cc->pollset, &worker, now, iteration_deadline);
+ grpc_pollset_work(&exec_ctx, &cc->pollset, &worker, now,
+ iteration_deadline);
del_plucker(cc, tag, &worker);
}
done:
diff --git a/test/core/iomgr/tcp_client_posix_test.c b/test/core/iomgr/tcp_client_posix_test.c
index 9725d8a..b574780 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 @@
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 @@
/* 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 @@
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]);