Fix to cancellations shutdown logic following regression in https://github.com/bazelbuild/bazel/commit/f54de41c15f1b7a9b0a902d31f1cce9cf7722cd4.
Also updated unit tests to use a default timeout of 60 seconds, so that such bugs get uncovered by the unit tests in the future.
TESTED=updated unit tests
PiperOrigin-RevId: 246124525
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 d744876..19b0e44 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
@@ -141,8 +141,13 @@
Context prevContext = withEmptyMetadata.attach();
RemoteRetrier retrier =
TestUtils.newRemoteRetrier(() -> mockBackoff, (e) -> true, retryService);
- ByteStreamUploader uploader = new ByteStreamUploader(INSTANCE_NAME,
- new ReferenceCountedChannel(channel), null, 3, retrier);
+ ByteStreamUploader uploader =
+ new ByteStreamUploader(
+ INSTANCE_NAME,
+ new ReferenceCountedChannel(channel),
+ null, /* timeout seconds */
+ 60,
+ retrier);
byte[] blob = new byte[CHUNK_SIZE * 2 + 1];
new Random().nextBytes(blob);
@@ -213,8 +218,13 @@
Context prevContext = withEmptyMetadata.attach();
RemoteRetrier retrier =
TestUtils.newRemoteRetrier(() -> new FixedBackoff(1, 0), (e) -> true, retryService);
- ByteStreamUploader uploader = new ByteStreamUploader(INSTANCE_NAME,
- new ReferenceCountedChannel(channel), null, 3, retrier);
+ ByteStreamUploader uploader =
+ new ByteStreamUploader(
+ INSTANCE_NAME,
+ new ReferenceCountedChannel(channel),
+ null, /* timeout seconds */
+ 60,
+ retrier);
int numUploads = 10;
Map<String, byte[]> blobsByHash = new HashMap<>();
@@ -246,8 +256,13 @@
// We verify that the correct metadata is passed to the server with every blob.
RemoteRetrier retrier =
TestUtils.newRemoteRetrier(() -> new FixedBackoff(5, 0), (e) -> true, retryService);
- ByteStreamUploader uploader = new ByteStreamUploader(INSTANCE_NAME,
- new ReferenceCountedChannel(channel), null, 3, retrier);
+ ByteStreamUploader uploader =
+ new ByteStreamUploader(
+ INSTANCE_NAME,
+ new ReferenceCountedChannel(channel),
+ null, /* timeout seconds */
+ 60,
+ retrier);
List<String> toUpload = ImmutableList.of("aaaaaaaaaa", "bbbbbbbbbb", "cccccccccc");
List<Chunker> builders = new ArrayList<>(toUpload.size());
@@ -339,8 +354,13 @@
Context prevContext = withEmptyMetadata.attach();
RemoteRetrier retrier =
TestUtils.newRemoteRetrier(() -> mockBackoff, (e) -> true, retryService);
- ByteStreamUploader uploader = new ByteStreamUploader(INSTANCE_NAME,
- new ReferenceCountedChannel(channel), null, 3, retrier);
+ ByteStreamUploader uploader =
+ new ByteStreamUploader(
+ INSTANCE_NAME,
+ new ReferenceCountedChannel(channel),
+ null, /* timeout seconds */
+ 60,
+ retrier);
byte[] blob = new byte[CHUNK_SIZE * 10];
Chunker chunker = Chunker.builder(DIGEST_UTIL).setInput(blob).setChunkSize(CHUNK_SIZE).build();
@@ -401,8 +421,13 @@
Context prevContext = withEmptyMetadata.attach();
RemoteRetrier retrier =
TestUtils.newRemoteRetrier(() -> new FixedBackoff(1, 10), (e) -> true, retryService);
- ByteStreamUploader uploader = new ByteStreamUploader(INSTANCE_NAME,
- new ReferenceCountedChannel(channel), null, 3, retrier);
+ ByteStreamUploader uploader =
+ new ByteStreamUploader(
+ INSTANCE_NAME,
+ new ReferenceCountedChannel(channel),
+ null, /* timeout seconds */
+ 60,
+ retrier);
byte[] blob = new byte[CHUNK_SIZE];
Chunker chunker = Chunker.builder(DIGEST_UTIL).setInput(blob).setChunkSize(CHUNK_SIZE).build();
@@ -426,8 +451,13 @@
Context prevContext = withEmptyMetadata.attach();
RemoteRetrier retrier =
TestUtils.newRemoteRetrier(() -> new FixedBackoff(1, 10), (e) -> true, retryService);
- ByteStreamUploader uploader = new ByteStreamUploader(INSTANCE_NAME,
- new ReferenceCountedChannel(channel), null, 3, retrier);
+ ByteStreamUploader uploader =
+ new ByteStreamUploader(
+ INSTANCE_NAME,
+ new ReferenceCountedChannel(channel),
+ null, /* timeout seconds */
+ 60,
+ retrier);
CountDownLatch cancellations = new CountDownLatch(2);
@@ -488,8 +518,13 @@
MoreExecutors.listeningDecorator(Executors.newScheduledThreadPool(1));
RemoteRetrier retrier =
TestUtils.newRemoteRetrier(() -> new FixedBackoff(1, 10), (e) -> true, retryService);
- ByteStreamUploader uploader = new ByteStreamUploader(INSTANCE_NAME,
- new ReferenceCountedChannel(channel), null, 3, retrier);
+ ByteStreamUploader uploader =
+ new ByteStreamUploader(
+ INSTANCE_NAME,
+ new ReferenceCountedChannel(channel),
+ null, /* timeout seconds */
+ 60,
+ retrier);
serviceRegistry.addService(new ByteStreamImplBase() {
@Override
@@ -519,8 +554,12 @@
RemoteRetrier retrier =
TestUtils.newRemoteRetrier(() -> mockBackoff, (e) -> true, retryService);
ByteStreamUploader uploader =
- new ByteStreamUploader(/* instanceName */ null,
- new ReferenceCountedChannel(channel), null, 3, retrier);
+ new ByteStreamUploader(
+ /* instanceName */ null,
+ new ReferenceCountedChannel(channel),
+ null, /* timeout seconds */
+ 60,
+ retrier);
serviceRegistry.addService(new ByteStreamImplBase() {
@Override
@@ -561,8 +600,12 @@
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);
+ new ByteStreamUploader(
+ /* instanceName */ null,
+ new ReferenceCountedChannel(channel),
+ null, /* timeout seconds */
+ 60,
+ retrier);
AtomicInteger numCalls = new AtomicInteger();
@@ -591,7 +634,11 @@
TestUtils.newRemoteRetrier(() -> Retrier.RETRIES_DISABLED, (e) -> false, retryService);
ByteStreamUploader uploader =
new ByteStreamUploader(
- INSTANCE_NAME, new ReferenceCountedChannel(channel), null, 3, retrier);
+ INSTANCE_NAME,
+ new ReferenceCountedChannel(channel),
+ null, /* timeout seconds */
+ 60,
+ retrier);
byte[] blob = new byte[CHUNK_SIZE * 2 + 1];
new Random().nextBytes(blob);
@@ -665,8 +712,13 @@
Context prevContext = withEmptyMetadata.attach();
RemoteRetrier retrier =
TestUtils.newRemoteRetrier(() -> mockBackoff, (e) -> true, retryService);
- ByteStreamUploader uploader = new ByteStreamUploader(INSTANCE_NAME,
- new ReferenceCountedChannel(channel), null, 3, retrier);
+ ByteStreamUploader uploader =
+ new ByteStreamUploader(
+ INSTANCE_NAME,
+ new ReferenceCountedChannel(channel),
+ null, /* timeout seconds */
+ 60,
+ retrier);
byte[] blob = new byte[CHUNK_SIZE * 2 + 1];
new Random().nextBytes(blob);