Skip to content
Permalink
Browse files

fix config cleanup in between multiple maven executions (#460)

  • Loading branch information
MykolaGolubyev committed Nov 25, 2019
1 parent f269b62 commit 69427edac2002781e84c6fcfc4e96d69877c97ed
@@ -97,7 +97,8 @@ public static void resetConfigHandlers() {
}

public void reset() {
getCfgValuesStream().forEach(ConfigValue::reset);
getEnumeratedCfgValuesStream().forEach(ConfigValue::reset);
freeFormCfgValues.forEach(ConfigValue::reset);
}

protected WebTauConfig() {
@@ -116,7 +117,7 @@ public void triggerConfigHandlers() {
handlers.forEach(h -> h.onAfterCreate(this));
}

public Stream<ConfigValue> getCfgValuesStream() {
public Stream<ConfigValue> getEnumeratedCfgValuesStream() {
return enumeratedCfgValues.values().stream();
}

@@ -109,7 +109,7 @@ class WebTauCliArgsConfig {
options.addOption(null, HELP_OPTION, false, "print help")
options.addOption(null, EXAMPLE_OPTION, false, "generate basic examples")

cfg.getCfgValuesStream().each {
cfg.getEnumeratedCfgValuesStream().each {
options.addOption(null, it.key, !it.isBoolean(), it.description)
}

@@ -17,7 +17,7 @@ class CLIArgsTest {

def cfg = new WebTauConfig()

def cfgValues = cfg.getCfgValuesStream()
def cfgValues = cfg.getEnumeratedCfgValuesStream()
def cfgList = cfgValues.map { cfgValue ->
def defaultValue = getDefaultValue(cfgValue)
return [
@@ -48,21 +48,38 @@
<version>${project.version}</version>
<executions>
<execution>
<id>run-one</id>
<phase>test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<workingDir>${project.basedir}/src/tests/groovy/one</workingDir>
<tests>
<directory>${project.basedir}/src/tests/groovy/one</directory>
<includes>
<include>scenarios/*.groovy</include>
</includes>
</tests>
</configuration>
</execution>
<execution>
<id>run-two</id>
<phase>test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<workingDir>${project.basedir}/src/tests/groovy/two</workingDir>
<tests>
<directory>${project.basedir}/src/tests/groovy/two</directory>
<includes>
<include>scenarios/*.groovy</include>
</includes>
</tests>
</configuration>
</execution>
</executions>
<configuration>
<workingDir>${project.basedir}/src/tests/groovy</workingDir>
<tests>
<directory>${project.basedir}/src/tests/groovy</directory>
<includes>
<include>scenarios/*.groovy</include>
</includes>
</tests>
</configuration>
</plugin>
</plugins>
</build>
@@ -0,0 +1,7 @@
package one.scenarios

import static com.twosigma.webtau.WebTauGroovyDsl.scenario

scenario('simple scenario A') {
2.should == 2
}
@@ -0,0 +1,8 @@
package one.scenarios

import static com.twosigma.webtau.WebTauGroovyDsl.*

scenario('simple scenario B') {
cfg.customValue.should == 42
cfg.baseUrl.should == 'http://localhost:8080'
}
@@ -0,0 +1,2 @@
url = 'http://localhost:8080'
customValue = 42

This file was deleted.

This file was deleted.

@@ -0,0 +1,7 @@
package two.scenarios

import static com.twosigma.webtau.WebTauGroovyDsl.scenario

scenario('simple scenario A') {
2.should == 2
}
@@ -0,0 +1,9 @@
package two.scenarios

import static com.twosigma.webtau.WebTauGroovyDsl.*

scenario('simple scenario B') {
cfg.customValue.should == null
cfg.anotherCustomValue.should == 42
cfg.baseUrl.should == 'http://localhost:1010'
}
@@ -0,0 +1,2 @@
url = 'http://localhost:1010'
anotherCustomValue = 42

This file was deleted.

@@ -26,8 +26,7 @@ import org.apache.maven.shared.model.fileset.util.FileSetManager
import java.util.concurrent.atomic.AtomicInteger

class WebTauMaven {
private static AtomicInteger numberOfRuns = new AtomicInteger(0)

private static final AtomicInteger numberOfRuns = new AtomicInteger(0)

static void runTests(Log log, FileSet tests, Map options) {
def fileSetManager = new FileSetManager()
@@ -38,9 +37,15 @@ class WebTauMaven {
def args = buildArgs(options)
args.addAll(files)

def cli = new WebTauCliApp(args as String[])
// multiple maven plugins can be executed within the same JVM
// we need to explicitly trigger config handlers
if (numberOfRuns.get() > 0) {
WebTauConfig.resetConfigHandlers()
WebTauConfig.getCfg().reset()
}

def cli = new WebTauCliApp(args as String[])

if (numberOfRuns.get() > 0) {
WebTauConfig.getCfg().triggerConfigHandlers()
}
@@ -58,7 +58,7 @@ public void generate(WebTauReport report) {

private String generateHtml(WebTauReport report) {
Map<String, Object> reportAsMap = new LinkedHashMap<>();
reportAsMap.put("config", configAsListOfMaps(getCfg().getCfgValuesStream()));
reportAsMap.put("config", configAsListOfMaps(getCfg().getEnumeratedCfgValuesStream()));
reportAsMap.put("summary", reportSummaryToMap(report));
reportAsMap.put("version", WebTauMeta.getVersion());
reportAsMap.put("tests", report.getTests().stream()

0 comments on commit 69427ed

Please sign in to comment.
You can’t perform that action at this time.