Make BESModule.MAX_WAIT_FOR_PREVIOUS_INVOCATION a method instead of a constant in the class.

PiperOrigin-RevId: 244252450
diff --git a/src/main/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceModule.java b/src/main/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceModule.java
index f65c9a5..da511ff 100644
--- a/src/main/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceModule.java
+++ b/src/main/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceModule.java
@@ -84,8 +84,6 @@
 
   private static final Logger logger = Logger.getLogger(BuildEventServiceModule.class.getName());
   private static final GoogleLogger googleLogger = GoogleLogger.forEnclosingClass();
-  // TODO(lpino): Consider making the wait value configurable.
-  private static final Duration MAX_WAIT_FOR_PREVIOUS_INVOCATION = Duration.ofSeconds(5);
 
   private final AtomicReference<AbruptExitException> pendingAbruptExitException =
       new AtomicReference<>();
@@ -114,6 +112,11 @@
     commandLineReporter.handle(Event.error(exception.getMessage()));
   }
 
+  /** Maximum duration Bazel waits for the previous invocation to finish before cancelling it. */
+  protected Duration getMaxWaitForPreviousInvocation() {
+    return Duration.ofSeconds(5);
+  }
+
   /** Report errors in the command line and possibly fail the build. */
   private void reportError(
       EventHandler commandLineReporter,
@@ -156,14 +159,14 @@
       // infrastructure doesn't allow printing messages in the terminal in beforeCommand.
       Uninterruptibles.getUninterruptibly(
           Futures.allAsList(closeFuturesMap.values()),
-          MAX_WAIT_FOR_PREVIOUS_INVOCATION.getSeconds(),
+          getMaxWaitForPreviousInvocation().getSeconds(),
           TimeUnit.SECONDS);
     } catch (TimeoutException exception) {
       String msg =
           String.format(
               "Pending Build Event Protocol upload took more than %ds to finish. "
                   + "Cancelling and starting a new invocation...",
-              MAX_WAIT_FOR_PREVIOUS_INVOCATION.getSeconds());
+              getMaxWaitForPreviousInvocation().getSeconds());
       cmdLineReporter.handle(Event.warn(msg));
       googleLogger.atWarning().withCause(exception).log(msg);
     } catch (ExecutionException exception) {
@@ -308,7 +311,7 @@
     try {
       Uninterruptibles.getUninterruptibly(
           Futures.allAsList(closeFuturesMap.values()),
-          MAX_WAIT_FOR_PREVIOUS_INVOCATION.getSeconds(),
+          getMaxWaitForPreviousInvocation().getSeconds(),
           TimeUnit.SECONDS);
     } catch (TimeoutException | ExecutionException exception) {
       googleLogger.atWarning().withCause(exception).log(