Skip to content

Commit

Permalink
Use a realistic Executor in BinderServerTransportTest (#10979)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdcormie committed Mar 5, 2024
1 parent 85e52cd commit d894c83
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
8 changes: 8 additions & 0 deletions binder/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ android {
withJavadocJar()
}
}
testFixtures { enable true }
}

repositories {
Expand Down Expand Up @@ -70,6 +71,8 @@ dependencies {
androidTestImplementation libraries.androidx.lifecycle.service
androidTestImplementation libraries.guava.testlib
androidTestImplementation testFixtures(project(':grpc-core'))

testFixturesImplementation libraries.guava.testlib
}

import net.ltgt.gradle.errorprone.CheckSeverity
Expand Down Expand Up @@ -123,3 +126,8 @@ publishing {
}
}
}

afterEvaluate {
components.release.withVariantsFromConfiguration(configurations.releaseTestFixturesVariantReleaseApiPublication) { skip() }
components.release.withVariantsFromConfiguration(configurations.releaseTestFixturesVariantReleaseRuntimePublication) { skip() }
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static com.google.common.util.concurrent.MoreExecutors.directExecutor;
import static org.robolectric.Shadows.shadowOf;

import io.grpc.binder.internal.MainThreadScheduledExecutorService;
import android.app.Application;
import android.content.ComponentName;
import android.content.Intent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.when;
import static org.robolectric.Shadows.shadowOf;
import static org.robolectric.annotation.LooperMode.Mode.PAUSED;

import android.os.IBinder;
import android.os.Looper;
import android.os.Parcel;
import com.google.common.collect.ImmutableList;
import com.google.common.util.concurrent.testing.TestingExecutors;
import io.grpc.Attributes;
import io.grpc.Metadata;
import io.grpc.Status;
import io.grpc.binder.internal.MainThreadScheduledExecutorService;
import io.grpc.internal.FixedObjectPool;
import io.grpc.internal.ServerStream;
import io.grpc.internal.ServerTransportListener;
Expand All @@ -56,8 +58,7 @@ public final class BinderServerTransportTest {

@Rule public MockitoRule mocks = MockitoJUnit.rule();

private final ScheduledExecutorService executorService =
TestingExecutors.sameThreadScheduledExecutor();
private final ScheduledExecutorService executorService = new MainThreadScheduledExecutorService();
private final TestTransportListener transportListener = new TestTransportListener();

@Mock IBinder mockBinder;
Expand All @@ -83,6 +84,7 @@ public void testSetupTransactionFailureCausesMultipleShutdowns_b153460678() thro

// Now shut it down.
transport.shutdownNow(Status.UNKNOWN.withDescription("reasons"));
shadowOf(Looper.getMainLooper()).idle();

assertThat(transportListener.terminated).isTrue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package io.grpc.binder;
package io.grpc.binder.internal;

import android.os.Handler;
import android.os.Looper;
Expand All @@ -37,7 +37,7 @@
*
* <p>Use {@link org.robolectric.shadows.ShadowLooper#idle()} to run queued work.
*/
class MainThreadScheduledExecutorService extends AbstractExecutorService
public class MainThreadScheduledExecutorService extends AbstractExecutorService
implements ScheduledExecutorService {

private final Handler handler = new Handler(Looper.getMainLooper());
Expand Down

0 comments on commit d894c83

Please sign in to comment.