Skip to content

Conversation

@creamsoup
Copy link
Contributor

Implementation is skipping flush task if another flush is queued.

Resolves #3258

Copy link
Member

@ejona86 ejona86 left a comment

Choose a reason for hiding this comment

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

Note that checkstyle is failing in the CIs.

@Before
public void setUp() throws Exception {
queueingExecutor = new QueueingExecutor();
asyncFrameWriter = spy(new AsyncFrameWriter(transport, new SerializingExecutor(queueingExecutor)));
Copy link
Member

Choose a reason for hiding this comment

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

Please, please no spies. They are so very magical, I don't trust tests with them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

spy is gone!

queueingExecutor.runAll();

verify(frameWriter, times(1)).ping(anyBoolean(), anyInt(), anyInt());
verify(asyncFrameWriter, times(1)).flush();
Copy link
Member

Choose a reason for hiding this comment

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

What is the point of this verification, here and elsewhere? Isn't this test the thing that called this method, on line 56?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

right. removed unnecessary verify.


private static abstract class PartiallyTrackingFrameWriter implements FrameWriter {

private static final List<Method> methods = new ArrayList<Method>();
Copy link
Member

Choose a reason for hiding this comment

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

This is just asking for trouble, as one test can influence another. Actually... how is flushCoalescing_shouldMergeTwoQueuedFlushes working? Nothing is clearing out these methods.

Implementation is skipping flush task if another flush is queued.
@@ -0,0 +1,151 @@
/*
* Copyright 2015 The gRPC Authors
Copy link
Contributor

Choose a reason for hiding this comment

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

2018

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks!


verify(frameWriter, times(2)).ping(anyBoolean(), anyInt(), anyInt());
verify(frameWriter, times(1)).flush();
assertThat(Iterables.getLast(PartiallyTrackingFrameWriter.getAllInvokedMethodsHistory()))
Copy link
Member

Choose a reason for hiding this comment

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

Why not use inOrder?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

didn't know that exists. thanks!

Copy link
Contributor

@carl-mastrangelo carl-mastrangelo left a comment

Choose a reason for hiding this comment

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

One nit but LGTM

}

/**
* Executor queues incoming runnables instead of running it. Runnables can be invoked via {@code
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be #link

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.


@Before
public void setUp() throws Exception {
queueingExecutor = new QueueingExecutor();
Copy link
Member

Choose a reason for hiding this comment

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

nit: Initialize at the declaration above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.


@After
public void tearDown() throws Exception {
asyncFrameWriter.close();
Copy link
Member

Choose a reason for hiding this comment

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

What's the point of this? It is guaranteed to do nothing. If we wanted to close the (mock) socket there would need to be a runAll() here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

@RunWith(MockitoJUnitRunner.class)
public class AsyncFrameWriterTest {

@Mock private OkHttpClientTransport transport;
Copy link
Member

Choose a reason for hiding this comment

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

Mocking a functional class like the transport is worrisome to me. Only a single method is used, could we make an interface for it and have the transport implement that interface?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, created an interface TransportExceptionHandler, can you review this part?


@After
public void tearDown() throws Exception {
queueingExecutor.clear();
Copy link
Member

Choose a reason for hiding this comment

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

This does nothing, as this test class instance will be thrown away. So you're clearing something before it is cleared by the GC.


@Override
public void onException(Throwable throwable) {
throw Status.INTERNAL.asRuntimeException();
Copy link
Member

Choose a reason for hiding this comment

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

This throws away the Throwable, and we don't use StatusRuntimeException too much like this. How about just new AssertionError(throwable)?

@Before
public void setUp() throws Exception {
asyncFrameWriter =
new AsyncFrameWriter(transportExceptionHandler, new SerializingExecutor(queueingExecutor));
Copy link
Member

Choose a reason for hiding this comment

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

nit: this could also be moved up to the declaration, now that the transport isn't a mock.

Copy link
Member

@ejona86 ejona86 left a comment

Choose a reason for hiding this comment

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

Looks good. Make sure to squash when merging.

@creamsoup creamsoup merged commit 30a4bfb into grpc:master Aug 17, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Nov 15, 2018
@creamsoup creamsoup deleted the nameresolver branch May 2, 2019 17:31
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.

3 participants