diff --git a/src/org/labkey/test/tests/assay/AssayTransformMissingParentDirTest.java b/src/org/labkey/test/tests/assay/AssayTransformMissingParentDirTest.java index d0979ba985..5cd0267904 100644 --- a/src/org/labkey/test/tests/assay/AssayTransformMissingParentDirTest.java +++ b/src/org/labkey/test/tests/assay/AssayTransformMissingParentDirTest.java @@ -1,9 +1,11 @@ package org.labkey.test.tests.assay; import org.apache.commons.io.FileUtils; +import org.apache.commons.lang3.SystemUtils; import org.junit.Test; import org.junit.experimental.categories.Category; import org.labkey.api.util.FileUtil; +import org.labkey.api.util.StringUtilsLabKey; import org.labkey.test.Locator; import org.labkey.test.TestFileUtils; import org.labkey.test.categories.Assays; @@ -13,12 +15,14 @@ import org.labkey.test.pages.assay.AssayImportPage; import org.labkey.test.pages.assay.AssayRunsPage; import org.labkey.test.params.assay.GeneralAssayDesign; +import org.labkey.test.util.search.SearchAdminAPIHelper; import java.io.File; import java.io.IOException; import java.nio.file.AccessDeniedException; import java.nio.file.Files; import java.nio.file.Path; +import java.util.stream.Stream; /** * Issue 54156: Regression test to ensure a reasonable error message is shown when an assay design references @@ -48,11 +52,19 @@ public void testMissingParentDirectoryRegression() throws Exception assayDesignerPage.addTransformScript(transformFile); assayDesignerPage.clickSave(); - // Now delete the parent dir to ensure we handle it reasonably. On Windows something locks the directory, maybe - // an external process. If that happens sleep for a second and try again. + // Now delete the parent dir to ensure we handle it reasonably. + // Sometimes on Windows the directory could be locked, maybe by an external process, or the child directory is + // readonly. Use a retry mechanism to set the writeable flag and then try to delete the parent directory. for (int attempt = 1; attempt <= 10; attempt++) { try { + parentDir.toFile().setWritable(true, false); + + // Wrap in a try to close the stream. + try (Stream files = Files.walk(parentDir)) { + files.forEach(p -> p.toFile().setWritable(true, false)); + } + FileUtils.deleteDirectory(parentDir.toFile()); log(String.format("Deletion of directory %s was successful.", parentDir)); break; @@ -67,7 +79,25 @@ public void testMissingParentDirectoryRegression() throws Exception catch (IOException ioException) { log(String.format("IOException trying to delete directory %s. Error: %s. Waiting 10s and retrying. Attempt %d of 10.", parentDir, ioException.getMessage(), attempt)); - if (attempt == 10) throw ioException; + if (attempt == 10) + { + log("Dump the heap."); + dumpHeap(); + + if (SystemUtils.IS_OS_WINDOWS) { + try { + log("Lock diagnostic..."); + ProcessBuilder pb = new ProcessBuilder("tasklist"); + pb.redirectErrorStream(true); + Process p = pb.start(); + String output = new String(p.getInputStream().readAllBytes(), StringUtilsLabKey.DEFAULT_CHARSET); + log("Running processes:\n" + output); + } catch (IOException diagnosticException) { + log("Failed to run lock diagnostic: " + diagnosticException.getMessage()); + } + } + throw ioException; + } sleep(10_000); } }