diff options
author | Yash Tibrewal <yashkt@google.com> | 2017-12-06 09:05:05 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-06 09:05:05 -0800 |
commit | ad4d2dde0052efbbf49d64b0843c45f0381cfeb3 (patch) | |
tree | 6a657f8c6179d873b34505cdc24bce9462ca68eb /test/core/backoff | |
parent | a3df36cc2505a89c2f481eea4a66a87b3002844a (diff) |
Revert "All instances of exec_ctx being passed around in src/core removed"
Diffstat (limited to 'test/core/backoff')
-rw-r--r-- | test/core/backoff/backoff_test.cc | 99 |
1 files changed, 49 insertions, 50 deletions
diff --git a/test/core/backoff/backoff_test.cc b/test/core/backoff/backoff_test.cc index d3115fe1dd..ef2de8d638 100644 --- a/test/core/backoff/backoff_test.cc +++ b/test/core/backoff/backoff_test.cc @@ -18,7 +18,6 @@ #include "src/core/lib/backoff/backoff.h" -#include <grpc/grpc.h> #include <grpc/support/log.h> #include <grpc/support/useful.h> @@ -33,24 +32,23 @@ static void test_constant_backoff(void) { const grpc_millis max_backoff = 1000; grpc_backoff_init(&backoff, initial_backoff, multiplier, jitter, min_connect_timeout, max_backoff); - grpc_core::ExecCtx exec_ctx; - grpc_backoff_result next_deadlines = grpc_backoff_begin(&backoff); - GPR_ASSERT(next_deadlines.current_deadline - - grpc_core::ExecCtx::Get()->Now() == + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_backoff_result next_deadlines = grpc_backoff_begin(&exec_ctx, &backoff); + GPR_ASSERT(next_deadlines.current_deadline - grpc_exec_ctx_now(&exec_ctx) == initial_backoff); GPR_ASSERT(next_deadlines.next_attempt_start_time - - grpc_core::ExecCtx::Get()->Now() == + grpc_exec_ctx_now(&exec_ctx) == initial_backoff); for (int i = 0; i < 10000; i++) { - next_deadlines = grpc_backoff_step(&backoff); - GPR_ASSERT(next_deadlines.current_deadline - - grpc_core::ExecCtx::Get()->Now() == + next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); + GPR_ASSERT(next_deadlines.current_deadline - grpc_exec_ctx_now(&exec_ctx) == initial_backoff); GPR_ASSERT(next_deadlines.next_attempt_start_time - - grpc_core::ExecCtx::Get()->Now() == + grpc_exec_ctx_now(&exec_ctx) == initial_backoff); - grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); + exec_ctx.now = next_deadlines.current_deadline; } + grpc_exec_ctx_finish(&exec_ctx); } static void test_min_connect(void) { @@ -62,16 +60,17 @@ static void test_min_connect(void) { const grpc_millis max_backoff = 1000; grpc_backoff_init(&backoff, initial_backoff, multiplier, jitter, min_connect_timeout, max_backoff); - grpc_core::ExecCtx exec_ctx; - grpc_backoff_result next = grpc_backoff_begin(&backoff); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_backoff_result next = grpc_backoff_begin(&exec_ctx, &backoff); // Because the min_connect_timeout > initial_backoff, current_deadline is used // as the deadline for the current attempt. - GPR_ASSERT(next.current_deadline - grpc_core::ExecCtx::Get()->Now() == + GPR_ASSERT(next.current_deadline - grpc_exec_ctx_now(&exec_ctx) == min_connect_timeout); // ... while, if the current attempt fails, the next one will happen after // initial_backoff. - GPR_ASSERT(next.next_attempt_start_time - grpc_core::ExecCtx::Get()->Now() == + GPR_ASSERT(next.next_attempt_start_time - grpc_exec_ctx_now(&exec_ctx) == initial_backoff); + grpc_exec_ctx_finish(&exec_ctx); } static void test_no_jitter_backoff(void) { @@ -85,47 +84,49 @@ static void test_no_jitter_backoff(void) { min_connect_timeout, max_backoff); // x_1 = 2 // x_n = 2**i + x_{i-1} ( = 2**(n+1) - 2 ) - grpc_core::ExecCtx exec_ctx; - grpc_core::ExecCtx::Get()->TestOnlySetNow(0); - grpc_backoff_result next_deadlines = grpc_backoff_begin(&backoff); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + exec_ctx.now = 0; + exec_ctx.now_is_valid = true; + grpc_backoff_result next_deadlines = grpc_backoff_begin(&exec_ctx, &backoff); GPR_ASSERT(next_deadlines.current_deadline == next_deadlines.next_attempt_start_time); GPR_ASSERT(next_deadlines.current_deadline == 2); - grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); - next_deadlines = grpc_backoff_step(&backoff); + exec_ctx.now = next_deadlines.current_deadline; + next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); GPR_ASSERT(next_deadlines.current_deadline == 6); - grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); - next_deadlines = grpc_backoff_step(&backoff); + exec_ctx.now = next_deadlines.current_deadline; + next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); GPR_ASSERT(next_deadlines.current_deadline == 14); - grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); - next_deadlines = grpc_backoff_step(&backoff); + exec_ctx.now = next_deadlines.current_deadline; + next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); GPR_ASSERT(next_deadlines.current_deadline == 30); - grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); - next_deadlines = grpc_backoff_step(&backoff); + exec_ctx.now = next_deadlines.current_deadline; + next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); GPR_ASSERT(next_deadlines.current_deadline == 62); - grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); - next_deadlines = grpc_backoff_step(&backoff); + exec_ctx.now = next_deadlines.current_deadline; + next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); GPR_ASSERT(next_deadlines.current_deadline == 126); - grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); - next_deadlines = grpc_backoff_step(&backoff); + exec_ctx.now = next_deadlines.current_deadline; + next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); GPR_ASSERT(next_deadlines.current_deadline == 254); - grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); - next_deadlines = grpc_backoff_step(&backoff); + exec_ctx.now = next_deadlines.current_deadline; + next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); GPR_ASSERT(next_deadlines.current_deadline == 510); - grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); - next_deadlines = grpc_backoff_step(&backoff); + exec_ctx.now = next_deadlines.current_deadline; + next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); GPR_ASSERT(next_deadlines.current_deadline == 1022); - grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); - next_deadlines = grpc_backoff_step(&backoff); + exec_ctx.now = next_deadlines.current_deadline; + next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); // Hit the maximum timeout. From this point onwards, retries will increase // only by max timeout. GPR_ASSERT(next_deadlines.current_deadline == 1535); - grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); - next_deadlines = grpc_backoff_step(&backoff); + exec_ctx.now = next_deadlines.current_deadline; + next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); GPR_ASSERT(next_deadlines.current_deadline == 2048); - grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); - next_deadlines = grpc_backoff_step(&backoff); + exec_ctx.now = next_deadlines.current_deadline; + next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); GPR_ASSERT(next_deadlines.current_deadline == 2561); + grpc_exec_ctx_finish(&exec_ctx); } static void test_jitter_backoff(void) { @@ -141,13 +142,12 @@ static void test_jitter_backoff(void) { backoff.rng_state = 0; // force consistent PRNG - grpc_core::ExecCtx exec_ctx; - grpc_backoff_result next_deadlines = grpc_backoff_begin(&backoff); - GPR_ASSERT(next_deadlines.current_deadline - - grpc_core::ExecCtx::Get()->Now() == + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_backoff_result next_deadlines = grpc_backoff_begin(&exec_ctx, &backoff); + GPR_ASSERT(next_deadlines.current_deadline - grpc_exec_ctx_now(&exec_ctx) == initial_backoff); GPR_ASSERT(next_deadlines.next_attempt_start_time - - grpc_core::ExecCtx::Get()->Now() == + grpc_exec_ctx_now(&exec_ctx) == initial_backoff); grpc_millis expected_next_lower_bound = @@ -156,11 +156,11 @@ static void test_jitter_backoff(void) { (grpc_millis)((double)current_backoff * (1 + jitter)); for (int i = 0; i < 10000; i++) { - next_deadlines = grpc_backoff_step(&backoff); + next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); // next-now must be within (jitter*100)% of the current backoff (which // increases by * multiplier up to max_backoff). const grpc_millis timeout_millis = - next_deadlines.current_deadline - grpc_core::ExecCtx::Get()->Now(); + next_deadlines.current_deadline - grpc_exec_ctx_now(&exec_ctx); GPR_ASSERT(timeout_millis >= expected_next_lower_bound); GPR_ASSERT(timeout_millis <= expected_next_upper_bound); current_backoff = GPR_MIN( @@ -169,13 +169,13 @@ static void test_jitter_backoff(void) { (grpc_millis)((double)current_backoff * (1 - jitter)); expected_next_upper_bound = (grpc_millis)((double)current_backoff * (1 + jitter)); - grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); + exec_ctx.now = next_deadlines.current_deadline; } + grpc_exec_ctx_finish(&exec_ctx); } int main(int argc, char** argv) { grpc_test_init(argc, argv); - grpc_init(); gpr_time_init(); test_constant_backoff(); @@ -183,6 +183,5 @@ int main(int argc, char** argv) { test_no_jitter_backoff(); test_jitter_backoff(); - grpc_shutdown(); return 0; } |