|
|
@ -140,21 +140,27 @@ TEST_F(TimerTest, CancelSomeTimers) { |
|
|
|
grpc_core::ExecCtx exec_ctx; |
|
|
|
grpc_core::ExecCtx exec_ctx; |
|
|
|
const int kNumTimers = 10; |
|
|
|
const int kNumTimers = 10; |
|
|
|
grpc_timer timers[kNumTimers]; |
|
|
|
grpc_timer timers[kNumTimers]; |
|
|
|
int timer_fired = 0; |
|
|
|
std::atomic<int> timer_fired{0}; |
|
|
|
|
|
|
|
grpc_core::ExecCtx::Get()->InvalidateNow(); |
|
|
|
for (int i = 0; i < kNumTimers; ++i) { |
|
|
|
for (int i = 0; i < kNumTimers; ++i) { |
|
|
|
grpc_timer_init(&timers[i], |
|
|
|
// Set a large firing time for timers which are bound to be cancelled
|
|
|
|
grpc_core::ExecCtx::Get()->Now() + |
|
|
|
// and set a small firing time for timers which need to execute.
|
|
|
|
grpc_core::Duration::Milliseconds(500) + |
|
|
|
grpc_timer_init( |
|
|
|
grpc_core::Duration::Milliseconds(i), |
|
|
|
&timers[i], |
|
|
|
GRPC_CLOSURE_CREATE( |
|
|
|
grpc_core::ExecCtx::Get()->Now() + |
|
|
|
[](void* arg, grpc_error_handle error) { |
|
|
|
((i < kNumTimers / 2) ? grpc_core ::Duration::Milliseconds(60000) |
|
|
|
if (error == GRPC_ERROR_CANCELLED) { |
|
|
|
: grpc_core ::Duration::Milliseconds(100) + |
|
|
|
return; |
|
|
|
grpc_core::Duration::Milliseconds(i)), |
|
|
|
} |
|
|
|
GRPC_CLOSURE_CREATE( |
|
|
|
int* timer_fired = static_cast<int*>(arg); |
|
|
|
[](void* arg, grpc_error_handle error) { |
|
|
|
++*timer_fired; |
|
|
|
if (error == GRPC_ERROR_CANCELLED) { |
|
|
|
}, |
|
|
|
return; |
|
|
|
&timer_fired, grpc_schedule_on_exec_ctx)); |
|
|
|
} |
|
|
|
|
|
|
|
std::atomic<int>* timer_fired = |
|
|
|
|
|
|
|
static_cast<std::atomic<int>*>(arg); |
|
|
|
|
|
|
|
++*timer_fired; |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
&timer_fired, grpc_schedule_on_exec_ctx)); |
|
|
|
} |
|
|
|
} |
|
|
|
for (int i = 0; i < kNumTimers / 2; ++i) { |
|
|
|
for (int i = 0; i < kNumTimers / 2; ++i) { |
|
|
|
grpc_timer_cancel(&timers[i]); |
|
|
|
grpc_timer_cancel(&timers[i]); |
|
|
|