Skip to content

Commit

Permalink
fix config cleanup in between multiple maven executions (#460)
Browse files Browse the repository at this point in the history
  • Loading branch information
MykolaGolubyev committed Nov 25, 2019
1 parent f269b62 commit 69427ed
Show file tree
Hide file tree
Showing 15 changed files with 75 additions and 64 deletions.
Expand Up @@ -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() {
Expand All @@ -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();
}

Expand Down
Expand Up @@ -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)
}

Expand Down
Expand Up @@ -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 [
Expand Down
35 changes: 26 additions & 9 deletions webtau-maven-plugin-test/pom.xml
Expand Up @@ -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>
Expand Down
@@ -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'
}
2 changes: 2 additions & 0 deletions webtau-maven-plugin-test/src/tests/groovy/one/webtau.cfg
@@ -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'
}
2 changes: 2 additions & 0 deletions webtau-maven-plugin-test/src/tests/groovy/two/webtau.cfg
@@ -0,0 +1,2 @@
url = 'http://localhost:1010'
anotherCustomValue = 42
1 change: 0 additions & 1 deletion webtau-maven-plugin-test/src/tests/groovy/webtau.cfg

This file was deleted.

Expand Up @@ -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()
Expand All @@ -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()
}
Expand Down
Expand Up @@ -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()
Expand Down

0 comments on commit 69427ed

Please sign in to comment.