Add integration test to check for thread leaks in sandboxed Daemon tests

Change-Id: Iaebf022608a56618f06550568ac283f0c0ab7f0e
This commit is contained in:
Luca Milanesio
2017-04-03 17:25:38 +01:00
committed by David Pursehouse
parent b5584d18f6
commit 5b42a126ef
2 changed files with 39 additions and 1 deletions

View File

@@ -500,7 +500,7 @@ public abstract class AbstractDaemonTest {
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();

View File

@@ -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);
}
}