aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2017-09-21 13:34:08 -0700
committerGravatar Craig Tiller <ctiller@google.com>2017-09-21 13:34:08 -0700
commit965d4159cb9d057023f204b020a8b9802349822a (patch)
tree5892f658ac3422bb37c35db15c8edc253c484c6a /test/core
parentf6343040bfa590881716e9820ab4779e931cd82f (diff)
parent88b8486f79d501c1ab8b72ac3092bd107656d6d6 (diff)
Merge branch 'grpc_millis' into flowctl+millis
Diffstat (limited to 'test/core')
-rw-r--r--test/core/backoff/BUILD36
-rw-r--r--test/core/backoff/backoff_test.c149
-rw-r--r--test/core/channel/channel_stack_test.c2
-rw-r--r--test/core/client_channel/resolvers/dns_resolver_connectivity_test.c2
-rw-r--r--test/core/end2end/fixtures/h2_ssl_cert.c2
-rw-r--r--test/core/end2end/fixtures/http_proxy_fixture.c10
-rw-r--r--test/core/end2end/fuzzers/api_fuzzer.c22
-rw-r--r--test/core/end2end/invalid_call_argument_test.c2
-rw-r--r--test/core/end2end/tests/bad_ping.c17
-rw-r--r--test/core/http/httpcli_test.c11
-rw-r--r--test/core/http/httpscli_test.c11
-rw-r--r--test/core/iomgr/endpoint_tests.c16
-rw-r--r--test/core/iomgr/ev_epollsig_linux_test.c6
-rw-r--r--test/core/iomgr/fd_posix_test.c24
-rw-r--r--test/core/iomgr/pollset_set_test.c24
-rw-r--r--test/core/iomgr/resolve_address_posix_test.c28
-rw-r--r--test/core/iomgr/resolve_address_test.c28
-rw-r--r--test/core/iomgr/tcp_client_posix_test.c21
-rw-r--r--test/core/iomgr/tcp_client_uv_test.c2
-rw-r--r--test/core/iomgr/tcp_posix_test.c31
-rw-r--r--test/core/iomgr/tcp_server_posix_test.c8
-rw-r--r--test/core/iomgr/timer_list_test.c83
-rw-r--r--test/core/iomgr/udp_server_test.c12
-rw-r--r--test/core/security/credentials_test.c33
-rw-r--r--test/core/security/jwt_verifier_test.c14
-rw-r--r--test/core/security/oauth2_utils.c3
-rw-r--r--test/core/security/print_google_default_creds_token.c3
-rw-r--r--test/core/security/ssl_server_fuzzer.c3
-rw-r--r--test/core/security/verify_jwt.c8
-rw-r--r--test/core/support/BUILD10
-rw-r--r--test/core/support/backoff_test.c143
-rw-r--r--test/core/surface/concurrent_connectivity_test.c10
-rw-r--r--test/core/transport/status_conversion_test.c13
-rw-r--r--test/core/transport/timeout_encoding_test.c117
-rw-r--r--test/core/util/port_server_client.c14
-rw-r--r--test/core/util/test_tcp_server.c12
36 files changed, 466 insertions, 464 deletions
diff --git a/test/core/backoff/BUILD b/test/core/backoff/BUILD
new file mode 100644
index 0000000000..4ae762007c
--- /dev/null
+++ b/test/core/backoff/BUILD
@@ -0,0 +1,36 @@
+# Copyright 2016 gRPC authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+load("//bazel:grpc_build_system.bzl", "grpc_cc_library", "grpc_cc_test", "grpc_cc_binary")
+
+licenses(["notice"]) # Apache v2
+
+package(
+ features = [
+ "-layering_check",
+ "-parse_headers",
+ ],
+)
+
+grpc_cc_test(
+ name = "backoff_test",
+ srcs = ["backoff_test.c"],
+ language = "C",
+ deps = [
+ "//:grpc",
+ "//test/core/util:grpc_test_util",
+ "//:gpr",
+ "//test/core/util:gpr_test_util",
+ ],
+)
diff --git a/test/core/backoff/backoff_test.c b/test/core/backoff/backoff_test.c
new file mode 100644
index 0000000000..3848b2a54d
--- /dev/null
+++ b/test/core/backoff/backoff_test.c
@@ -0,0 +1,149 @@
+/*
+ *
+ * Copyright 2016 gRPC authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "src/core/lib/backoff/backoff.h"
+
+#include <grpc/support/log.h>
+
+#include "test/core/util/test_config.h"
+
+static void test_constant_backoff(void) {
+ grpc_backoff backoff;
+ grpc_backoff_init(&backoff, 200 /* initial timeout */, 1.0 /* multiplier */,
+ 0.0 /* jitter */, 100 /* min timeout */,
+ 1000 /* max timeout */);
+
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_millis next = grpc_backoff_begin(&exec_ctx, &backoff);
+ GPR_ASSERT(next - grpc_exec_ctx_now(&exec_ctx) == 200);
+ for (int i = 0; i < 10000; i++) {
+ next = grpc_backoff_step(&exec_ctx, &backoff);
+ GPR_ASSERT(next - grpc_exec_ctx_now(&exec_ctx) == 200);
+ exec_ctx.now = next;
+ }
+ grpc_exec_ctx_finish(&exec_ctx);
+}
+
+static void test_min_connect(void) {
+ grpc_backoff backoff;
+ grpc_backoff_init(&backoff, 100 /* initial timeout */, 1.0 /* multiplier */,
+ 0.0 /* jitter */, 200 /* min timeout */,
+ 1000 /* max timeout */);
+
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_millis next = grpc_backoff_begin(&exec_ctx, &backoff);
+ GPR_ASSERT(next - grpc_exec_ctx_now(&exec_ctx) == 200);
+ grpc_exec_ctx_finish(&exec_ctx);
+}
+
+static void test_no_jitter_backoff(void) {
+ grpc_backoff backoff;
+ grpc_backoff_init(&backoff, 2 /* initial timeout */, 2.0 /* multiplier */,
+ 0.0 /* jitter */, 1 /* min timeout */,
+ 513 /* max timeout */);
+ // x_1 = 2
+ // x_n = 2**i + x_{i-1} ( = 2**(n+1) - 2 )
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ exec_ctx.now = 0;
+ exec_ctx.now_is_valid = true;
+ grpc_millis next = grpc_backoff_begin(&exec_ctx, &backoff);
+ GPR_ASSERT(next == 2);
+ exec_ctx.now = next;
+ next = grpc_backoff_step(&exec_ctx, &backoff);
+ GPR_ASSERT(next == 6);
+ exec_ctx.now = next;
+ next = grpc_backoff_step(&exec_ctx, &backoff);
+ GPR_ASSERT(next == 14);
+ exec_ctx.now = next;
+ next = grpc_backoff_step(&exec_ctx, &backoff);
+ GPR_ASSERT(next == 30);
+ exec_ctx.now = next;
+ next = grpc_backoff_step(&exec_ctx, &backoff);
+ GPR_ASSERT(next == 62);
+ exec_ctx.now = next;
+ next = grpc_backoff_step(&exec_ctx, &backoff);
+ GPR_ASSERT(next == 126);
+ exec_ctx.now = next;
+ next = grpc_backoff_step(&exec_ctx, &backoff);
+ GPR_ASSERT(next == 254);
+ exec_ctx.now = next;
+ next = grpc_backoff_step(&exec_ctx, &backoff);
+ GPR_ASSERT(next == 510);
+ exec_ctx.now = next;
+ next = grpc_backoff_step(&exec_ctx, &backoff);
+ GPR_ASSERT(next == 1022);
+ exec_ctx.now = next;
+ next = grpc_backoff_step(&exec_ctx, &backoff);
+ // Hit the maximum timeout. From this point onwards, retries will increase
+ // only by max timeout.
+ GPR_ASSERT(next == 1535);
+ exec_ctx.now = next;
+ next = grpc_backoff_step(&exec_ctx, &backoff);
+ GPR_ASSERT(next == 2048);
+ exec_ctx.now = next;
+ next = grpc_backoff_step(&exec_ctx, &backoff);
+ GPR_ASSERT(next == 2561);
+ grpc_exec_ctx_finish(&exec_ctx);
+}
+
+static void test_jitter_backoff(void) {
+ const int64_t initial_timeout = 500;
+ const double jitter = 0.1;
+ grpc_backoff backoff;
+ grpc_backoff_init(&backoff, initial_timeout, 1.0 /* multiplier */, jitter,
+ 100 /* min timeout */, 1000 /* max timeout */);
+
+ backoff.rng_state = 0; // force consistent PRNG
+
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_millis next = grpc_backoff_begin(&exec_ctx, &backoff);
+ GPR_ASSERT(next - grpc_exec_ctx_now(&exec_ctx) == 500);
+
+ int64_t expected_next_lower_bound =
+ (int64_t)((double)initial_timeout * (1 - jitter));
+ int64_t expected_next_upper_bound =
+ (int64_t)((double)initial_timeout * (1 + jitter));
+
+ for (int i = 0; i < 10000; i++) {
+ next = grpc_backoff_step(&exec_ctx, &backoff);
+
+ // next-now must be within (jitter*100)% of the previous timeout.
+ const int64_t timeout_millis = next - grpc_exec_ctx_now(&exec_ctx);
+ GPR_ASSERT(timeout_millis >= expected_next_lower_bound);
+ GPR_ASSERT(timeout_millis <= expected_next_upper_bound);
+
+ expected_next_lower_bound =
+ (int64_t)((double)timeout_millis * (1 - jitter));
+ expected_next_upper_bound =
+ (int64_t)((double)timeout_millis * (1 + jitter));
+ exec_ctx.now = next;
+ }
+ grpc_exec_ctx_finish(&exec_ctx);
+}
+
+int main(int argc, char **argv) {
+ grpc_test_init(argc, argv);
+ gpr_time_init();
+
+ test_constant_backoff();
+ test_min_connect();
+ test_no_jitter_backoff();
+ test_jitter_backoff();
+
+ return 0;
+}
diff --git a/test/core/channel/channel_stack_test.c b/test/core/channel/channel_stack_test.c
index 7c3614b4a2..a07ef89ba8 100644
--- a/test/core/channel/channel_stack_test.c
+++ b/test/core/channel/channel_stack_test.c
@@ -125,7 +125,7 @@ static void test_create_channel_stack(void) {
.context = NULL,
.path = path,
.start_time = gpr_now(GPR_CLOCK_MONOTONIC),
- .deadline = gpr_inf_future(GPR_CLOCK_MONOTONIC),
+ .deadline = GRPC_MILLIS_INF_FUTURE,
.arena = NULL};
grpc_error *error = grpc_call_stack_init(&exec_ctx, channel_stack, 1,
free_call, call_stack, &args);
diff --git a/test/core/client_channel/resolvers/dns_resolver_connectivity_test.c b/test/core/client_channel/resolvers/dns_resolver_connectivity_test.c
index 364e180963..4597285063 100644
--- a/test/core/client_channel/resolvers/dns_resolver_connectivity_test.c
+++ b/test/core/client_channel/resolvers/dns_resolver_connectivity_test.c
@@ -106,7 +106,7 @@ static bool wait_loop(int deadline_seconds, gpr_event *ev) {
deadline_seconds--;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- grpc_timer_check(&exec_ctx, gpr_now(GPR_CLOCK_MONOTONIC), NULL);
+ grpc_timer_check(&exec_ctx, NULL);
grpc_exec_ctx_finish(&exec_ctx);
}
return false;
diff --git a/test/core/end2end/fixtures/h2_ssl_cert.c b/test/core/end2end/fixtures/h2_ssl_cert.c
index 9b1ddadfe4..f0a2ee5430 100644
--- a/test/core/end2end/fixtures/h2_ssl_cert.c
+++ b/test/core/end2end/fixtures/h2_ssl_cert.c
@@ -319,7 +319,7 @@ static void simple_request_body(grpc_end2end_test_fixture f,
op = ops;
op->op = GRPC_OP_SEND_INITIAL_METADATA;
op->data.send_initial_metadata.count = 0;
- op->flags = 0;
+ op->flags = GRPC_INITIAL_METADATA_WAIT_FOR_READY;
op->reserved = NULL;
op++;
error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL);
diff --git a/test/core/end2end/fixtures/http_proxy_fixture.c b/test/core/end2end/fixtures/http_proxy_fixture.c
index a4cfc77bcb..d29401fdc3 100644
--- a/test/core/end2end/fixtures/http_proxy_fixture.c
+++ b/test/core/end2end/fixtures/http_proxy_fixture.c
@@ -412,8 +412,8 @@ static void on_read_request_done(grpc_exec_ctx* exec_ctx, void* arg,
GPR_ASSERT(resolved_addresses->naddrs >= 1);
// Connect to requested address.
// The connection callback inherits our reference to conn.
- const gpr_timespec deadline = gpr_time_add(
- gpr_now(GPR_CLOCK_MONOTONIC), gpr_time_from_seconds(10, GPR_TIMESPAN));
+ const grpc_millis deadline =
+ grpc_exec_ctx_now(exec_ctx) + 10 * GPR_MS_PER_SEC;
grpc_tcp_client_connect(exec_ctx, &conn->on_server_connect_done,
&conn->server_endpoint, conn->pollset_set, NULL,
&resolved_addresses->addrs[0], deadline);
@@ -469,14 +469,12 @@ static void thread_main(void* arg) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
do {
gpr_ref(&proxy->users);
- const gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC);
- const gpr_timespec deadline =
- gpr_time_add(now, gpr_time_from_seconds(1, GPR_TIMESPAN));
grpc_pollset_worker* worker = NULL;
gpr_mu_lock(proxy->mu);
GRPC_LOG_IF_ERROR(
"grpc_pollset_work",
- grpc_pollset_work(&exec_ctx, proxy->pollset, &worker, now, deadline));
+ grpc_pollset_work(&exec_ctx, proxy->pollset, &worker,
+ grpc_exec_ctx_now(&exec_ctx) + GPR_MS_PER_SEC));
gpr_mu_unlock(proxy->mu);
grpc_exec_ctx_flush(&exec_ctx);
} while (!gpr_unref(&proxy->users));
diff --git a/test/core/end2end/fuzzers/api_fuzzer.c b/test/core/end2end/fuzzers/api_fuzzer.c
index 1228c9fe9a..0a787bbf30 100644
--- a/test/core/end2end/fuzzers/api_fuzzer.c
+++ b/test/core/end2end/fuzzers/api_fuzzer.c
@@ -60,7 +60,9 @@ extern gpr_timespec (*gpr_now_impl)(gpr_clock_type clock_type);
static gpr_timespec now_impl(gpr_clock_type clock_type) {
GPR_ASSERT(clock_type != GPR_TIMESPAN);
- return g_now;
+ gpr_timespec ts = g_now;
+ ts.clock_type = clock_type;
+ return ts;
}
////////////////////////////////////////////////////////////////////////////////
@@ -407,10 +409,8 @@ void my_resolve_address(grpc_exec_ctx *exec_ctx, const char *addr,
r->addrs = addresses;
r->lb_addrs = NULL;
grpc_timer_init(
- exec_ctx, &r->timer, gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC),
- gpr_time_from_seconds(1, GPR_TIMESPAN)),
- GRPC_CLOSURE_CREATE(finish_resolve, r, grpc_schedule_on_exec_ctx),
- gpr_now(GPR_CLOCK_MONOTONIC));
+ exec_ctx, &r->timer, GPR_MS_PER_SEC + grpc_exec_ctx_now(exec_ctx),
+ GRPC_CLOSURE_CREATE(finish_resolve, r, grpc_schedule_on_exec_ctx));
}
grpc_ares_request *my_dns_lookup_ares(
@@ -424,10 +424,8 @@ grpc_ares_request *my_dns_lookup_ares(
r->addrs = NULL;
r->lb_addrs = lb_addrs;
grpc_timer_init(
- exec_ctx, &r->timer, gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC),
- gpr_time_from_seconds(1, GPR_TIMESPAN)),
- GRPC_CLOSURE_CREATE(finish_resolve, r, grpc_schedule_on_exec_ctx),
- gpr_now(GPR_CLOCK_MONOTONIC));
+ exec_ctx, &r->timer, GPR_MS_PER_SEC + grpc_exec_ctx_now(exec_ctx),
+ GRPC_CLOSURE_CREATE(finish_resolve, r, grpc_schedule_on_exec_ctx));
return NULL;
}
@@ -487,10 +485,8 @@ static void sched_connect(grpc_exec_ctx *exec_ctx, grpc_closure *closure,
fc->ep = ep;
fc->deadline = deadline;
grpc_timer_init(
- exec_ctx, &fc->timer, gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC),
- gpr_time_from_millis(1, GPR_TIMESPAN)),
- GRPC_CLOSURE_CREATE(do_connect, fc, grpc_schedule_on_exec_ctx),
- gpr_now(GPR_CLOCK_MONOTONIC));
+ exec_ctx, &fc->timer, GPR_MS_PER_SEC + grpc_exec_ctx_now(exec_ctx),
+ GRPC_CLOSURE_CREATE(do_connect, fc, grpc_schedule_on_exec_ctx));
}
static void my_tcp_client_connect(grpc_exec_ctx *exec_ctx,
diff --git a/test/core/end2end/invalid_call_argument_test.c b/test/core/end2end/invalid_call_argument_test.c
index bf0d08adec..e3fd5a8fbe 100644
--- a/test/core/end2end/invalid_call_argument_test.c
+++ b/test/core/end2end/invalid_call_argument_test.c
@@ -92,7 +92,7 @@ static void prepare_test(int is_client) {
op = g_state.ops;
op->op = GRPC_OP_SEND_INITIAL_METADATA;
op->data.send_initial_metadata.count = 0;
- op->flags = 0;
+ op->flags = GRPC_INITIAL_METADATA_WAIT_FOR_READY;
op->reserved = NULL;
op++;
GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(g_state.call, g_state.ops,
diff --git a/test/core/end2end/tests/bad_ping.c b/test/core/end2end/tests/bad_ping.c
index c97d11b306..d442f12480 100644
--- a/test/core/end2end/tests/bad_ping.c
+++ b/test/core/end2end/tests/bad_ping.c
@@ -155,14 +155,16 @@ static void test_bad_ping(grpc_end2end_test_config config) {
cq_verify(cqv);
// Send too many pings to the server to trigger the punishment:
- // The first ping is sent after data frames, it won't trigger a ping strike.
- // Each of the following pings will trigger a ping strike, and we need at
- // least (MAX_PING_STRIKES + 1) strikes to trigger the punishment. So
- // (MAX_PING_STRIKES + 2) pings are needed here.
+ // Each ping will trigger a ping strike, and we need at least MAX_PING_STRIKES
+ // strikes to trigger the punishment. So (MAX_PING_STRIKES + 1) pings are
+ // needed here.
int i;
- for (i = 200; i < 202 + MAX_PING_STRIKES; i++) {
- grpc_channel_ping(f.client, f.cq, tag(i), NULL);
- CQ_EXPECT_COMPLETION(cqv, tag(i), 1);
+ for (i = 1; i <= MAX_PING_STRIKES + 1; i++) {
+ grpc_channel_ping(f.client, f.cq, tag(200 + i), NULL);
+ CQ_EXPECT_COMPLETION(cqv, tag(200 + i), 1);
+ if (i == MAX_PING_STRIKES + 1) {
+ CQ_EXPECT_COMPLETION(cqv, tag(1), 1);
+ }
cq_verify(cqv);
}
@@ -190,7 +192,6 @@ static void test_bad_ping(grpc_end2end_test_config config) {
GPR_ASSERT(GRPC_CALL_OK == error);
CQ_EXPECT_COMPLETION(cqv, tag(102), 1);
- CQ_EXPECT_COMPLETION(cqv, tag(1), 1);
cq_verify(cqv);
grpc_server_shutdown_and_notify(f.server, f.cq, tag(0xdead));
diff --git a/test/core/http/httpcli_test.c b/test/core/http/httpcli_test.c
index 8a53903763..cc1c16d695 100644
--- a/test/core/http/httpcli_test.c
+++ b/test/core/http/httpcli_test.c
@@ -35,8 +35,9 @@ static grpc_httpcli_context g_context;
static gpr_mu *g_mu;
static grpc_polling_entity g_pops;
-static gpr_timespec n_seconds_time(int seconds) {
- return grpc_timeout_seconds_to_deadline(seconds);
+static grpc_millis n_seconds_time(int seconds) {
+ return grpc_timespec_to_millis_round_up(
+ grpc_timeout_seconds_to_deadline(seconds));
}
static void on_finish(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {
@@ -86,8 +87,7 @@ static void test_get(int port) {
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"pollset_work",
grpc_pollset_work(&exec_ctx, grpc_polling_entity_pollset(&g_pops),
- &worker, gpr_now(GPR_CLOCK_MONOTONIC),
- n_seconds_time(1))));
+ &worker, n_seconds_time(1))));
gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
gpr_mu_lock(g_mu);
@@ -128,8 +128,7 @@ static void test_post(int port) {
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"pollset_work",
grpc_pollset_work(&exec_ctx, grpc_polling_entity_pollset(&g_pops),
- &worker, gpr_now(GPR_CLOCK_MONOTONIC),
- n_seconds_time(1))));
+ &worker, n_seconds_time(1))));
gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
gpr_mu_lock(g_mu);
diff --git a/test/core/http/httpscli_test.c b/test/core/http/httpscli_test.c
index c7455bd8df..f8a3cfdd76 100644
--- a/test/core/http/httpscli_test.c
+++ b/test/core/http/httpscli_test.c
@@ -35,8 +35,9 @@ static grpc_httpcli_context g_context;
static gpr_mu *g_mu;
static grpc_polling_entity g_pops;
-static gpr_timespec n_seconds_time(int seconds) {
- return grpc_timeout_seconds_to_deadline(seconds);
+static grpc_millis n_seconds_time(int seconds) {
+ return grpc_timespec_to_millis_round_up(
+ grpc_timeout_seconds_to_deadline(seconds));
}
static void on_finish(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {
@@ -87,8 +88,7 @@ static void test_get(int port) {
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"pollset_work",
grpc_pollset_work(&exec_ctx, grpc_polling_entity_pollset(&g_pops),
- &worker, gpr_now(GPR_CLOCK_MONOTONIC),
- n_seconds_time(1))));
+ &worker, n_seconds_time(1))));
gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
gpr_mu_lock(g_mu);
@@ -130,8 +130,7 @@ static void test_post(int port) {
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"pollset_work",
grpc_pollset_work(&exec_ctx, grpc_polling_entity_pollset(&g_pops),
- &worker, gpr_now(GPR_CLOCK_MONOTONIC),
- n_seconds_time(1))));
+ &worker, n_seconds_time(1))));
gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
gpr_mu_lock(g_mu);
diff --git a/test/core/iomgr/endpoint_tests.c b/test/core/iomgr/endpoint_tests.c
index f8570edde7..61e901f645 100644
--- a/test/core/iomgr/endpoint_tests.c
+++ b/test/core/iomgr/endpoint_tests.c
@@ -176,10 +176,11 @@ static void read_and_write_test(grpc_endpoint_test_config config,
size_t num_bytes, size_t write_size,
size_t slice_size, bool shutdown) {
struct read_and_write_test_state state;
- gpr_timespec deadline = grpc_timeout_seconds_to_deadline(20);
grpc_endpoint_test_fixture f =
begin_test(config, "read_and_write_test", slice_size);
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_millis deadline =
+ grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(20));
gpr_log(GPR_DEBUG, "num_bytes=%" PRIuPTR " write_size=%" PRIuPTR
" slice_size=%" PRIuPTR " shutdown=%d",
num_bytes, write_size, slice_size, shutdown);
@@ -235,11 +236,10 @@ static void read_and_write_test(grpc_endpoint_test_config config,
gpr_mu_lock(g_mu);
while (!state.read_done || !state.write_done) {
grpc_pollset_worker *worker = NULL;
- GPR_ASSERT(gpr_time_cmp(gpr_now(GPR_CLOCK_MONOTONIC), deadline) < 0);
+ GPR_ASSERT(grpc_exec_ctx_now(&exec_ctx) < deadline);
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"pollset_work",
- grpc_pollset_work(&exec_ctx, g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC), deadline)));
+ grpc_pollset_work(&exec_ctx, g_pollset, &worker, deadline)));
}
gpr_mu_unlock(g_mu);
grpc_exec_ctx_flush(&exec_ctx);
@@ -265,14 +265,14 @@ static void wait_for_fail_count(grpc_exec_ctx *exec_ctx, int *fail_count,
int want_fail_count) {
grpc_exec_ctx_flush(exec_ctx);
gpr_mu_lock(g_mu);
- gpr_timespec deadline = grpc_timeout_seconds_to_deadline(10);
- while (gpr_time_cmp(gpr_now(deadline.clock_type), deadline) < 0 &&
+ grpc_millis deadline =
+ grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(10));
+ while (grpc_exec_ctx_now(exec_ctx) < deadline &&
*fail_count < want_fail_count) {
grpc_pollset_worker *worker = NULL;
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"pollset_work",
- grpc_pollset_work(exec_ctx, g_pollset, &worker,
- gpr_now(deadline.clock_type), deadline)));
+ grpc_pollset_work(exec_ctx, g_pollset, &worker, deadline)));
gpr_mu_unlock(g_mu);
grpc_exec_ctx_flush(exec_ctx);
gpr_mu_lock(g_mu);
diff --git a/test/core/iomgr/ev_epollsig_linux_test.c b/test/core/iomgr/ev_epollsig_linux_test.c
index cca07bf002..37aadacd49 100644
--- a/test/core/iomgr/ev_epollsig_linux_test.c
+++ b/test/core/iomgr/ev_epollsig_linux_test.c
@@ -238,10 +238,8 @@ static void test_threading_loop(void *arg) {
grpc_pollset_worker *worker;
gpr_mu_lock(shared->mu);
GPR_ASSERT(GRPC_LOG_IF_ERROR(
- "pollset_work",
- grpc_pollset_work(&exec_ctx, shared->pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC),
- gpr_inf_future(GPR_CLOCK_MONOTONIC))));
+ "pollset_work", grpc_pollset_work(&exec_ctx, shared->pollset, &worker,
+ GRPC_MILLIS_INF_FUTURE)));
gpr_mu_unlock(shared->mu);
grpc_exec_ctx_finish(&exec_ctx);
}
diff --git a/test/core/iomgr/fd_posix_test.c b/test/core/iomgr/fd_posix_test.c
index 881277a8d6..1c62f34d3e 100644
--- a/test/core/iomgr/fd_posix_test.c
+++ b/test/core/iomgr/fd_posix_test.c
@@ -252,10 +252,8 @@ static void server_wait_and_shutdown(server *sv) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_pollset_worker *worker = NULL;
GPR_ASSERT(GRPC_LOG_IF_ERROR(
- "pollset_work",
- grpc_pollset_work(&exec_ctx, g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC),
- gpr_inf_future(GPR_CLOCK_MONOTONIC))));
+ "pollset_work", grpc_pollset_work(&exec_ctx, g_pollset, &worker,
+ GRPC_MILLIS_INF_FUTURE)));
gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
gpr_mu_lock(g_mu);
@@ -371,10 +369,8 @@ static void client_wait_and_shutdown(client *cl) {
grpc_pollset_worker *worker = NULL;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
GPR_ASSERT(GRPC_LOG_IF_ERROR(
- "pollset_work",
- grpc_pollset_work(&exec_ctx, g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC),
- gpr_inf_future(GPR_CLOCK_MONOTONIC))));
+ "pollset_work", grpc_pollset_work(&exec_ctx, g_pollset, &worker,
+ GRPC_MILLIS_INF_FUTURE)));
gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
gpr_mu_lock(g_mu);
@@ -477,10 +473,8 @@ static void test_grpc_fd_change(void) {
while (a.cb_that_ran == NULL) {
grpc_pollset_worker *worker = NULL;
GPR_ASSERT(GRPC_LOG_IF_ERROR(
- "pollset_work",
- grpc_pollset_work(&exec_ctx, g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC),
- gpr_inf_future(GPR_CLOCK_MONOTONIC))));
+ "pollset_work", grpc_pollset_work(&exec_ctx, g_pollset, &worker,
+ GRPC_MILLIS_INF_FUTURE)));
gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
gpr_mu_lock(g_mu);
@@ -503,10 +497,8 @@ static void test_grpc_fd_change(void) {
while (b.cb_that_ran == NULL) {
grpc_pollset_worker *worker = NULL;
GPR_ASSERT(GRPC_LOG_IF_ERROR(
- "pollset_work",
- grpc_pollset_work(&exec_ctx, g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC),
- gpr_inf_future(GPR_CLOCK_MONOTONIC))));
+ "pollset_work", grpc_pollset_work(&exec_ctx, g_pollset, &worker,
+ GRPC_MILLIS_INF_FUTURE)));
gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
gpr_mu_lock(g_mu);
diff --git a/test/core/iomgr/pollset_set_test.c b/test/core/iomgr/pollset_set_test.c
index 70efca8b16..dee526c22a 100644
--- a/test/core/iomgr/pollset_set_test.c
+++ b/test/core/iomgr/pollset_set_test.c
@@ -204,7 +204,7 @@ static void pollset_set_test_basic() {
*/
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_pollset_worker *worker;
- gpr_timespec deadline;
+ grpc_millis deadline;
test_fd tfds[10];
test_pollset pollsets[3];
@@ -257,10 +257,10 @@ static void pollset_set_test_basic() {
make_test_fds_readable(tfds, num_fds);
gpr_mu_lock(pollsets[i].mu);
- deadline = grpc_timeout_milliseconds_to_deadline(2);
+ deadline = grpc_timespec_to_millis_round_up(
+ grpc_timeout_milliseconds_to_deadline(2));
GPR_ASSERT(GRPC_ERROR_NONE ==
- grpc_pollset_work(&exec_ctx, pollsets[i].ps, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC), deadline));
+ grpc_pollset_work(&exec_ctx, pollsets[i].ps, &worker, deadline));
gpr_mu_unlock(pollsets[i].mu);
grpc_exec_ctx_flush(&exec_ctx);
@@ -309,7 +309,7 @@ void pollset_set_test_dup_fds() {
*/
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_pollset_worker *worker;
- gpr_timespec deadline;
+ grpc_millis deadline;
test_fd tfds[3];
test_pollset pollset;
@@ -339,10 +339,10 @@ void pollset_set_test_dup_fds() {
make_test_fds_readable(tfds, num_fds);
gpr_mu_lock(pollset.mu);
- deadline = grpc_timeout_milliseconds_to_deadline(2);
+ deadline = grpc_timespec_to_millis_round_up(
+ grpc_timeout_milliseconds_to_deadline(2));
GPR_ASSERT(GRPC_ERROR_NONE ==
- grpc_pollset_work(&exec_ctx, pollset.ps, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC), deadline));
+ grpc_pollset_work(&exec_ctx, pollset.ps, &worker, deadline));
gpr_mu_unlock(pollset.mu);
grpc_exec_ctx_flush(&exec_ctx);
@@ -382,7 +382,7 @@ void pollset_set_test_empty_pollset() {
*/
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_pollset_worker *worker;
- gpr_timespec deadline;
+ grpc_millis deadline;
test_fd tfds[3];
test_pollset pollsets[2];
@@ -408,10 +408,10 @@ void pollset_set_test_empty_pollset() {
make_test_fds_readable(tfds, num_fds);
gpr_mu_lock(pollsets[0].mu);
- deadline = grpc_timeout_milliseconds_to_deadline(2);
+ deadline = grpc_timespec_to_millis_round_up(
+ grpc_timeout_milliseconds_to_deadline(2));
GPR_ASSERT(GRPC_ERROR_NONE ==
- grpc_pollset_work(&exec_ctx, pollsets[0].ps, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC), deadline));
+ grpc_pollset_work(&exec_ctx, pollsets[0].ps, &worker, deadline));
gpr_mu_unlock(pollsets[0].mu);
grpc_exec_ctx_flush(&exec_ctx);
diff --git a/test/core/iomgr/resolve_address_posix_test.c b/test/core/iomgr/resolve_address_posix_test.c
index e4be99f03c..cb9d6080fb 100644
--- a/test/core/iomgr/resolve_address_posix_test.c
+++ b/test/core/iomgr/resolve_address_posix_test.c
@@ -72,35 +72,33 @@ void args_finish(grpc_exec_ctx *exec_ctx, args_struct *args) {
gpr_free(args->pollset);
}
-static gpr_timespec n_sec_deadline(int seconds) {
- return gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
- gpr_time_from_seconds(seconds, GPR_TIMESPAN));
+static grpc_millis n_sec_deadline(int seconds) {
+ return grpc_timespec_to_millis_round_up(
+ grpc_timeout_seconds_to_deadline(seconds));
}
static void actually_poll(void *argsp) {
args_struct *args = argsp;
- gpr_timespec deadline = n_sec_deadline(10);
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_millis deadline = n_sec_deadline(10);
while (true) {
bool done = gpr_atm_acq_load(&args->done_atm) != 0;
if (done) {
break;
}
- gpr_timespec time_left =
- gpr_time_sub(deadline, gpr_now(GPR_CLOCK_REALTIME));
- gpr_log(GPR_DEBUG, "done=%d, time_left=%" PRId64 ".%09d", done,
- time_left.tv_sec, time_left.tv_nsec);
- GPR_ASSERT(gpr_time_cmp(time_left, gpr_time_0(GPR_TIMESPAN)) >= 0);
+ grpc_millis time_left = deadline - grpc_exec_ctx_now(&exec_ctx);
+ gpr_log(GPR_DEBUG, "done=%d, time_left=%" PRIdPTR, done, time_left);
+ GPR_ASSERT(time_left >= 0);
grpc_pollset_worker *worker = NULL;
- grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
gpr_mu_lock(args->mu);
- GRPC_LOG_IF_ERROR(
- "pollset_work",
- grpc_pollset_work(&exec_ctx, args->pollset, &worker,
- gpr_now(GPR_CLOCK_REALTIME), n_sec_deadline(1)));
+ GRPC_LOG_IF_ERROR("pollset_work",
+ grpc_pollset_work(&exec_ctx, args->pollset, &worker,
+ n_sec_deadline(1)));
gpr_mu_unlock(args->mu);
- grpc_exec_ctx_finish(&exec_ctx);
+ grpc_exec_ctx_flush(&exec_ctx);
}
gpr_event_set(&args->ev, (void *)1);
+ grpc_exec_ctx_finish(&exec_ctx);
}
static void poll_pollset_until_request_done(args_struct *args) {
diff --git a/test/core/iomgr/resolve_address_test.c b/test/core/iomgr/resolve_address_test.c
index 1110c04b6e..178bbbb95f 100644
--- a/test/core/iomgr/resolve_address_test.c
+++ b/test/core/iomgr/resolve_address_test.c
@@ -68,34 +68,32 @@ void args_finish(grpc_exec_ctx *exec_ctx, args_struct *args) {
gpr_free(args->pollset);
}
-static gpr_timespec n_sec_deadline(int seconds) {
- return gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
- gpr_time_from_seconds(seconds, GPR_TIMESPAN));
+static grpc_millis n_sec_deadline(int seconds) {
+ return grpc_timespec_to_millis_round_up(
+ grpc_timeout_seconds_to_deadline(seconds));
}
static void poll_pollset_until_request_done(args_struct *args) {
- gpr_timespec deadline = n_sec_deadline(10);
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_millis deadline = n_sec_deadline(10);
while (true) {
bool done = gpr_atm_acq_load(&args->done_atm) != 0;
if (done) {
break;
}
- gpr_timespec time_left =
- gpr_time_sub(deadline, gpr_now(GPR_CLOCK_REALTIME));
- gpr_log(GPR_DEBUG, "done=%d, time_left=%" PRId64 ".%09d", done,
- time_left.tv_sec, time_left.tv_nsec);
- GPR_ASSERT(gpr_time_cmp(time_left, gpr_time_0(GPR_TIMESPAN)) >= 0);
+ grpc_millis time_left = deadline - grpc_exec_ctx_now(&exec_ctx);
+ gpr_log(GPR_DEBUG, "done=%d, time_left=%" PRIdPTR, done, time_left);
+ GPR_ASSERT(time_left >= 0);
grpc_pollset_worker *worker = NULL;
- grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
gpr_mu_lock(args->mu);
- GRPC_LOG_IF_ERROR(
- "pollset_work",
- grpc_pollset_work(&exec_ctx, args->pollset, &worker,
- gpr_now(GPR_CLOCK_REALTIME), n_sec_deadline(1)));
+ GRPC_LOG_IF_ERROR("pollset_work",
+ grpc_pollset_work(&exec_ctx, args->pollset, &worker,
+ n_sec_deadline(1)));
gpr_mu_unlock(args->mu);
- grpc_exec_ctx_finish(&exec_ctx);
+ grpc_exec_ctx_flush(&exec_ctx);
}
gpr_event_set(&args->ev, (void *)1);
+ grpc_exec_ctx_finish(&exec_ctx);
}
static void must_succeed(grpc_exec_ctx *exec_ctx, void *argsp,
diff --git a/test/core/iomgr/tcp_client_posix_test.c b/test/core/iomgr/tcp_client_posix_test.c
index 1032da942b..b8b76d1c42 100644
--- a/test/core/iomgr/tcp_client_posix_test.c
+++ b/test/core/iomgr/tcp_client_posix_test.c
@@ -46,8 +46,8 @@ static grpc_pollset *g_pollset;
static int g_connections_complete = 0;
static grpc_endpoint *g_connecting = NULL;
-static gpr_timespec test_deadline(void) {
- return grpc_timeout_seconds_to_deadline(10);
+static grpc_millis test_deadline(void) {
+ return grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(10));
}
static void finish_connection() {
@@ -109,7 +109,7 @@ void test_succeeds(void) {
(socklen_t *)&resolved_addr.len) == 0);
GRPC_CLOSURE_INIT(&done, must_succeed, NULL, grpc_schedule_on_exec_ctx);
grpc_tcp_client_connect(&exec_ctx, &done, &g_connecting, g_pollset_set, NULL,
- &resolved_addr, gpr_inf_future(GPR_CLOCK_REALTIME));
+ &resolved_addr, GRPC_MILLIS_INF_FUTURE);
/* await the connection */
do {
@@ -127,8 +127,8 @@ void test_succeeds(void) {
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"pollset_work",
grpc_pollset_work(&exec_ctx, g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC),
- grpc_timeout_seconds_to_deadline(5))));
+ grpc_timespec_to_millis_round_up(
+ grpc_timeout_seconds_to_deadline(5)))));
gpr_mu_unlock(g_mu);
grpc_exec_ctx_flush(&exec_ctx);
gpr_mu_lock(g_mu);
@@ -159,25 +159,24 @@ void test_fails(void) {
/* connect to a broken address */
GRPC_CLOSURE_INIT(&done, must_fail, NULL, grpc_schedule_on_exec_ctx);
grpc_tcp_client_connect(&exec_ctx, &done, &g_connecting, g_pollset_set, NULL,
- &resolved_addr, gpr_inf_future(GPR_CLOCK_REALTIME));
+ &resolved_addr, GRPC_MILLIS_INF_FUTURE);
gpr_mu_lock(g_mu);
/* wait for the connection callback to finish */
while (g_connections_complete == connections_complete_before) {
grpc_pollset_worker *worker = NULL;
- gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC);
- gpr_timespec polling_deadline = test_deadline();
- switch (grpc_timer_check(&exec_ctx, now, &polling_deadline)) {
+ grpc_millis polling_deadline = test_deadline();
+ switch (grpc_timer_check(&exec_ctx, &polling_deadline)) {
case GRPC_TIMERS_FIRED:
break;
case GRPC_TIMERS_NOT_CHECKED:
- polling_deadline = now;
+ polling_deadline = 0;
/* fall through */
case GRPC_TIMERS_CHECKED_AND_EMPTY:
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"pollset_work", grpc_pollset_work(&exec_ctx, g_pollset, &worker,
- now, polling_deadline)));
+ polling_deadline)));
break;
}
gpr_mu_unlock(g_mu);
diff --git a/test/core/iomgr/tcp_client_uv_test.c b/test/core/iomgr/tcp_client_uv_test.c
index b0ff11b39a..0f1db4705b 100644
--- a/test/core/iomgr/tcp_client_uv_test.c
+++ b/test/core/iomgr/tcp_client_uv_test.c
@@ -69,7 +69,7 @@ static void must_succeed(grpc_exec_ctx *exec_ctx, void *arg,
static void must_fail(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {
GPR_ASSERT(g_connecting == NULL);
GPR_ASSERT(error != GRPC_ERROR_NONE);
- finish_connection();
+ finish_connection(exec_ctx);
}
static void close_cb(uv_handle_t *handle) { gpr_free(handle); }
diff --git a/test/core/iomgr/tcp_posix_test.c b/test/core/iomgr/tcp_posix_test.c
index cfb3cf897c..6501160c6f 100644
--- a/test/core/iomgr/tcp_posix_test.c
+++ b/test/core/iomgr/tcp_posix_test.c
@@ -162,7 +162,8 @@ static void read_test(size_t num_bytes, size_t slice_size) {
grpc_endpoint *ep;
struct read_socket_state state;
size_t written_bytes;
- gpr_timespec deadline = grpc_timeout_seconds_to_deadline(20);
+ grpc_millis deadline =
+ grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(20));
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
gpr_log(GPR_INFO, "Read test of size %" PRIuPTR ", slice size %" PRIuPTR,
@@ -194,8 +195,7 @@ static void read_test(size_t num_bytes, size_t slice_size) {
grpc_pollset_worker *worker = NULL;
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"pollset_work",
- grpc_pollset_work(&exec_ctx, g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC), deadline)));
+ grpc_pollset_work(&exec_ctx, g_pollset, &worker, deadline)));
gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
gpr_mu_lock(g_mu);
@@ -215,7 +215,8 @@ static void large_read_test(size_t slice_size) {
grpc_endpoint *ep;
struct read_socket_state state;
ssize_t written_bytes;
- gpr_timespec deadline = grpc_timeout_seconds_to_deadline(20);
+ grpc_millis deadline =
+ grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(20));
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
gpr_log(GPR_INFO, "Start large read test, slice size %" PRIuPTR, slice_size);
@@ -246,8 +247,7 @@ static void large_read_test(size_t slice_size) {
grpc_pollset_worker *worker = NULL;
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"pollset_work",
- grpc_pollset_work(&exec_ctx, g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC), deadline)));
+ grpc_pollset_work(&exec_ctx, g_pollset, &worker, deadline)));
gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
gpr_mu_lock(g_mu);
@@ -319,8 +319,8 @@ void drain_socket_blocking(int fd, size_t num_bytes, size_t read_size) {
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"pollset_work",
grpc_pollset_work(&exec_ctx, g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC),
- grpc_timeout_milliseconds_to_deadline(10))));
+ grpc_timespec_to_millis_round_up(
+ grpc_timeout_milliseconds_to_deadline(10)))));
gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
do {
@@ -353,7 +353,8 @@ static void write_test(size_t num_bytes, size_t slice_size) {
uint8_t current_data = 0;
grpc_slice_buffer outgoing;
grpc_closure write_done_closure;
- gpr_timespec deadline = grpc_timeout_seconds_to_deadline(20);
+ grpc_millis deadline =
+ grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(20));
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
gpr_log(GPR_INFO,
@@ -390,8 +391,7 @@ static void write_test(size_t num_bytes, size_t slice_size) {
}
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"pollset_work",
- grpc_pollset_work(&exec_ctx, g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC), deadline)));
+ grpc_pollset_work(&exec_ctx, g_pollset, &worker, deadline)));
gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
gpr_mu_lock(g_mu);
@@ -419,7 +419,8 @@ static void release_fd_test(size_t num_bytes, size_t slice_size) {
struct read_socket_state state;
size_t written_bytes;
int fd;
- gpr_timespec deadline = grpc_timeout_seconds_to_deadline(20);
+ grpc_millis deadline =
+ grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(20));
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_closure fd_released_cb;
int fd_released_done = 0;
@@ -457,8 +458,7 @@ static void release_fd_test(size_t num_bytes, size_t slice_size) {
grpc_pollset_worker *worker = NULL;
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"pollset_work",
- grpc_pollset_work(&exec_ctx, g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC), deadline)));
+ grpc_pollset_work(&exec_ctx, g_pollset, &worker, deadline)));
gpr_log(GPR_DEBUG, "wakeup: read=%" PRIdPTR " target=%" PRIdPTR,
state.read_bytes, state.target_read_bytes);
gpr_mu_unlock(g_mu);
@@ -476,8 +476,7 @@ static void release_fd_test(size_t num_bytes, size_t slice_size) {
grpc_pollset_worker *worker = NULL;
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"pollset_work",
- grpc_pollset_work(&exec_ctx, g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC), deadline)));
+ grpc_pollset_work(&exec_ctx, g_pollset, &worker, deadline)));
gpr_log(GPR_DEBUG, "wakeup: fd_released_done=%d", fd_released_done);
}
gpr_mu_unlock(g_mu);
diff --git a/test/core/iomgr/tcp_server_posix_test.c b/test/core/iomgr/tcp_server_posix_test.c
index 4d84608376..782dfb413a 100644
--- a/test/core/iomgr/tcp_server_posix_test.c
+++ b/test/core/iomgr/tcp_server_posix_test.c
@@ -230,7 +230,8 @@ static void test_no_op_with_port_and_start(void) {
static grpc_error *tcp_connect(grpc_exec_ctx *exec_ctx, const test_addr *remote,
on_connect_result *result) {
- gpr_timespec deadline = grpc_timeout_seconds_to_deadline(10);
+ grpc_millis deadline =
+ grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(10));
int clifd;
int nconnects_before;
const struct sockaddr *remote_addr =
@@ -253,11 +254,10 @@ static grpc_error *tcp_connect(grpc_exec_ctx *exec_ctx, const test_addr *remote,
}
gpr_log(GPR_DEBUG, "wait");
while (g_nconnects == nconnects_before &&
- gpr_time_cmp(deadline, gpr_now(deadline.clock_type)) > 0) {
+ deadline > grpc_exec_ctx_now(exec_ctx)) {
grpc_pollset_worker *worker = NULL;
grpc_error *err;
- if ((err = grpc_pollset_work(exec_ctx, g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC), deadline)) !=
+ if ((err = grpc_pollset_work(exec_ctx, g_pollset, &worker, deadline)) !=
GRPC_ERROR_NONE) {
gpr_mu_unlock(g_mu);
close(clifd);
diff --git a/test/core/iomgr/timer_list_test.c b/test/core/iomgr/timer_list_test.c
index 5f8b01fdc4..c3d9f9d88d 100644
--- a/test/core/iomgr/timer_list_test.c
+++ b/test/core/iomgr/timer_list_test.c
@@ -41,51 +41,45 @@ static void cb(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {
}
static void add_test(void) {
- gpr_timespec start = gpr_now(GPR_CLOCK_REALTIME);
int i;
grpc_timer timers[20];
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
gpr_log(GPR_INFO, "add_test");
- grpc_timer_list_init(start);
+ grpc_timer_list_init(&exec_ctx);
grpc_timer_trace.value = 1;
grpc_timer_check_trace.value = 1;
memset(cb_called, 0, sizeof(cb_called));
+ grpc_millis start = grpc_exec_ctx_now(&exec_ctx);
+
/* 10 ms timers. will expire in the current epoch */
for (i = 0; i < 10; i++) {
- grpc_timer_init(
- &exec_ctx, &timers[i],
- gpr_time_add(start, gpr_time_from_millis(10, GPR_TIMESPAN)),
- GRPC_CLOSURE_CREATE(cb, (void *)(intptr_t)i, grpc_schedule_on_exec_ctx),
- start);
+ grpc_timer_init(&exec_ctx, &timers[i], start + 10,
+ GRPC_CLOSURE_CREATE(cb, (void *)(intptr_t)i,
+ grpc_schedule_on_exec_ctx));
}
/* 1010 ms timers. will expire in the next epoch */
for (i = 10; i < 20; i++) {
- grpc_timer_init(
- &exec_ctx, &timers[i],
- gpr_time_add(start, gpr_time_from_millis(1010, GPR_TIMESPAN)),
- GRPC_CLOSURE_CREATE(cb, (void *)(intptr_t)i, grpc_schedule_on_exec_ctx),
- start);
+ grpc_timer_init(&exec_ctx, &timers[i], start + 1010,
+ GRPC_CLOSURE_CREATE(cb, (void *)(intptr_t)i,
+ grpc_schedule_on_exec_ctx));
}
/* collect timers. Only the first batch should be ready. */
- GPR_ASSERT(grpc_timer_check(
- &exec_ctx,
- gpr_time_add(start, gpr_time_from_millis(500, GPR_TIMESPAN)),
- NULL) == GRPC_TIMERS_FIRED);
+ exec_ctx.now = start + 500;
+ GPR_ASSERT(grpc_timer_check(&exec_ctx, NULL) == GRPC_TIMERS_FIRED);
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(grpc_timer_check(
- &exec_ctx,
- gpr_time_add(start, gpr_time_from_millis(600, GPR_TIMESPAN)),
- NULL) == GRPC_TIMERS_CHECKED_AND_EMPTY);
+ exec_ctx.now = start + 600;
+ GPR_ASSERT(grpc_timer_check(&exec_ctx, NULL) ==
+ GRPC_TIMERS_CHECKED_AND_EMPTY);
grpc_exec_ctx_finish(&exec_ctx);
for (i = 0; i < 30; i++) {
GPR_ASSERT(cb_called[i][1] == (i < 10));
@@ -93,20 +87,17 @@ static void add_test(void) {
}
/* collect the rest of the timers */
- GPR_ASSERT(grpc_timer_check(
- &exec_ctx,
- gpr_time_add(start, gpr_time_from_millis(1500, GPR_TIMESPAN)),
- NULL) == GRPC_TIMERS_FIRED);
+ exec_ctx.now = start + 1500;
+ GPR_ASSERT(grpc_timer_check(&exec_ctx, NULL) == GRPC_TIMERS_FIRED);
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(grpc_timer_check(
- &exec_ctx,
- gpr_time_add(start, gpr_time_from_millis(1600, GPR_TIMESPAN)),
- NULL) == GRPC_TIMERS_CHECKED_AND_EMPTY);
+ exec_ctx.now = start + 1600;
+ GPR_ASSERT(grpc_timer_check(&exec_ctx, NULL) ==
+ GRPC_TIMERS_CHECKED_AND_EMPTY);
for (i = 0; i < 30; i++) {
GPR_ASSERT(cb_called[i][1] == (i < 20));
GPR_ASSERT(cb_called[i][0] == 0);
@@ -116,10 +107,6 @@ static void add_test(void) {
grpc_exec_ctx_finish(&exec_ctx);
}
-static gpr_timespec tfm(int m) {
- return gpr_time_from_millis(m, GPR_CLOCK_REALTIME);
-}
-
/* Cleaning up a list with pending timers. */
void destruction_test(void) {
grpc_timer timers[5];
@@ -127,32 +114,30 @@ void destruction_test(void) {
gpr_log(GPR_INFO, "destruction_test");
- grpc_timer_list_init(gpr_time_0(GPR_CLOCK_REALTIME));
+ exec_ctx.now_is_valid = true;
+ exec_ctx.now = 0;
+ grpc_timer_list_init(&exec_ctx);
grpc_timer_trace.value = 1;
grpc_timer_check_trace.value = 1;
memset(cb_called, 0, sizeof(cb_called));
grpc_timer_init(
- &exec_ctx, &timers[0], tfm(100),
- GRPC_CLOSURE_CREATE(cb, (void *)(intptr_t)0, grpc_schedule_on_exec_ctx),
- gpr_time_0(GPR_CLOCK_REALTIME));
+ &exec_ctx, &timers[0], 100,
+ GRPC_CLOSURE_CREATE(cb, (void *)(intptr_t)0, grpc_schedule_on_exec_ctx));
grpc_timer_init(
- &exec_ctx, &timers[1], tfm(3),
- GRPC_CLOSURE_CREATE(cb, (void *)(intptr_t)1, grpc_schedule_on_exec_ctx),
- gpr_time_0(GPR_CLOCK_REALTIME));
+ &exec_ctx, &timers[1], 3,
+ GRPC_CLOSURE_CREATE(cb, (void *)(intptr_t)1, grpc_schedule_on_exec_ctx));
grpc_timer_init(
- &exec_ctx, &timers[2], tfm(100),
- GRPC_CLOSURE_CREATE(cb, (void *)(intptr_t)2, grpc_schedule_on_exec_ctx),
- gpr_time_0(GPR_CLOCK_REALTIME));
+ &exec_ctx, &timers[2], 100,
+ GRPC_CLOSURE_CREATE(cb, (void *)(intptr_t)2, grpc_schedule_on_exec_ctx));
grpc_timer_init(
- &exec_ctx, &timers[3], tfm(3),
- GRPC_CLOSURE_CREATE(cb, (void *)(intptr_t)3, grpc_schedule_on_exec_ctx),
- gpr_time_0(GPR_CLOCK_REALTIME));
+ &exec_ctx, &timers[3], 3,
+ GRPC_CLOSURE_CREATE(cb, (void *)(intptr_t)3, grpc_schedule_on_exec_ctx));
grpc_timer_init(
- &exec_ctx, &timers[4], tfm(1),
- GRPC_CLOSURE_CREATE(cb, (void *)(intptr_t)4, grpc_schedule_on_exec_ctx),
- gpr_time_0(GPR_CLOCK_REALTIME));
- GPR_ASSERT(grpc_timer_check(&exec_ctx, tfm(2), NULL) == GRPC_TIMERS_FIRED);
+ &exec_ctx, &timers[4], 1,
+ GRPC_CLOSURE_CREATE(cb, (void *)(intptr_t)4, grpc_schedule_on_exec_ctx));
+ exec_ctx.now = 2;
+ GPR_ASSERT(grpc_timer_check(&exec_ctx, NULL) == GRPC_TIMERS_FIRED);
grpc_exec_ctx_finish(&exec_ctx);
GPR_ASSERT(1 == cb_called[4][1]);
grpc_timer_cancel(&exec_ctx, &timers[0]);
diff --git a/test/core/iomgr/udp_server_test.c b/test/core/iomgr/udp_server_test.c
index 1d051bea62..2e44d0abc8 100644
--- a/test/core/iomgr/udp_server_test.c
+++ b/test/core/iomgr/udp_server_test.c
@@ -226,7 +226,7 @@ static void test_receive(int number_of_clients) {
grpc_udp_server *s = grpc_udp_server_create(NULL);
int i;
int number_of_reads_before;
- gpr_timespec deadline;
+ grpc_millis deadline;
grpc_pollset *pollsets[1];
LOG_TEST("test_receive");
gpr_log(GPR_INFO, "clients=%d", number_of_clients);
@@ -252,7 +252,8 @@ static void test_receive(int number_of_clients) {
gpr_mu_lock(g_mu);
for (i = 0; i < number_of_clients; i++) {
- deadline = grpc_timeout_seconds_to_deadline(10);
+ deadline =
+ grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(10));
number_of_reads_before = g_number_of_reads;
/* Create a socket, send a packet to the UDP server. */
@@ -262,14 +263,13 @@ static void test_receive(int number_of_clients) {
(socklen_t)resolved_addr.len) == 0);
GPR_ASSERT(5 == write(clifd, "hello", 5));
while (g_number_of_reads == number_of_reads_before &&
- gpr_time_cmp(deadline, gpr_now(deadline.clock_type)) > 0) {
+ deadline > grpc_exec_ctx_now(&exec_ctx)) {
grpc_pollset_worker *worker = NULL;
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"pollset_work",
- grpc_pollset_work(&exec_ctx, g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC), deadline)));
+ grpc_pollset_work(&exec_ctx, g_pollset, &worker, deadline)));
gpr_mu_unlock(g_mu);
- grpc_exec_ctx_finish(&exec_ctx);
+ grpc_exec_ctx_flush(&exec_ctx);
gpr_mu_lock(g_mu);
}
GPR_ASSERT(g_number_of_reads == number_of_reads_before + 1);
diff --git a/test/core/security/credentials_test.c b/test/core/security/credentials_test.c
index 441c431135..fa8f1089c3 100644
--- a/test/core/security/credentials_test.c
+++ b/test/core/security/credentials_test.c
@@ -194,14 +194,13 @@ static void test_add_abunch_to_md_array(void) {
static void test_oauth2_token_fetcher_creds_parsing_ok(void) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_mdelem token_md = GRPC_MDNULL;
- gpr_timespec token_lifetime;
+ grpc_millis token_lifetime;
grpc_httpcli_response response =
http_response(200, valid_oauth2_json_response);
GPR_ASSERT(grpc_oauth2_token_fetcher_credentials_parse_server_response(
&exec_ctx, &response, &token_md, &token_lifetime) ==
GRPC_CREDENTIALS_OK);
- GPR_ASSERT(token_lifetime.tv_sec == 3599);
- GPR_ASSERT(token_lifetime.tv_nsec == 0);
+ GPR_ASSERT(token_lifetime == 3599 * GPR_MS_PER_SEC);
GPR_ASSERT(grpc_slice_str_cmp(GRPC_MDKEY(token_md), "authorization") == 0);
GPR_ASSERT(grpc_slice_str_cmp(GRPC_MDVALUE(token_md),
"Bearer ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_") ==
@@ -214,7 +213,7 @@ static void test_oauth2_token_fetcher_creds_parsing_ok(void) {
static void test_oauth2_token_fetcher_creds_parsing_bad_http_status(void) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_mdelem token_md = GRPC_MDNULL;
- gpr_timespec token_lifetime;
+ grpc_millis token_lifetime;
grpc_httpcli_response response =
http_response(401, valid_oauth2_json_response);
GPR_ASSERT(grpc_oauth2_token_fetcher_credentials_parse_server_response(
@@ -227,7 +226,7 @@ static void test_oauth2_token_fetcher_creds_parsing_bad_http_status(void) {
static void test_oauth2_token_fetcher_creds_parsing_empty_http_body(void) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_mdelem token_md = GRPC_MDNULL;
- gpr_timespec token_lifetime;
+ grpc_millis token_lifetime;
grpc_httpcli_response response = http_response(200, "");
GPR_ASSERT(grpc_oauth2_token_fetcher_credentials_parse_server_response(
&exec_ctx, &response, &token_md, &token_lifetime) ==
@@ -239,7 +238,7 @@ static void test_oauth2_token_fetcher_creds_parsing_empty_http_body(void) {
static void test_oauth2_token_fetcher_creds_parsing_invalid_json(void) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_mdelem token_md = GRPC_MDNULL;
- gpr_timespec token_lifetime;
+ grpc_millis token_lifetime;
grpc_httpcli_response response =
http_response(200,
"{\"access_token\":\"ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_\","
@@ -255,7 +254,7 @@ static void test_oauth2_token_fetcher_creds_parsing_invalid_json(void) {
static void test_oauth2_token_fetcher_creds_parsing_missing_token(void) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_mdelem token_md = GRPC_MDNULL;
- gpr_timespec token_lifetime;
+ grpc_millis token_lifetime;
grpc_httpcli_response response = http_response(200,
"{"
" \"expires_in\":3599, "
@@ -270,7 +269,7 @@ static void test_oauth2_token_fetcher_creds_parsing_missing_token(void) {
static void test_oauth2_token_fetcher_creds_parsing_missing_token_type(void) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_mdelem token_md = GRPC_MDNULL;
- gpr_timespec token_lifetime;
+ grpc_millis token_lifetime;
grpc_httpcli_response response =
http_response(200,
"{\"access_token\":\"ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_\","
@@ -287,7 +286,7 @@ static void test_oauth2_token_fetcher_creds_parsing_missing_token_lifetime(
void) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_mdelem token_md = GRPC_MDNULL;
- gpr_timespec token_lifetime;
+ grpc_millis token_lifetime;
grpc_httpcli_response response =
http_response(200,
"{\"access_token\":\"ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_\","
@@ -555,7 +554,7 @@ static void validate_compute_engine_http_request(
static int compute_engine_httpcli_get_success_override(
grpc_exec_ctx *exec_ctx, const grpc_httpcli_request *request,
- gpr_timespec deadline, grpc_closure *on_done,
+ grpc_millis deadline, grpc_closure *on_done,
grpc_httpcli_response *response) {
validate_compute_engine_http_request(request);
*response = http_response(200, valid_oauth2_json_response);
@@ -565,7 +564,7 @@ static int compute_engine_httpcli_get_success_override(
static int compute_engine_httpcli_get_failure_override(
grpc_exec_ctx *exec_ctx, const grpc_httpcli_request *request,
- gpr_timespec deadline, grpc_closure *on_done,
+ grpc_millis deadline, grpc_closure *on_done,
grpc_httpcli_response *response) {
validate_compute_engine_http_request(request);
*response = http_response(403, "Not Authorized.");
@@ -575,7 +574,7 @@ static int compute_engine_httpcli_get_failure_override(
static int httpcli_post_should_not_be_called(
grpc_exec_ctx *exec_ctx, const grpc_httpcli_request *request,
- const char *body_bytes, size_t body_size, gpr_timespec deadline,
+ const char *body_bytes, size_t body_size, grpc_millis deadline,
grpc_closure *on_done, grpc_httpcli_response *response) {
GPR_ASSERT("HTTP POST should not be called" == NULL);
return 1;
@@ -583,7 +582,7 @@ static int httpcli_post_should_not_be_called(
static int httpcli_get_should_not_be_called(grpc_exec_ctx *exec_ctx,
const grpc_httpcli_request *request,
- gpr_timespec deadline,
+ grpc_millis deadline,
grpc_closure *on_done,
grpc_httpcli_response *response) {
GPR_ASSERT("HTTP GET should not be called" == NULL);
@@ -663,7 +662,7 @@ static void validate_refresh_token_http_request(
static int refresh_token_httpcli_post_success(
grpc_exec_ctx *exec_ctx, const grpc_httpcli_request *request,
- const char *body, size_t body_size, gpr_timespec deadline,
+ const char *body, size_t body_size, grpc_millis deadline,
grpc_closure *on_done, grpc_httpcli_response *response) {
validate_refresh_token_http_request(request, body, body_size);
*response = http_response(200, valid_oauth2_json_response);
@@ -673,7 +672,7 @@ static int refresh_token_httpcli_post_success(
static int refresh_token_httpcli_post_failure(
grpc_exec_ctx *exec_ctx, const grpc_httpcli_request *request,
- const char *body, size_t body_size, gpr_timespec deadline,
+ const char *body, size_t body_size, grpc_millis deadline,
grpc_closure *on_done, grpc_httpcli_response *response) {
validate_refresh_token_http_request(request, body, body_size);
*response = http_response(403, "Not Authorized.");
@@ -932,7 +931,7 @@ static void test_google_default_creds_refresh_token(void) {
static int default_creds_gce_detection_httpcli_get_success_override(
grpc_exec_ctx *exec_ctx, const grpc_httpcli_request *request,
- gpr_timespec deadline, grpc_closure *on_done,
+ grpc_millis deadline, grpc_closure *on_done,
grpc_httpcli_response *response) {
*response = http_response(200, "");
grpc_http_header *headers = gpr_malloc(sizeof(*headers) * 1);
@@ -996,7 +995,7 @@ static void test_google_default_creds_gce(void) {
static int default_creds_gce_detection_httpcli_get_failure_override(
grpc_exec_ctx *exec_ctx, const grpc_httpcli_request *request,
- gpr_timespec deadline, grpc_closure *on_done,
+ grpc_millis deadline, grpc_closure *on_done,
grpc_httpcli_response *response) {
/* No magic header. */
GPR_ASSERT(strcmp(request->http.path, "/") == 0);
diff --git a/test/core/security/jwt_verifier_test.c b/test/core/security/jwt_verifier_test.c
index 9b17fb516d..a4bfe0130e 100644
--- a/test/core/security/jwt_verifier_test.c
+++ b/test/core/security/jwt_verifier_test.c
@@ -324,7 +324,7 @@ static grpc_httpcli_response http_response(int status, char *body) {
static int httpcli_post_should_not_be_called(
grpc_exec_ctx *exec_ctx, const grpc_httpcli_request *request,
- const char *body_bytes, size_t body_size, gpr_timespec deadline,
+ const char *body_bytes, size_t body_size, grpc_millis deadline,
grpc_closure *on_done, grpc_httpcli_response *response) {
GPR_ASSERT("HTTP POST should not be called" == NULL);
return 1;
@@ -332,7 +332,7 @@ static int httpcli_post_should_not_be_called(
static int httpcli_get_google_keys_for_email(
grpc_exec_ctx *exec_ctx, const grpc_httpcli_request *request,
- gpr_timespec deadline, grpc_closure *on_done,
+ grpc_millis deadline, grpc_closure *on_done,
grpc_httpcli_response *response) {
*response = http_response(200, good_google_email_keys());
GPR_ASSERT(request->handshaker == &grpc_httpcli_ssl);
@@ -379,7 +379,7 @@ static void test_jwt_verifier_google_email_issuer_success(void) {
static int httpcli_get_custom_keys_for_email(
grpc_exec_ctx *exec_ctx, const grpc_httpcli_request *request,
- gpr_timespec deadline, grpc_closure *on_done,
+ grpc_millis deadline, grpc_closure *on_done,
grpc_httpcli_response *response) {
*response = http_response(200, gpr_strdup(good_jwk_set));
GPR_ASSERT(request->handshaker == &grpc_httpcli_ssl);
@@ -413,7 +413,7 @@ static void test_jwt_verifier_custom_email_issuer_success(void) {
static int httpcli_get_jwk_set(grpc_exec_ctx *exec_ctx,
const grpc_httpcli_request *request,
- gpr_timespec deadline, grpc_closure *on_done,
+ grpc_millis deadline, grpc_closure *on_done,
grpc_httpcli_response *response) {
*response = http_response(200, gpr_strdup(good_jwk_set));
GPR_ASSERT(request->handshaker == &grpc_httpcli_ssl);
@@ -425,7 +425,7 @@ static int httpcli_get_jwk_set(grpc_exec_ctx *exec_ctx,
static int httpcli_get_openid_config(grpc_exec_ctx *exec_ctx,
const grpc_httpcli_request *request,
- gpr_timespec deadline,
+ grpc_millis deadline,
grpc_closure *on_done,
grpc_httpcli_response *response) {
*response = http_response(200, gpr_strdup(good_openid_config));
@@ -471,7 +471,7 @@ static void on_verification_key_retrieval_error(grpc_exec_ctx *exec_ctx,
static int httpcli_get_bad_json(grpc_exec_ctx *exec_ctx,
const grpc_httpcli_request *request,
- gpr_timespec deadline, grpc_closure *on_done,
+ grpc_millis deadline, grpc_closure *on_done,
grpc_httpcli_response *response) {
*response = http_response(200, gpr_strdup("{\"bad\": \"stuff\"}"));
GPR_ASSERT(request->handshaker == &grpc_httpcli_ssl);
@@ -581,7 +581,7 @@ static void test_jwt_verifier_bad_signature(void) {
static int httpcli_get_should_not_be_called(grpc_exec_ctx *exec_ctx,
const grpc_httpcli_request *request,
- gpr_timespec deadline,
+ grpc_millis deadline,
grpc_closure *on_done,
grpc_httpcli_response *response) {
GPR_ASSERT(0);
diff --git a/test/core/security/oauth2_utils.c b/test/core/security/oauth2_utils.c
index d240403a29..73d6c5bc7d 100644
--- a/test/core/security/oauth2_utils.c
+++ b/test/core/security/oauth2_utils.c
@@ -104,8 +104,7 @@ char *grpc_test_fetch_oauth2_token_with_credentials(
"pollset_work",
grpc_pollset_work(&exec_ctx,
grpc_polling_entity_pollset(&request.pops),
- &worker, gpr_now(GPR_CLOCK_MONOTONIC),
- gpr_inf_future(GPR_CLOCK_MONOTONIC)))) {
+ &worker, GRPC_MILLIS_INF_FUTURE))) {
request.is_done = true;
}
}
diff --git a/test/core/security/print_google_default_creds_token.c b/test/core/security/print_google_default_creds_token.c
index 3144717a85..29c38dfdf8 100644
--- a/test/core/security/print_google_default_creds_token.c
+++ b/test/core/security/print_google_default_creds_token.c
@@ -110,8 +110,7 @@ int main(int argc, char **argv) {
"pollset_work",
grpc_pollset_work(&exec_ctx,
grpc_polling_entity_pollset(&sync.pops), &worker,
- gpr_now(GPR_CLOCK_MONOTONIC),
- gpr_inf_future(GPR_CLOCK_MONOTONIC))))
+ GRPC_MILLIS_INF_FUTURE)))
sync.is_done = true;
gpr_mu_unlock(sync.mu);
grpc_exec_ctx_flush(&exec_ctx);
diff --git a/test/core/security/ssl_server_fuzzer.c b/test/core/security/ssl_server_fuzzer.c
index 9858b11c7c..f9b754b8f2 100644
--- a/test/core/security/ssl_server_fuzzer.c
+++ b/test/core/security/ssl_server_fuzzer.c
@@ -84,8 +84,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
grpc_security_status status =
grpc_server_credentials_create_security_connector(&exec_ctx, creds, &sc);
GPR_ASSERT(status == GRPC_SECURITY_OK);
- gpr_timespec deadline = gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC),
- gpr_time_from_seconds(1, GPR_TIMESPAN));
+ grpc_millis deadline = GPR_MS_PER_SEC + grpc_exec_ctx_now(&exec_ctx);
struct handshake_state state;
state.done_callback_called = false;
diff --git a/test/core/security/verify_jwt.c b/test/core/security/verify_jwt.c
index 5faa6352a8..cec6fb94b4 100644
--- a/test/core/security/verify_jwt.c
+++ b/test/core/security/verify_jwt.c
@@ -102,11 +102,9 @@ int main(int argc, char **argv) {
gpr_mu_lock(sync.mu);
while (!sync.is_done) {
grpc_pollset_worker *worker = NULL;
- if (!GRPC_LOG_IF_ERROR(
- "pollset_work",
- grpc_pollset_work(&exec_ctx, sync.pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC),
- gpr_inf_future(GPR_CLOCK_MONOTONIC))))
+ if (!GRPC_LOG_IF_ERROR("pollset_work",
+ grpc_pollset_work(&exec_ctx, sync.pollset, &worker,
+ GRPC_MILLIS_INF_FUTURE)))
sync.is_done = true;
gpr_mu_unlock(sync.mu);
grpc_exec_ctx_flush(&exec_ctx);
diff --git a/test/core/support/BUILD b/test/core/support/BUILD
index 096576e13c..407c3eff7b 100644
--- a/test/core/support/BUILD
+++ b/test/core/support/BUILD
@@ -39,16 +39,6 @@ grpc_cc_test(
)
grpc_cc_test(
- name = "backoff_test",
- srcs = ["backoff_test.c"],
- language = "C",
- deps = [
- "//:gpr",
- "//test/core/util:gpr_test_util",
- ],
-)
-
-grpc_cc_test(
name = "cmdline_test",
srcs = ["cmdline_test.c"],
language = "C",
diff --git a/test/core/support/backoff_test.c b/test/core/support/backoff_test.c
deleted file mode 100644
index 23e3005af0..0000000000
--- a/test/core/support/backoff_test.c
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- *
- * Copyright 2016 gRPC authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include "src/core/lib/support/backoff.h"
-
-#include <grpc/support/log.h>
-
-#include "test/core/util/test_config.h"
-
-static void test_constant_backoff(void) {
- gpr_backoff backoff;
- gpr_backoff_init(&backoff, 200 /* initial timeout */, 1.0 /* multiplier */,
- 0.0 /* jitter */, 100 /* min timeout */,
- 1000 /* max timeout */);
-
- gpr_timespec now = gpr_time_0(GPR_TIMESPAN);
- gpr_timespec next = gpr_backoff_begin(&backoff, now);
- GPR_ASSERT(gpr_time_to_millis(gpr_time_sub(next, now)) == 200);
- for (int i = 0; i < 10000; i++) {
- next = gpr_backoff_step(&backoff, now);
- GPR_ASSERT(gpr_time_to_millis(gpr_time_sub(next, now)) == 200);
- now = next;
- }
-}
-
-static void test_min_connect(void) {
- gpr_backoff backoff;
- gpr_backoff_init(&backoff, 100 /* initial timeout */, 1.0 /* multiplier */,
- 0.0 /* jitter */, 200 /* min timeout */,
- 1000 /* max timeout */);
-
- gpr_timespec now = gpr_time_0(GPR_TIMESPAN);
- gpr_timespec next = gpr_backoff_begin(&backoff, now);
- GPR_ASSERT(gpr_time_to_millis(gpr_time_sub(next, now)) == 200);
-}
-
-static void test_no_jitter_backoff(void) {
- gpr_backoff backoff;
- gpr_backoff_init(&backoff, 2 /* initial timeout */, 2.0 /* multiplier */,
- 0.0 /* jitter */, 1 /* min timeout */,
- 513 /* max timeout */);
- // x_1 = 2
- // x_n = 2**i + x_{i-1} ( = 2**(n+1) - 2 )
- gpr_timespec now = gpr_time_0(GPR_TIMESPAN);
- gpr_timespec next = gpr_backoff_begin(&backoff, now);
- GPR_ASSERT(gpr_time_cmp(gpr_time_from_millis(2, GPR_TIMESPAN), next) == 0);
- now = next;
- next = gpr_backoff_step(&backoff, now);
- GPR_ASSERT(gpr_time_cmp(gpr_time_from_millis(6, GPR_TIMESPAN), next) == 0);
- now = next;
- next = gpr_backoff_step(&backoff, now);
- GPR_ASSERT(gpr_time_cmp(gpr_time_from_millis(14, GPR_TIMESPAN), next) == 0);
- now = next;
- next = gpr_backoff_step(&backoff, now);
- GPR_ASSERT(gpr_time_cmp(gpr_time_from_millis(30, GPR_TIMESPAN), next) == 0);
- now = next;
- next = gpr_backoff_step(&backoff, now);
- GPR_ASSERT(gpr_time_cmp(gpr_time_from_millis(62, GPR_TIMESPAN), next) == 0);
- now = next;
- next = gpr_backoff_step(&backoff, now);
- GPR_ASSERT(gpr_time_cmp(gpr_time_from_millis(126, GPR_TIMESPAN), next) == 0);
- now = next;
- next = gpr_backoff_step(&backoff, now);
- GPR_ASSERT(gpr_time_cmp(gpr_time_from_millis(254, GPR_TIMESPAN), next) == 0);
- now = next;
- next = gpr_backoff_step(&backoff, now);
- GPR_ASSERT(gpr_time_cmp(gpr_time_from_millis(510, GPR_TIMESPAN), next) == 0);
- now = next;
- next = gpr_backoff_step(&backoff, now);
- GPR_ASSERT(gpr_time_cmp(gpr_time_from_millis(1022, GPR_TIMESPAN), next) == 0);
- now = next;
- next = gpr_backoff_step(&backoff, now);
- // Hit the maximum timeout. From this point onwards, retries will increase
- // only by max timeout.
- GPR_ASSERT(gpr_time_cmp(gpr_time_from_millis(1535, GPR_TIMESPAN), next) == 0);
- now = next;
- next = gpr_backoff_step(&backoff, now);
- GPR_ASSERT(gpr_time_cmp(gpr_time_from_millis(2048, GPR_TIMESPAN), next) == 0);
- now = next;
- next = gpr_backoff_step(&backoff, now);
- GPR_ASSERT(gpr_time_cmp(gpr_time_from_millis(2561, GPR_TIMESPAN), next) == 0);
-}
-
-static void test_jitter_backoff(void) {
- const int64_t initial_timeout = 500;
- const double jitter = 0.1;
- gpr_backoff backoff;
- gpr_backoff_init(&backoff, initial_timeout, 1.0 /* multiplier */, jitter,
- 100 /* min timeout */, 1000 /* max timeout */);
-
- backoff.rng_state = 0; // force consistent PRNG
-
- gpr_timespec now = gpr_time_0(GPR_TIMESPAN);
- gpr_timespec next = gpr_backoff_begin(&backoff, now);
- GPR_ASSERT(gpr_time_to_millis(gpr_time_sub(next, now)) == 500);
-
- int64_t expected_next_lower_bound =
- (int64_t)((double)initial_timeout * (1 - jitter));
- int64_t expected_next_upper_bound =
- (int64_t)((double)initial_timeout * (1 + jitter));
-
- for (int i = 0; i < 10000; i++) {
- next = gpr_backoff_step(&backoff, now);
-
- // next-now must be within (jitter*100)% of the previous timeout.
- const int64_t timeout_millis = gpr_time_to_millis(gpr_time_sub(next, now));
- GPR_ASSERT(timeout_millis >= expected_next_lower_bound);
- GPR_ASSERT(timeout_millis <= expected_next_upper_bound);
-
- expected_next_lower_bound =
- (int64_t)((double)timeout_millis * (1 - jitter));
- expected_next_upper_bound =
- (int64_t)((double)timeout_millis * (1 + jitter));
- now = next;
- }
-}
-
-int main(int argc, char **argv) {
- grpc_test_init(argc, argv);
- gpr_time_init();
-
- test_constant_backoff();
- test_min_connect();
- test_no_jitter_backoff();
- test_jitter_backoff();
-
- return 0;
-}
diff --git a/test/core/surface/concurrent_connectivity_test.c b/test/core/surface/concurrent_connectivity_test.c
index ec2cd8610b..3595885ff6 100644
--- a/test/core/surface/concurrent_connectivity_test.c
+++ b/test/core/surface/concurrent_connectivity_test.c
@@ -135,14 +135,12 @@ void bad_server_thread(void *vargs) {
gpr_mu_lock(args->mu);
while (gpr_atm_acq_load(&args->stop) == 0) {
- gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC);
- gpr_timespec deadline =
- gpr_time_add(now, gpr_time_from_millis(100, GPR_TIMESPAN));
+ grpc_millis deadline = grpc_exec_ctx_now(&exec_ctx) + 100;
grpc_pollset_worker *worker = NULL;
- if (!GRPC_LOG_IF_ERROR("pollset_work",
- grpc_pollset_work(&exec_ctx, args->pollset, &worker,
- now, deadline))) {
+ if (!GRPC_LOG_IF_ERROR(
+ "pollset_work",
+ grpc_pollset_work(&exec_ctx, args->pollset, &worker, deadline))) {
gpr_atm_rel_store(&args->stop, 1);
}
gpr_mu_unlock(args->mu);
diff --git a/test/core/transport/status_conversion_test.c b/test/core/transport/status_conversion_test.c
index 89558964c1..de8fa4458a 100644
--- a/test/core/transport/status_conversion_test.c
+++ b/test/core/transport/status_conversion_test.c
@@ -22,8 +22,13 @@
#define GRPC_STATUS_TO_HTTP2_ERROR(a, b) \
GPR_ASSERT(grpc_status_to_http2_error(a) == (b))
-#define HTTP2_ERROR_TO_GRPC_STATUS(a, deadline, b) \
- GPR_ASSERT(grpc_http2_error_to_grpc_status(a, deadline) == (b))
+#define HTTP2_ERROR_TO_GRPC_STATUS(a, deadline, b) \
+ do { \
+ grpc_exec_ctx my_exec_ctx = GRPC_EXEC_CTX_INIT; \
+ GPR_ASSERT(grpc_http2_error_to_grpc_status(&my_exec_ctx, a, deadline) == \
+ (b)); \
+ grpc_exec_ctx_finish(&my_exec_ctx); \
+ } while (0)
#define GRPC_STATUS_TO_HTTP2_STATUS(a, b) \
GPR_ASSERT(grpc_status_to_http2_status(a) == (b))
#define HTTP2_STATUS_TO_GRPC_STATUS(a, b) \
@@ -79,7 +84,7 @@ int main(int argc, char **argv) {
GRPC_STATUS_TO_HTTP2_STATUS(GRPC_STATUS_UNAVAILABLE, 200);
GRPC_STATUS_TO_HTTP2_STATUS(GRPC_STATUS_DATA_LOSS, 200);
- const gpr_timespec before_deadline = gpr_inf_future(GPR_CLOCK_MONOTONIC);
+ const grpc_millis before_deadline = GRPC_MILLIS_INF_FUTURE;
HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_NO_ERROR, before_deadline,
GRPC_STATUS_INTERNAL);
HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_PROTOCOL_ERROR, before_deadline,
@@ -107,7 +112,7 @@ int main(int argc, char **argv) {
HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_INADEQUATE_SECURITY, before_deadline,
GRPC_STATUS_PERMISSION_DENIED);
- const gpr_timespec after_deadline = gpr_inf_past(GPR_CLOCK_MONOTONIC);
+ const grpc_millis after_deadline = 0;
HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_NO_ERROR, after_deadline,
GRPC_STATUS_INTERNAL);
HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_PROTOCOL_ERROR, after_deadline,
diff --git a/test/core/transport/timeout_encoding_test.c b/test/core/transport/timeout_encoding_test.c
index 6388ffbcec..3010c6d057 100644
--- a/test/core/transport/timeout_encoding_test.c
+++ b/test/core/transport/timeout_encoding_test.c
@@ -25,12 +25,13 @@
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
#include <grpc/support/useful.h>
+#include "src/core/lib/support/murmur_hash.h"
#include "src/core/lib/support/string.h"
#include "test/core/util/test_config.h"
#define LOG_TEST(x) gpr_log(GPR_INFO, "%s", x)
-static void assert_encodes_as(gpr_timespec ts, const char *s) {
+static void assert_encodes_as(grpc_millis ts, const char *s) {
char buffer[GRPC_HTTP2_TIMEOUT_ENCODE_MIN_BUFSIZE];
grpc_http2_encode_timeout(ts, buffer);
gpr_log(GPR_INFO, "check '%s' == '%s'", buffer, s);
@@ -39,47 +40,43 @@ static void assert_encodes_as(gpr_timespec ts, const char *s) {
void test_encoding(void) {
LOG_TEST("test_encoding");
- assert_encodes_as(gpr_time_from_micros(-1, GPR_TIMESPAN), "1n");
- assert_encodes_as(gpr_time_from_seconds(-10, GPR_TIMESPAN), "1n");
- assert_encodes_as(gpr_time_from_nanos(10, GPR_TIMESPAN), "10n");
- assert_encodes_as(gpr_time_from_nanos(999999999, GPR_TIMESPAN), "1S");
- assert_encodes_as(gpr_time_from_micros(1, GPR_TIMESPAN), "1u");
- assert_encodes_as(gpr_time_from_micros(10, GPR_TIMESPAN), "10u");
- assert_encodes_as(gpr_time_from_micros(100, GPR_TIMESPAN), "100u");
- assert_encodes_as(gpr_time_from_micros(890, GPR_TIMESPAN), "890u");
- assert_encodes_as(gpr_time_from_micros(900, GPR_TIMESPAN), "900u");
- assert_encodes_as(gpr_time_from_micros(901, GPR_TIMESPAN), "901u");
- assert_encodes_as(gpr_time_from_millis(1, GPR_TIMESPAN), "1m");
- assert_encodes_as(gpr_time_from_millis(2, GPR_TIMESPAN), "2m");
- assert_encodes_as(gpr_time_from_micros(10001, GPR_TIMESPAN), "10100u");
- assert_encodes_as(gpr_time_from_micros(999999, GPR_TIMESPAN), "1S");
- assert_encodes_as(gpr_time_from_millis(1000, GPR_TIMESPAN), "1S");
- assert_encodes_as(gpr_time_from_millis(2000, GPR_TIMESPAN), "2S");
- assert_encodes_as(gpr_time_from_millis(2500, GPR_TIMESPAN), "2500m");
- assert_encodes_as(gpr_time_from_millis(59900, GPR_TIMESPAN), "59900m");
- assert_encodes_as(gpr_time_from_seconds(50, GPR_TIMESPAN), "50S");
- assert_encodes_as(gpr_time_from_seconds(59, GPR_TIMESPAN), "59S");
- assert_encodes_as(gpr_time_from_seconds(60, GPR_TIMESPAN), "1M");
- assert_encodes_as(gpr_time_from_seconds(80, GPR_TIMESPAN), "80S");
- assert_encodes_as(gpr_time_from_seconds(90, GPR_TIMESPAN), "90S");
- assert_encodes_as(gpr_time_from_minutes(2, GPR_TIMESPAN), "2M");
- assert_encodes_as(gpr_time_from_minutes(20, GPR_TIMESPAN), "20M");
- assert_encodes_as(gpr_time_from_hours(1, GPR_TIMESPAN), "1H");
- assert_encodes_as(gpr_time_from_hours(10, GPR_TIMESPAN), "10H");
- assert_encodes_as(gpr_time_from_seconds(1000000000, GPR_TIMESPAN),
- "1000000000S");
+ assert_encodes_as(-1, "1n");
+ assert_encodes_as(-10, "1n");
+ assert_encodes_as(1, "1m");
+ assert_encodes_as(10, "10m");
+ assert_encodes_as(100, "100m");
+ assert_encodes_as(890, "890m");
+ assert_encodes_as(900, "900m");
+ assert_encodes_as(901, "901m");
+ assert_encodes_as(1000, "1S");
+ assert_encodes_as(2000, "2S");
+ assert_encodes_as(2500, "2500m");
+ assert_encodes_as(59900, "59900m");
+ assert_encodes_as(50000, "50S");
+ assert_encodes_as(59000, "59S");
+ assert_encodes_as(60000, "1M");
+ assert_encodes_as(80000, "80S");
+ assert_encodes_as(90000, "90S");
+ assert_encodes_as(120000, "2M");
+ assert_encodes_as(20 * 60 * GPR_MS_PER_SEC, "20M");
+ assert_encodes_as(60 * 60 * GPR_MS_PER_SEC, "1H");
+ assert_encodes_as(10 * 60 * 60 * GPR_MS_PER_SEC, "10H");
}
-static void assert_decodes_as(const char *buffer, gpr_timespec expected) {
- gpr_timespec got;
- gpr_log(GPR_INFO, "check decoding '%s'", buffer);
+static void assert_decodes_as(const char *buffer, grpc_millis expected) {
+ grpc_millis got;
+ uint32_t hash = gpr_murmur_hash3(buffer, strlen(buffer), 0);
+ gpr_log(GPR_INFO, "check decoding '%s' (hash=0x%x)", buffer, hash);
GPR_ASSERT(1 == grpc_http2_decode_timeout(
grpc_slice_from_static_string(buffer), &got));
- GPR_ASSERT(0 == gpr_time_cmp(got, expected));
+ if (got != expected) {
+ gpr_log(GPR_ERROR, "got:'%" PRIdPTR "' != expected:'%" PRIdPTR "'", got,
+ expected);
+ abort();
+ }
}
-void decode_suite(char ext,
- gpr_timespec (*answer)(int64_t x, gpr_clock_type clock)) {
+void decode_suite(char ext, grpc_millis (*answer)(int64_t x)) {
long test_vals[] = {1, 12, 123, 1234, 12345, 123456,
1234567, 12345678, 123456789, 98765432, 9876543, 987654,
98765, 9876, 987, 98, 9};
@@ -87,41 +84,55 @@ void decode_suite(char ext,
char *input;
for (i = 0; i < GPR_ARRAY_SIZE(test_vals); i++) {
gpr_asprintf(&input, "%ld%c", test_vals[i], ext);
- assert_decodes_as(input, answer(test_vals[i], GPR_TIMESPAN));
+ assert_decodes_as(input, answer(test_vals[i]));
gpr_free(input);
gpr_asprintf(&input, " %ld%c", test_vals[i], ext);
- assert_decodes_as(input, answer(test_vals[i], GPR_TIMESPAN));
+ assert_decodes_as(input, answer(test_vals[i]));
gpr_free(input);
gpr_asprintf(&input, "%ld %c", test_vals[i], ext);
- assert_decodes_as(input, answer(test_vals[i], GPR_TIMESPAN));
+ assert_decodes_as(input, answer(test_vals[i]));
gpr_free(input);
gpr_asprintf(&input, "%ld %c ", test_vals[i], ext);
- assert_decodes_as(input, answer(test_vals[i], GPR_TIMESPAN));
+ assert_decodes_as(input, answer(test_vals[i]));
gpr_free(input);
}
}
+static grpc_millis millis_from_nanos(int64_t x) {
+ return x / GPR_NS_PER_MS + (x % GPR_NS_PER_MS != 0);
+}
+static grpc_millis millis_from_micros(int64_t x) {
+ return x / GPR_US_PER_MS + (x % GPR_US_PER_MS != 0);
+}
+static grpc_millis millis_from_millis(int64_t x) { return x; }
+static grpc_millis millis_from_seconds(int64_t x) { return x * GPR_MS_PER_SEC; }
+static grpc_millis millis_from_minutes(int64_t x) {
+ return x * 60 * GPR_MS_PER_SEC;
+}
+static grpc_millis millis_from_hours(int64_t x) {
+ return x * 3600 * GPR_MS_PER_SEC;
+}
+
void test_decoding(void) {
LOG_TEST("test_decoding");
- decode_suite('n', gpr_time_from_nanos);
- decode_suite('u', gpr_time_from_micros);
- decode_suite('m', gpr_time_from_millis);
- decode_suite('S', gpr_time_from_seconds);
- decode_suite('M', gpr_time_from_minutes);
- decode_suite('H', gpr_time_from_hours);
- assert_decodes_as("1000000000S",
- gpr_time_from_seconds(1000 * 1000 * 1000, GPR_TIMESPAN));
- assert_decodes_as("1000000000000000000000u", gpr_inf_future(GPR_TIMESPAN));
- assert_decodes_as("1000000001S", gpr_inf_future(GPR_TIMESPAN));
- assert_decodes_as("2000000001S", gpr_inf_future(GPR_TIMESPAN));
- assert_decodes_as("9999999999S", gpr_inf_future(GPR_TIMESPAN));
+ decode_suite('n', millis_from_nanos);
+ decode_suite('u', millis_from_micros);
+ decode_suite('m', millis_from_millis);
+ decode_suite('S', millis_from_seconds);
+ decode_suite('M', millis_from_minutes);
+ decode_suite('H', millis_from_hours);
+ assert_decodes_as("1000000000S", millis_from_seconds(1000 * 1000 * 1000));
+ assert_decodes_as("1000000000000000000000u", GRPC_MILLIS_INF_FUTURE);
+ assert_decodes_as("1000000001S", GRPC_MILLIS_INF_FUTURE);
+ assert_decodes_as("2000000001S", GRPC_MILLIS_INF_FUTURE);
+ assert_decodes_as("9999999999S", GRPC_MILLIS_INF_FUTURE);
}
static void assert_decoding_fails(const char *s) {
- gpr_timespec x;
+ grpc_millis x;
GPR_ASSERT(0 ==
grpc_http2_decode_timeout(grpc_slice_from_static_string(s), &x));
}
diff --git a/test/core/util/port_server_client.c b/test/core/util/port_server_client.c
index ba4028dbee..7b94ac4ada 100644
--- a/test/core/util/port_server_client.c
+++ b/test/core/util/port_server_client.c
@@ -88,7 +88,7 @@ void grpc_free_port_using_server(int port) {
grpc_resource_quota *resource_quota =
grpc_resource_quota_create("port_server_client/free");
grpc_httpcli_get(&exec_ctx, &context, &pr.pops, resource_quota, &req,
- grpc_timeout_seconds_to_deadline(30),
+ grpc_exec_ctx_now(&exec_ctx) + 30 * GPR_MS_PER_SEC,
GRPC_CLOSURE_CREATE(freed_port_from_server, &pr,
grpc_schedule_on_exec_ctx),
&rsp);
@@ -100,8 +100,8 @@ void grpc_free_port_using_server(int port) {
if (!GRPC_LOG_IF_ERROR(
"pollset_work",
grpc_pollset_work(&exec_ctx, grpc_polling_entity_pollset(&pr.pops),
- &worker, gpr_now(GPR_CLOCK_MONOTONIC),
- grpc_timeout_seconds_to_deadline(1)))) {
+ &worker,
+ grpc_exec_ctx_now(&exec_ctx) + GPR_MS_PER_SEC))) {
pr.done = 1;
}
}
@@ -173,7 +173,7 @@ static void got_port_from_server(grpc_exec_ctx *exec_ctx, void *arg,
grpc_resource_quota *resource_quota =
grpc_resource_quota_create("port_server_client/pick_retry");
grpc_httpcli_get(exec_ctx, pr->ctx, &pr->pops, resource_quota, &req,
- grpc_timeout_seconds_to_deadline(10),
+ grpc_exec_ctx_now(exec_ctx) + 30 * GPR_MS_PER_SEC,
GRPC_CLOSURE_CREATE(got_port_from_server, pr,
grpc_schedule_on_exec_ctx),
&pr->response);
@@ -224,7 +224,7 @@ int grpc_pick_port_using_server(void) {
grpc_resource_quota_create("port_server_client/pick");
grpc_httpcli_get(
&exec_ctx, &context, &pr.pops, resource_quota, &req,
- grpc_timeout_seconds_to_deadline(30),
+ grpc_exec_ctx_now(&exec_ctx) + 30 * GPR_MS_PER_SEC,
GRPC_CLOSURE_CREATE(got_port_from_server, &pr, grpc_schedule_on_exec_ctx),
&pr.response);
grpc_resource_quota_unref_internal(&exec_ctx, resource_quota);
@@ -235,8 +235,8 @@ int grpc_pick_port_using_server(void) {
if (!GRPC_LOG_IF_ERROR(
"pollset_work",
grpc_pollset_work(&exec_ctx, grpc_polling_entity_pollset(&pr.pops),
- &worker, gpr_now(GPR_CLOCK_MONOTONIC),
- grpc_timeout_seconds_to_deadline(1)))) {
+ &worker,
+ grpc_exec_ctx_now(&exec_ctx) + GPR_MS_PER_SEC))) {
pr.port = 0;
}
}
diff --git a/test/core/util/test_tcp_server.c b/test/core/util/test_tcp_server.c
index d3a1de8a3b..611ecb330c 100644
--- a/test/core/util/test_tcp_server.c
+++ b/test/core/util/test_tcp_server.c
@@ -31,6 +31,7 @@
#include "src/core/lib/iomgr/resolve_address.h"
#include "src/core/lib/iomgr/tcp_server.h"
#include "test/core/util/port.h"
+#include "test/core/util/test_config.h"
static void on_server_destroyed(grpc_exec_ctx *exec_ctx, void *data,
grpc_error *error) {
@@ -78,14 +79,13 @@ void test_tcp_server_start(test_tcp_server *server, int port) {
void test_tcp_server_poll(test_tcp_server *server, int seconds) {
grpc_pollset_worker *worker = NULL;
- gpr_timespec deadline =
- gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC),
- gpr_time_from_seconds(seconds, GPR_TIMESPAN));
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_millis deadline = grpc_timespec_to_millis_round_up(
+ grpc_timeout_seconds_to_deadline(seconds));
gpr_mu_lock(server->mu);
- GRPC_LOG_IF_ERROR("pollset_work",
- grpc_pollset_work(&exec_ctx, server->pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC), deadline));
+ GRPC_LOG_IF_ERROR(
+ "pollset_work",
+ grpc_pollset_work(&exec_ctx, server->pollset, &worker, deadline));
gpr_mu_unlock(server->mu);
grpc_exec_ctx_finish(&exec_ctx);
}