-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
core: use FakeClock.ScheduledExecutorService for KeepAliveManagerTest #5501
core: use FakeClock.ScheduledExecutorService for KeepAliveManagerTest #5501
Conversation
e2c142e
to
90f73a3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally looks good to me. Some nitpicks.
} | ||
|
||
@Test | ||
public void sendKeepAlivePings() { | ||
ticker.time = 1; | ||
fakeClock.forwardNanos(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assertThat(fakeClock.getPendingTasks()).isEmpty()
before, and assertThat(fakeClock.getPendingTasks()).hasSize(1)
after. You could also use fakeClock.numPendingTasks()
.
verify(scheduler, times(2)).schedule(isA(Runnable.class), delayCaptor.capture(), | ||
isA(TimeUnit.class)); | ||
delay = delayCaptor.getValue(); | ||
ScheduledFuture<?> shutdownFuture = Iterables.getFirst(fakeClock.getPendingTasks(), null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assertThat(fakeClock.getPendingTasks()).hasSize(1)
first
// Transport becomes active. We should schedule keepalive pings. | ||
keepAliveManager.onTransportActive(); | ||
ArgumentCaptor<Runnable> sendPingCaptor = ArgumentCaptor.forClass(Runnable.class); | ||
verify(scheduler, times(1)).schedule(sendPingCaptor.capture(), isA(Long.class), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assert number of pendingTasks change.
|
||
// We receive some data. We may need to delay the ping. | ||
ticker.time = 1500; | ||
fakeClock.forwardNanos(990); | ||
keepAliveManager.onDataReceived(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assert number of pendingTasks unchanged.
verify(transport, times(0)).ping(isA(ClientTransport.PingCallback.class), | ||
isA(Executor.class)); | ||
verify(keepAlivePinger, never()).ping(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assert number of pendingTasks unchanged.
ticker.time = 1000; | ||
sendPing.run(); | ||
fakeClock.forwardNanos(1000); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also assert number of pending tasks changes. The same for the other tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Use
ScheduledExecutorService
provided byFakeClock
as the scheduler to runKeepAliveManager
inKeepAliveManagerTest
. Also modified hownextKeepaliveTime
is managed inKeepAliveManager
by using a Stopwatch. Solves #2868