Add integration test to check for thread leaks in sandboxed Daemon tests
Change-Id: Iaebf022608a56618f06550568ac283f0c0ab7f0e
diff --git a/gerrit-acceptance-framework/src/test/java/com/google/gerrit/acceptance/AbstractDaemonTest.java b/gerrit-acceptance-framework/src/test/java/com/google/gerrit/acceptance/AbstractDaemonTest.java
index 24b3724..dbc65a2 100644
--- a/gerrit-acceptance-framework/src/test/java/com/google/gerrit/acceptance/AbstractDaemonTest.java
+++ b/gerrit-acceptance-framework/src/test/java/com/google/gerrit/acceptance/AbstractDaemonTest.java
@@ -500,7 +500,7 @@
return GitUtil.cloneProject(p, inProcessProtocol.register(ctx, repo).toString());
}
- private void afterTest() throws Exception {
+ protected void afterTest() throws Exception {
Transport.unregister(inProcessProtocol);
for (Repository repo : toClose) {
repo.close();
diff --git a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/pgm/StartStopDeamonIT.java b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/pgm/StartStopDeamonIT.java
new file mode 100644
index 0000000..45d3370
--- /dev/null
+++ b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/pgm/StartStopDeamonIT.java
@@ -0,0 +1,38 @@
+// Copyright (C) 2017 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.gerrit.acceptance.pgm;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.google.gerrit.acceptance.AbstractDaemonTest;
+import com.google.gerrit.acceptance.Sandboxed;
+import java.lang.management.ManagementFactory;
+import java.lang.management.ThreadMXBean;
+import org.junit.Test;
+import org.junit.runner.Description;
+
+@Sandboxed
+public class StartStopDeamonIT extends AbstractDaemonTest {
+ Description suiteDescription = Description.createSuiteDescription(StartStopDeamonIT.class);
+
+ @Test
+ public void sandboxedDaemonDoesNotLeakThreads() throws Exception {
+ ThreadMXBean thbean = ManagementFactory.getThreadMXBean();
+ int startThreads = thbean.getThreadCount();
+ beforeTest(suiteDescription);
+ afterTest();
+ assertThat(Thread.activeCount()).isLessThan(startThreads);
+ }
+}