Skip to content
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

Conversation

voidzcy
Copy link
Contributor

@voidzcy voidzcy commented Mar 25, 2019

Use ScheduledExecutorService provided by FakeClock as the scheduler to run KeepAliveManager in KeepAliveManagerTest. Also modified how nextKeepaliveTime is managed in KeepAliveManager by using a Stopwatch. Solves #2868

@voidzcy voidzcy force-pushed the testfix/keep_alive_manager_test_with_fake_executor branch from e2c142e to 90f73a3 Compare March 25, 2019 23:16
Copy link
Member

@dapengzhang0 dapengzhang0 left a 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);
Copy link
Member

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);
Copy link
Member

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),
Copy link
Member

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();
Copy link
Member

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();

Copy link
Member

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);

Copy link
Member

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.

Copy link
Member

@dapengzhang0 dapengzhang0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@voidzcy voidzcy merged commit 9a2ef07 into grpc:master Apr 5, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jul 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants