remote: significantly speed up remote unit tests
Never actually sleep() during retries in tests.
//src/test/j/c/g/d/b/lib/remote:remote runtime improves from 59s to 7s.
Progress towards #7530.
fyi @werkt
Closes #7648.
PiperOrigin-RevId: 237195399
diff --git a/src/test/java/com/google/devtools/build/lib/remote/ByteStreamUploaderTest.java b/src/test/java/com/google/devtools/build/lib/remote/ByteStreamUploaderTest.java
index 76a426e..fb1a3c3 100644
--- a/src/test/java/com/google/devtools/build/lib/remote/ByteStreamUploaderTest.java
+++ b/src/test/java/com/google/devtools/build/lib/remote/ByteStreamUploaderTest.java
@@ -29,6 +29,7 @@
import com.google.common.util.concurrent.MoreExecutors;
import com.google.devtools.build.lib.analysis.BlazeVersionInfo;
import com.google.devtools.build.lib.remote.util.DigestUtil;
+import com.google.devtools.build.lib.remote.util.TestUtils;
import com.google.devtools.build.lib.remote.util.TracingMetadataUtils;
import com.google.devtools.build.lib.vfs.DigestHashFunction;
import com.google.protobuf.ByteString;
@@ -136,7 +137,7 @@
public void singleBlobUploadShouldWork() throws Exception {
Context prevContext = withEmptyMetadata.attach();
RemoteRetrier retrier =
- new RemoteRetrier(() -> mockBackoff, (e) -> true, retryService, Retrier.ALLOW_ALL_CALLS);
+ TestUtils.newRemoteRetrier(() -> mockBackoff, (e) -> true, retryService);
ByteStreamUploader uploader = new ByteStreamUploader(INSTANCE_NAME,
new ReferenceCountedChannel(channel), null, 3, retrier);
@@ -208,8 +209,7 @@
public void multipleBlobsUploadShouldWork() throws Exception {
Context prevContext = withEmptyMetadata.attach();
RemoteRetrier retrier =
- new RemoteRetrier(
- () -> new FixedBackoff(1, 0), (e) -> true, retryService, Retrier.ALLOW_ALL_CALLS);
+ TestUtils.newRemoteRetrier(() -> new FixedBackoff(1, 0), (e) -> true, retryService);
ByteStreamUploader uploader = new ByteStreamUploader(INSTANCE_NAME,
new ReferenceCountedChannel(channel), null, 3, retrier);
@@ -242,8 +242,7 @@
// We upload blobs with different context, and retry 3 times for each upload.
// We verify that the correct metadata is passed to the server with every blob.
RemoteRetrier retrier =
- new RemoteRetrier(
- () -> new FixedBackoff(5, 0), (e) -> true, retryService, Retrier.ALLOW_ALL_CALLS);
+ TestUtils.newRemoteRetrier(() -> new FixedBackoff(5, 0), (e) -> true, retryService);
ByteStreamUploader uploader = new ByteStreamUploader(INSTANCE_NAME,
new ReferenceCountedChannel(channel), null, 3, retrier);
@@ -336,7 +335,7 @@
Context prevContext = withEmptyMetadata.attach();
RemoteRetrier retrier =
- new RemoteRetrier(() -> mockBackoff, (e) -> true, retryService, Retrier.ALLOW_ALL_CALLS);
+ TestUtils.newRemoteRetrier(() -> mockBackoff, (e) -> true, retryService);
ByteStreamUploader uploader = new ByteStreamUploader(INSTANCE_NAME,
new ReferenceCountedChannel(channel), null, 3, retrier);
@@ -398,8 +397,7 @@
public void errorsShouldBeReported() throws IOException, InterruptedException {
Context prevContext = withEmptyMetadata.attach();
RemoteRetrier retrier =
- new RemoteRetrier(
- () -> new FixedBackoff(1, 10), (e) -> true, retryService, Retrier.ALLOW_ALL_CALLS);
+ TestUtils.newRemoteRetrier(() -> new FixedBackoff(1, 10), (e) -> true, retryService);
ByteStreamUploader uploader = new ByteStreamUploader(INSTANCE_NAME,
new ReferenceCountedChannel(channel), null, 3, retrier);
@@ -428,8 +426,7 @@
public void shutdownShouldCancelOngoingUploads() throws Exception {
Context prevContext = withEmptyMetadata.attach();
RemoteRetrier retrier =
- new RemoteRetrier(
- () -> new FixedBackoff(1, 10), (e) -> true, retryService, Retrier.ALLOW_ALL_CALLS);
+ TestUtils.newRemoteRetrier(() -> new FixedBackoff(1, 10), (e) -> true, retryService);
ByteStreamUploader uploader = new ByteStreamUploader(INSTANCE_NAME,
new ReferenceCountedChannel(channel), null, 3, retrier);
@@ -491,8 +488,7 @@
ListeningScheduledExecutorService retryService =
MoreExecutors.listeningDecorator(Executors.newScheduledThreadPool(1));
RemoteRetrier retrier =
- new RemoteRetrier(
- () -> new FixedBackoff(1, 10), (e) -> true, retryService, Retrier.ALLOW_ALL_CALLS);
+ TestUtils.newRemoteRetrier(() -> new FixedBackoff(1, 10), (e) -> true, retryService);
ByteStreamUploader uploader = new ByteStreamUploader(INSTANCE_NAME,
new ReferenceCountedChannel(channel), null, 3, retrier);
@@ -526,7 +522,7 @@
public void resourceNameWithoutInstanceName() throws Exception {
Context prevContext = withEmptyMetadata.attach();
RemoteRetrier retrier =
- new RemoteRetrier(() -> mockBackoff, (e) -> true, retryService, Retrier.ALLOW_ALL_CALLS);
+ TestUtils.newRemoteRetrier(() -> mockBackoff, (e) -> true, retryService);
ByteStreamUploader uploader =
new ByteStreamUploader(/* instanceName */ null,
new ReferenceCountedChannel(channel), null, 3, retrier);
@@ -567,11 +563,8 @@
public void nonRetryableStatusShouldNotBeRetried() throws Exception {
Context prevContext = withEmptyMetadata.attach();
RemoteRetrier retrier =
- new RemoteRetrier(
- () -> new FixedBackoff(1, 0),
- /* No Status is retriable. */ (e) -> false,
- retryService,
- Retrier.ALLOW_ALL_CALLS);
+ TestUtils.newRemoteRetrier(
+ () -> new FixedBackoff(1, 0), /* No Status is retriable. */ (e) -> false, retryService);
ByteStreamUploader uploader =
new ByteStreamUploader(/* instanceName */ null,
new ReferenceCountedChannel(channel), null, 3, retrier);
@@ -604,8 +597,7 @@
public void failedUploadsShouldNotDeduplicate() throws Exception {
Context prevContext = withEmptyMetadata.attach();
RemoteRetrier retrier =
- new RemoteRetrier(
- () -> Retrier.RETRIES_DISABLED, (e) -> false, retryService, Retrier.ALLOW_ALL_CALLS);
+ TestUtils.newRemoteRetrier(() -> Retrier.RETRIES_DISABLED, (e) -> false, retryService);
ByteStreamUploader uploader =
new ByteStreamUploader(
INSTANCE_NAME, new ReferenceCountedChannel(channel), null, 3, retrier);
@@ -681,7 +673,7 @@
public void deduplicationOfUploadsShouldWork() throws Exception {
Context prevContext = withEmptyMetadata.attach();
RemoteRetrier retrier =
- new RemoteRetrier(() -> mockBackoff, (e) -> true, retryService, Retrier.ALLOW_ALL_CALLS);
+ TestUtils.newRemoteRetrier(() -> mockBackoff, (e) -> true, retryService);
ByteStreamUploader uploader = new ByteStreamUploader(INSTANCE_NAME,
new ReferenceCountedChannel(channel), null, 3, retrier);