Run acceptance tests with different configs using @Parameterized

This is a simpler approach as it doesn't require generating extra test
targets for Buck, nor rebuilding test jars to get everything working
in Eclipse. There are enough tests running at any given time with Buck
that having each acceptance test take twice as long should maintain
adequate parallelism.

Change-Id: I109acaf6b957e8f9dd621e98abe46a75f78cdc32
This commit is contained in:
Dave Borowitz 2014-01-30 16:04:47 -08:00
parent 02bf1cd82a
commit 063e0fd4fd
4 changed files with 48 additions and 70 deletions

View File

@ -40,14 +40,3 @@ java_library(
'//gerrit-acceptance-tests/...', '//gerrit-acceptance-tests/...',
], ],
) )
java_library(
name = 'configs',
resources = glob([
'src/test/resources/com/google/gerrit/acceptance/config/*.config',
]),
visibility = [
'//tools/eclipse:classpath',
'//gerrit-acceptance-tests/...',
],
)

View File

@ -14,6 +14,7 @@
package com.google.gerrit.acceptance; package com.google.gerrit.acceptance;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.gerrit.acceptance.GitUtil.initSsh; import static com.google.gerrit.acceptance.GitUtil.initSsh;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@ -25,16 +26,46 @@ import com.google.gson.Gson;
import com.google.inject.Inject; import com.google.inject.Inject;
import org.apache.http.HttpStatus; import org.apache.http.HttpStatus;
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.Config;
import org.junit.Rule; import org.junit.Rule;
import org.junit.rules.TestRule; import org.junit.rules.TestRule;
import org.junit.runner.Description; import org.junit.runner.Description;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
import org.junit.runners.model.Statement; import org.junit.runners.model.Statement;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays;
@RunWith(Parameterized.class)
public abstract class AbstractDaemonTest { public abstract class AbstractDaemonTest {
private static class NamedConfig extends Config {
private final String name;
private NamedConfig(String name) {
this.name = checkNotNull(name);
}
@Override
public String toString() {
return name;
}
}
@Parameters(name = "{0}")
public static Iterable<Object[]> configs() {
Config defaultConfig = new NamedConfig("default");
return Arrays.asList(new Object[][]{
{defaultConfig},
});
}
@Parameter
public Config baseConfig;
@Inject @Inject
protected AccountCreator accounts; protected AccountCreator accounts;
@ -58,20 +89,18 @@ public abstract class AbstractDaemonTest {
} }
}; };
private static Config config(Description description) private Config config(Description description) {
throws IOException, ConfigInvalidException {
Config base = ConfigAnnotationParser.parseFromSystemProperty();
GerritConfigs cfgs = description.getAnnotation(GerritConfigs.class); GerritConfigs cfgs = description.getAnnotation(GerritConfigs.class);
GerritConfig cfg = description.getAnnotation(GerritConfig.class); GerritConfig cfg = description.getAnnotation(GerritConfig.class);
if (cfgs != null && cfg != null) { if (cfgs != null && cfg != null) {
throw new IllegalStateException("Use either @GerritConfigs or @GerritConfig not both"); throw new IllegalStateException("Use either @GerritConfigs or @GerritConfig not both");
} }
if (cfgs != null) { if (cfgs != null) {
return ConfigAnnotationParser.parse(base, cfgs); return ConfigAnnotationParser.parse(baseConfig, cfgs);
} else if (cfg != null) { } else if (cfg != null) {
return ConfigAnnotationParser.parse(base, cfg); return ConfigAnnotationParser.parse(baseConfig, cfg);
} else { } else {
return base; return baseConfig;
} }
} }

View File

@ -14,40 +14,16 @@
package com.google.gerrit.acceptance; package com.google.gerrit.acceptance;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.Charsets;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.io.Resources;
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.Config;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
class ConfigAnnotationParser { class ConfigAnnotationParser {
private static final String CONFIG_PKG =
"com.google.gerrit.acceptance.config.";
private static final String CONFIG_DIR = "/" + CONFIG_PKG.replace('.', '/');
private static Splitter splitter = Splitter.on(".").trimResults(); private static Splitter splitter = Splitter.on(".").trimResults();
static Config parseFromSystemProperty()
throws ConfigInvalidException, IOException {
Config cfg = new Config();
String name = System.getProperty(CONFIG_PKG + "BaseConfig");
if (!Strings.isNullOrEmpty(name)) {
String resource = CONFIG_DIR + name + ".config";
URL url = checkNotNull(ConfigAnnotationParser.class.getResource(resource),
"test config resource not found: %s", resource);
cfg.fromText(Resources.toString(url, Charsets.UTF_8));
}
return cfg;
}
static Config parse(Config base, GerritConfigs annotation) { static Config parse(Config base, GerritConfigs annotation) {
if (annotation == null) { if (annotation == null) {
return null; return null;

View File

@ -1,36 +1,20 @@
def acceptance_tests( def acceptance_tests(
srcs, srcs,
deps = [], deps = [],
configs = [],
vm_args = ['-Xmx256m']): vm_args = ['-Xmx256m']):
for j in srcs: for j in srcs:
for config in [None] + configs: java_test(
name = j[:-len('.java')] name = j[:-len('.java')],
srcs = [j],
deps = ['//gerrit-acceptance-tests:lib'] + deps,
source_under_test = [
'//gerrit-httpd:httpd',
'//gerrit-sshd:sshd',
'//gerrit-server:server',
],
labels = [ labels = [
'acceptance', 'acceptance',
'slow', 'slow',
] ],
curr_vm_args = list(vm_args) vm_args = vm_args,
)
if config:
curr_vm_args.append(
'-Dcom.google.gerrit.acceptance.config.BaseConfig=' + config)
name += '_' + config
labels.append('acceptance_config')
labels.append('config_' + config)
java_test(
name = name,
srcs = [j],
deps = deps + [
'//gerrit-acceptance-tests:configs',
'//gerrit-acceptance-tests:lib',
],
source_under_test = [
'//gerrit-httpd:httpd',
'//gerrit-sshd:sshd',
'//gerrit-server:server',
],
labels = labels,
vm_args = curr_vm_args,
)