remote: fix flaky test. Fixes #3348

The sameBlobsShouldNotBeUploadedTwice() test was found flaky on bazel ci
[1]. This can happen when the first upload finishes before the second is
started.

Add a CountDownLatch to stop the first upload from completing, before the
second is started.

[1] https://github.com/bazelbuild/bazel/issues/3348

PiperOrigin-RevId: 161641110
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 8cd78ff..732afac 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
@@ -263,11 +263,18 @@
     Chunker chunker = new Chunker(blob, CHUNK_SIZE);
 
     AtomicInteger numWriteCalls = new AtomicInteger();
+    CountDownLatch blocker = new CountDownLatch(1);
 
     serviceRegistry.addService(new ByteStreamImplBase() {
       @Override
       public StreamObserver<WriteRequest> write(StreamObserver<WriteResponse> response) {
         numWriteCalls.incrementAndGet();
+        try {
+          // Ensures that the first upload does not finish, before the second upload is started.
+          blocker.await();
+        } catch (InterruptedException e) {
+          Thread.currentThread().interrupt();
+        }
 
         return new StreamObserver<WriteRequest>() {
 
@@ -295,6 +302,8 @@
     Future<?> upload1 = uploader.uploadBlobAsync(chunker);
     Future<?> upload2 = uploader.uploadBlobAsync(chunker);
 
+    blocker.countDown();
+
     assertThat(upload1).isSameAs(upload2);
 
     upload1.get();