Add @Sandboxed annotation for classes and methods

There are some tests where it is especially hard to make sure that they
are not influenced by other tests in the same class. This includes all
indexer tests since some of them check the cardinality of a query result,
which might change as more entities are added by other tests.

This is a backport of the original change, adapted to work on stable-2.12.

Change-Id: I74b40b2e7f95894dd666dcd87d97fd29b2d67c51
This commit is contained in:
Patrick Hiesel
2016-09-21 22:30:58 +02:00
committed by David Pursehouse
parent 0d3dab2236
commit 225da2dc6d
4 changed files with 96 additions and 3 deletions

View File

@@ -256,7 +256,8 @@ public abstract class AbstractDaemonTest {
}
baseConfig.setString("gerrit", null, "tempSiteDir",
tempSiteDir.getRoot().getPath());
if (classDesc.equals(methodDesc)) {
if (classDesc.equals(methodDesc) && !classDesc.sandboxed() &&
!methodDesc.sandboxed()) {
if (commonServer == null) {
commonServer = GerritServer.start(classDesc, baseConfig);
}

View File

@@ -41,6 +41,7 @@ import org.eclipse.jgit.lib.RepositoryCache;
import org.eclipse.jgit.util.FS;
import java.io.File;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.net.InetAddress;
import java.net.InetSocketAddress;
@@ -60,7 +61,8 @@ public class GerritServer {
return new AutoValue_GerritServer_Description(
configName,
true, // @UseLocalDisk is only valid on methods.
testDesc.getTestClass().getAnnotation(NoHttpd.class) == null,
!has(NoHttpd.class, testDesc.getTestClass()),
has(Sandboxed.class, testDesc.getTestClass()),
null, // @GerritConfig is only valid on methods.
null); // @GerritConfigs is only valid on methods.
@@ -72,14 +74,27 @@ public class GerritServer {
configName,
testDesc.getAnnotation(UseLocalDisk.class) == null,
testDesc.getAnnotation(NoHttpd.class) == null
&& testDesc.getTestClass().getAnnotation(NoHttpd.class) == null,
&& !has(NoHttpd.class, testDesc.getTestClass()),
testDesc.getAnnotation(Sandboxed.class) != null ||
has(Sandboxed.class, testDesc.getTestClass()),
testDesc.getAnnotation(GerritConfig.class),
testDesc.getAnnotation(GerritConfigs.class));
}
private static boolean has(
Class<? extends Annotation> annotation, Class<?> clazz) {
for (; clazz != null; clazz = clazz.getSuperclass()) {
if (clazz.getAnnotation(annotation) != null) {
return true;
}
}
return false;
}
@Nullable abstract String configName();
abstract boolean memory();
abstract boolean httpd();
abstract boolean sandboxed();
@Nullable abstract GerritConfig config();
@Nullable abstract GerritConfigs configs();

View File

@@ -0,0 +1,27 @@
// Copyright (C) 2016 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;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
@Target({TYPE, METHOD})
@Retention(RUNTIME)
public @interface Sandboxed {
}