@@ -3141,4 +3141,51 @@ private static void uploadOutputsAndWait(
31413141 service .uploadOutputs (action , result , () -> future .set (null ), ConcurrentChangesCheckLevel .OFF );
31423142 future .get ();
31433143 }
3144+
3145+ // ==================== Tests for shutdown(RemoteUploadMode) ====================
3146+
3147+ @ Test
3148+ public void shutdown_waitForUploadComplete_blocksUntilDone () throws Exception {
3149+ // Test that WAIT_FOR_UPLOAD_COMPLETE mode blocks until uploads complete
3150+ RemoteExecutionService service = newRemoteExecutionService ();
3151+
3152+ // Shutdown with default mode should return an immediate future
3153+ var future = service .shutdown (RemoteOptions .RemoteUploadMode .WAIT_FOR_UPLOAD_COMPLETE );
3154+
3155+ assertThat (future .isDone ()).isTrue ();
3156+ }
3157+
3158+ @ Test
3159+ public void shutdown_nowaitForUploadComplete_returnsImmediateFutureWhenNoUploads ()
3160+ throws Exception {
3161+ // Test that NOWAIT_FOR_UPLOAD_COMPLETE returns immediately when there are no pending uploads
3162+ RemoteExecutionService service = newRemoteExecutionService ();
3163+
3164+ var future = service .shutdown (RemoteOptions .RemoteUploadMode .NOWAIT_FOR_UPLOAD_COMPLETE );
3165+
3166+ // With no pending uploads, future should be done immediately
3167+ assertThat (future .isDone ()).isTrue ();
3168+ }
3169+
3170+ @ Test
3171+ public void shutdown_calledTwice_secondCallReturnsImmediately () throws Exception {
3172+ // Test that calling shutdown twice doesn't cause issues
3173+ RemoteExecutionService service = newRemoteExecutionService ();
3174+
3175+ var future1 = service .shutdown (RemoteOptions .RemoteUploadMode .WAIT_FOR_UPLOAD_COMPLETE );
3176+ var future2 = service .shutdown (RemoteOptions .RemoteUploadMode .WAIT_FOR_UPLOAD_COMPLETE );
3177+
3178+ assertThat (future1 .isDone ()).isTrue ();
3179+ assertThat (future2 .isDone ()).isTrue ();
3180+ }
3181+
3182+ @ Test
3183+ public void shutdown_releasesCache () throws Exception {
3184+ // Test that shutdown releases the cache
3185+ RemoteExecutionService service = newRemoteExecutionService ();
3186+
3187+ service .shutdown (RemoteOptions .RemoteUploadMode .WAIT_FOR_UPLOAD_COMPLETE );
3188+
3189+ verify (cache ).release ();
3190+ }
31443191}
0 commit comments