diff options
author | Yash Tibrewal <yashkt@google.com> | 2017-11-14 18:11:22 -0800 |
---|---|---|
committer | Yash Tibrewal <yashkt@google.com> | 2017-11-14 18:11:22 -0800 |
commit | 6c26b16fe06b1cc75b4dac372f4f51f6b7d1bfc0 (patch) | |
tree | 5d9b7bbdcf125bfc103b67778349ea075b049bb4 /test/core/backoff/backoff_test.cc | |
parent | 75122c23578e24417dcf64081c737571a9fc2dbc (diff) |
Move ExecCtx to grpc_core namespace. Make exec_ctx a private static in ExecCtx and some minor changes
Diffstat (limited to 'test/core/backoff/backoff_test.cc')
-rw-r--r-- | test/core/backoff/backoff_test.cc | 60 |
1 files changed, 33 insertions, 27 deletions
diff --git a/test/core/backoff/backoff_test.cc b/test/core/backoff/backoff_test.cc index 739ab86bb2..76a9f39c35 100644 --- a/test/core/backoff/backoff_test.cc +++ b/test/core/backoff/backoff_test.cc @@ -32,19 +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); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_backoff_result next_deadlines = grpc_backoff_begin(&backoff); - GPR_ASSERT(next_deadlines.current_deadline - ExecCtx::Get()->Now() == + GPR_ASSERT(next_deadlines.current_deadline - + grpc_core::ExecCtx::Get()->Now() == initial_backoff); - GPR_ASSERT(next_deadlines.next_attempt_start_time - ExecCtx::Get()->Now() == + GPR_ASSERT(next_deadlines.next_attempt_start_time - + grpc_core::ExecCtx::Get()->Now() == initial_backoff); for (int i = 0; i < 10000; i++) { next_deadlines = grpc_backoff_step(&backoff); - GPR_ASSERT(next_deadlines.current_deadline - ExecCtx::Get()->Now() == + GPR_ASSERT(next_deadlines.current_deadline - + grpc_core::ExecCtx::Get()->Now() == initial_backoff); - GPR_ASSERT(next_deadlines.next_attempt_start_time - ExecCtx::Get()->Now() == + GPR_ASSERT(next_deadlines.next_attempt_start_time - + grpc_core::ExecCtx::Get()->Now() == initial_backoff); - ExecCtx::Get()->SetNow(next_deadlines.current_deadline); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); } } @@ -57,15 +61,15 @@ 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); - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_backoff_result next = grpc_backoff_begin(&backoff); // Because the min_connect_timeout > initial_backoff, current_deadline is used // as the deadline for the current attempt. - GPR_ASSERT(next.current_deadline - ExecCtx::Get()->Now() == + GPR_ASSERT(next.current_deadline - grpc_core::ExecCtx::Get()->Now() == min_connect_timeout); // ... while, if the current attempt fails, the next one will happen after // initial_backoff. - GPR_ASSERT(next.next_attempt_start_time - ExecCtx::Get()->Now() == + GPR_ASSERT(next.next_attempt_start_time - grpc_core::ExecCtx::Get()->Now() == initial_backoff); } @@ -80,45 +84,45 @@ 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 ) - ExecCtx _local_exec_ctx; - ExecCtx::Get()->SetNow(0); + grpc_core::ExecCtx _local_exec_ctx; + grpc_core::ExecCtx::Get()->TestOnlySetNow(0); grpc_backoff_result next_deadlines = grpc_backoff_begin(&backoff); GPR_ASSERT(next_deadlines.current_deadline == next_deadlines.next_attempt_start_time); GPR_ASSERT(next_deadlines.current_deadline == 2); - ExecCtx::Get()->SetNow(next_deadlines.current_deadline); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 6); - ExecCtx::Get()->SetNow(next_deadlines.current_deadline); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 14); - ExecCtx::Get()->SetNow(next_deadlines.current_deadline); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 30); - ExecCtx::Get()->SetNow(next_deadlines.current_deadline); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 62); - ExecCtx::Get()->SetNow(next_deadlines.current_deadline); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 126); - ExecCtx::Get()->SetNow(next_deadlines.current_deadline); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 254); - ExecCtx::Get()->SetNow(next_deadlines.current_deadline); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 510); - ExecCtx::Get()->SetNow(next_deadlines.current_deadline); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 1022); - ExecCtx::Get()->SetNow(next_deadlines.current_deadline); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); next_deadlines = grpc_backoff_step(&backoff); // Hit the maximum timeout. From this point onwards, retries will increase // only by max timeout. GPR_ASSERT(next_deadlines.current_deadline == 1535); - ExecCtx::Get()->SetNow(next_deadlines.current_deadline); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 2048); - ExecCtx::Get()->SetNow(next_deadlines.current_deadline); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 2561); } @@ -136,11 +140,13 @@ static void test_jitter_backoff(void) { backoff.rng_state = 0; // force consistent PRNG - ExecCtx _local_exec_ctx; + grpc_core::ExecCtx _local_exec_ctx; grpc_backoff_result next_deadlines = grpc_backoff_begin(&backoff); - GPR_ASSERT(next_deadlines.current_deadline - ExecCtx::Get()->Now() == + GPR_ASSERT(next_deadlines.current_deadline - + grpc_core::ExecCtx::Get()->Now() == initial_backoff); - GPR_ASSERT(next_deadlines.next_attempt_start_time - ExecCtx::Get()->Now() == + GPR_ASSERT(next_deadlines.next_attempt_start_time - + grpc_core::ExecCtx::Get()->Now() == initial_backoff); grpc_millis expected_next_lower_bound = @@ -153,7 +159,7 @@ static void test_jitter_backoff(void) { // 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 - ExecCtx::Get()->Now(); + next_deadlines.current_deadline - grpc_core::ExecCtx::Get()->Now(); GPR_ASSERT(timeout_millis >= expected_next_lower_bound); GPR_ASSERT(timeout_millis <= expected_next_upper_bound); current_backoff = GPR_MIN( @@ -162,7 +168,7 @@ static void test_jitter_backoff(void) { (grpc_millis)((double)current_backoff * (1 - jitter)); expected_next_upper_bound = (grpc_millis)((double)current_backoff * (1 + jitter)); - ExecCtx::Get()->SetNow(next_deadlines.current_deadline); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); } } |