GauthamBanasandra commented on code in PR #7755:
URL: https://github.com/apache/hadoop/pull/7755#discussion_r2160428122


##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/converter/FSConfigConverterTestCommons.java:
##########
@@ -58,9 +58,32 @@ public FSConfigConverterTestCommons() {
 
   public void setUp() throws IOException {
     File d = new File(TEST_DIR, "conversion-output");
+
     if (d.exists()) {
-      FileUtils.deleteDirectory(d);
+      // Retry mechanism to ensure file handles are released
+      int maxRetries = 3;
+      int attempts = 0;
+      boolean deleted = false;
+
+      while (attempts < maxRetries && !deleted) {
+        try {
+          FileUtils.deleteDirectory(d);
+          deleted = true;
+        } catch (IOException e) {
+          attempts++;
+          System.gc(); // Hint JVM to run GC to close any unreferenced file 
streams
+          try {
+            Thread.sleep(100); // Wait a bit before retrying
+          } catch (InterruptedException ie) {
+            Thread.currentThread().interrupt();
+          }
+          if (attempts == maxRetries) {
+            throw new IOException("Failed to delete directory after retries: " 
+ d.getAbsolutePath(), e);
+          }
+        }
+      }

Review Comment:
   This still may not guarantee the folder deletion. A better way to solve this 
would be to configure this class to never run the unit tests in parallel. You 
can use the `@Execution(ExecutionMode.SAME_THREAD)` annotation on the class in 
JUnit 5.
   
   Could you please use an equivalent approach for the version of JUnit used 
here?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org

Reply via email to