Skip to content
Permalink
Browse files

Windows is failing tests due to spurious cleanup errors (#2537)

* NMS-12102: Windows is failing tests due to spurious cleanup errors

* NMS-12102: Add logging and catch both cleanup errors
  • Loading branch information...
smith-opennms committed Jun 10, 2019
1 parent e5bb40f commit a08a123c2323f79c27e7fe4cdc60dc0ec00229c7
@@ -29,6 +29,7 @@
package org.opennms.core.collection.test;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Method;

@@ -41,6 +42,8 @@
import org.opennms.netmgt.config.DefaultDataCollectionConfigDao;
import org.opennms.netmgt.config.HttpCollectionConfigFactory;
import org.opennms.test.FileAnticipator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.Resource;
import org.springframework.test.context.TestContext;
import org.springframework.test.context.TestExecutionListener;
@@ -57,6 +60,7 @@
*/
public class JUnitCollectorExecutionListener extends AbstractTestExecutionListener {

private static final Logger LOG = LoggerFactory.getLogger(JUnitCollectorExecutionListener.class);
private File m_snmpRrdDirectory;
private FileAnticipator m_fileAnticipator;

@@ -154,9 +158,27 @@ public void afterTestMethod(TestContext testContext) throws Exception {
}
}

FileUtils.deleteDirectory(m_snmpRrdDirectory);
try {
FileUtils.deleteDirectory(m_snmpRrdDirectory);
} catch (IOException deleteDirectoryException) {
// Windows is failing tests due to spurious cleanup errors
LOG.warn("Failed to delete {} during cleanup.", m_snmpRrdDirectory, deleteDirectoryException);
String os = System.getProperty("os.name");
if (os == null || !os.contains("Windows")) {
throw deleteDirectoryException;
}
}

m_fileAnticipator.tearDown();
try {
m_fileAnticipator.tearDown();
} catch (RuntimeException anticipatorTeardownException) {
// Windows is failing tests due to spurious cleanup errors
LOG.warn("Failed to delete {} during cleanup.", m_fileAnticipator.getTempDir(), anticipatorTeardownException);
String os = System.getProperty("os.name");
if (os == null || !os.contains("Windows")) {
throw anticipatorTeardownException;
}
}

if (e != null) {
throw e;

0 comments on commit a08a123

Please sign in to comment.
You can’t perform that action at this time.