-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JUnit Platform Engine] Cache parsed features (#2711)
The JUnit Platform allows Scenarios and Examples to be selected by their unique id. This id is stable between test executions and can be used to rerun failing Scenarios and Examples. For practical reasons each unique id is processed individually[+] and results in a feature file being parsed. The parsed feature is then compiled into pickles. Both are mapped to a hierarchy of JUnit 5 test descriptors. These are then merged. The merge process will discard any duplicate nodes. Each time a feature file is parsed the parser will assign unique identifiers to all ast nodes and pickles. As a result the merged hierarchy of junit test descriptors contained pickles that belonged to a different feature file. This poses a problem for tools such as the junit-xml-formatter that depend on the identifiers in pickles and features to stitch everything back together. By caching the parsed feature files we ensure that within a single execution the internal identifiers do not change. + : It would actually matter little if we did process all unique ids at once, the problem would persist when uri selectors are used, either alone or in combination with unique id selectors. Fixes: #2709
- Loading branch information
1 parent
12c5029
commit ee2a0bd
Showing
7 changed files
with
88 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...platform-engine/src/main/java/io/cucumber/junit/platform/engine/CachingFeatureParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.cucumber.junit.platform.engine; | ||
|
||
import io.cucumber.core.feature.FeatureParser; | ||
import io.cucumber.core.gherkin.Feature; | ||
import io.cucumber.core.resource.Resource; | ||
|
||
import java.net.URI; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
class CachingFeatureParser { | ||
|
||
private final Map<URI, Optional<Feature>> cache = new HashMap<>(); | ||
private final FeatureParser delegate; | ||
|
||
CachingFeatureParser(FeatureParser delegate) { | ||
this.delegate = delegate; | ||
} | ||
|
||
Optional<Feature> parseResource(Resource resource) { | ||
return cache.computeIfAbsent(resource.getUri(), uri -> delegate.parseResource(resource)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters