|
1 | 1 | package org.labkey.test.tests.assay; |
2 | 2 |
|
| 3 | +import org.apache.commons.io.FileUtils; |
3 | 4 | import org.junit.Test; |
4 | 5 | import org.junit.experimental.categories.Category; |
5 | 6 | import org.labkey.api.util.FileUtil; |
|
14 | 15 | import org.labkey.test.params.assay.GeneralAssayDesign; |
15 | 16 |
|
16 | 17 | import java.io.File; |
| 18 | +import java.io.IOException; |
| 19 | +import java.nio.file.AccessDeniedException; |
17 | 20 | import java.nio.file.Files; |
18 | 21 | import java.nio.file.Path; |
19 | 22 |
|
@@ -45,8 +48,29 @@ public void testMissingParentDirectoryRegression() throws Exception |
45 | 48 | assayDesignerPage.addTransformScript(transformFile); |
46 | 49 | assayDesignerPage.clickSave(); |
47 | 50 |
|
48 | | - // Now delete the parent dir to ensure we handle it reasonably |
49 | | - TestFileUtils.deleteDir(parentDir.toFile()); |
| 51 | + // Now delete the parent dir to ensure we handle it reasonably. On Windows something locks the directory, maybe |
| 52 | + // an external process. If that happens sleep for a second and try again. |
| 53 | + for (int attempt = 1; attempt <= 10; attempt++) { |
| 54 | + try |
| 55 | + { |
| 56 | + FileUtils.deleteDirectory(parentDir.toFile()); |
| 57 | + log(String.format("Deletion of directory %s was successful.", parentDir)); |
| 58 | + break; |
| 59 | + } catch (AccessDeniedException deniedException) { |
| 60 | + // Yes I know AccessDeniedException is a subset of an IOException, but I wanted to log explicitly a |
| 61 | + // failure and retry because of an AccessDeniedException from some other IOException. |
| 62 | + log(String.format("Access denied trying to delete directory %s. Error: %s. Waiting 10s and retrying. Attempt %d of 10.", |
| 63 | + parentDir, deniedException.getMessage(), attempt)); |
| 64 | + if (attempt == 10) throw deniedException; |
| 65 | + sleep(10_000); |
| 66 | + } |
| 67 | + catch (IOException ioException) { |
| 68 | + log(String.format("IOException trying to delete directory %s. Error: %s. Waiting 10s and retrying. Attempt %d of 10.", |
| 69 | + parentDir, ioException.getMessage(), attempt)); |
| 70 | + if (attempt == 10) throw ioException; |
| 71 | + sleep(10_000); |
| 72 | + } |
| 73 | + } |
50 | 74 |
|
51 | 75 | // Attempt to import data and verify a reasonable error message is shown |
52 | 76 | String importData = """ |
|
0 commit comments