Merge "Fix cleanup after tests"
This commit is contained in:
@@ -146,6 +146,7 @@ public abstract class AbstractDaemonTest {
|
|||||||
db.close();
|
db.close();
|
||||||
sshSession.close();
|
sshSession.close();
|
||||||
server.stop();
|
server.stop();
|
||||||
|
TempFileUtil.cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected PushOneCommit.Result createChange() throws GitAPIException,
|
protected PushOneCommit.Result createChange() throws GitAPIException,
|
||||||
|
@@ -98,7 +98,7 @@ public class GerritServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Injector i = createTestInjector(daemon);
|
Injector i = createTestInjector(daemon);
|
||||||
return new GerritServer(site, i, daemon, daemonService);
|
return new GerritServer(i, daemon, daemonService);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static File initSite(Config base) throws Exception {
|
private static File initSite(Config base) throws Exception {
|
||||||
@@ -160,7 +160,6 @@ public class GerritServer {
|
|||||||
return InetAddress.getLoopbackAddress();
|
return InetAddress.getLoopbackAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
private File sitePath;
|
|
||||||
private Daemon daemon;
|
private Daemon daemon;
|
||||||
private ExecutorService daemonService;
|
private ExecutorService daemonService;
|
||||||
private Injector testInjector;
|
private Injector testInjector;
|
||||||
@@ -168,9 +167,8 @@ public class GerritServer {
|
|||||||
private InetSocketAddress sshdAddress;
|
private InetSocketAddress sshdAddress;
|
||||||
private InetSocketAddress httpAddress;
|
private InetSocketAddress httpAddress;
|
||||||
|
|
||||||
private GerritServer(File sitePath, Injector testInjector, Daemon daemon,
|
private GerritServer(Injector testInjector, Daemon daemon,
|
||||||
ExecutorService daemonService) throws IOException, ConfigInvalidException {
|
ExecutorService daemonService) throws IOException, ConfigInvalidException {
|
||||||
this.sitePath = sitePath;
|
|
||||||
this.testInjector = testInjector;
|
this.testInjector = testInjector;
|
||||||
this.daemon = daemon;
|
this.daemon = daemon;
|
||||||
this.daemonService = daemonService;
|
this.daemonService = daemonService;
|
||||||
@@ -209,9 +207,6 @@ public class GerritServer {
|
|||||||
daemonService.shutdownNow();
|
daemonService.shutdownNow();
|
||||||
daemonService.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS);
|
daemonService.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
if (sitePath != null) {
|
|
||||||
TempFileUtil.recursivelyDelete(sitePath);
|
|
||||||
}
|
|
||||||
RepositoryCache.clear();
|
RepositoryCache.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,17 +16,29 @@ package com.google.gerrit.acceptance;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class TempFileUtil {
|
public class TempFileUtil {
|
||||||
public static File createTempDirectory() throws IOException {
|
private static List<File> allDirsCreated = new ArrayList<>();
|
||||||
|
|
||||||
|
public synchronized static File createTempDirectory() throws IOException {
|
||||||
File tmp = File.createTempFile("gerrit_test_", "");
|
File tmp = File.createTempFile("gerrit_test_", "");
|
||||||
if (!tmp.delete() || !tmp.mkdir()) {
|
if (!tmp.delete() || !tmp.mkdir()) {
|
||||||
throw new IOException("Cannot create " + tmp.getPath());
|
throw new IOException("Cannot create " + tmp.getPath());
|
||||||
}
|
}
|
||||||
|
allDirsCreated.add(tmp);
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void recursivelyDelete(File dir) throws IOException {
|
public static synchronized void cleanup() throws IOException {
|
||||||
|
for (File dir : allDirsCreated) {
|
||||||
|
recursivelyDelete(dir);
|
||||||
|
}
|
||||||
|
allDirsCreated.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void recursivelyDelete(File dir) throws IOException {
|
||||||
if (!dir.getPath().equals(dir.getCanonicalPath())) {
|
if (!dir.getPath().equals(dir.getCanonicalPath())) {
|
||||||
// Directory symlink reaching outside of temporary space.
|
// Directory symlink reaching outside of temporary space.
|
||||||
return;
|
return;
|
||||||
|
@@ -36,7 +36,7 @@ public class ReindexIT {
|
|||||||
@After
|
@After
|
||||||
public void destroySite() throws Exception {
|
public void destroySite() throws Exception {
|
||||||
if (sitePath != null) {
|
if (sitePath != null) {
|
||||||
TempFileUtil.recursivelyDelete(sitePath);
|
TempFileUtil.cleanup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user