Repository navigation
Add implied features... - #1598
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #1598 +/- ##
============================================
+ Coverage 78.18% 78.27% +0.09%
- Complexity 3992 4023 +31
============================================
Files 422 423 +1
Lines 12922 12991 +69
Branches 1675 1679 +4
============================================
+ Hits 10103 10169 +66
- Misses 2195 2196 +1
- Partials 624 626 +2
... and 1 file with indirect coverage changes Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report in Codecov by Sentry. |
|
Hm, if the dependencies are data-driven, the iterations do get reported even if successful, but also as part of |
leonard84
left a comment
There was a problem hiding this comment.
An interesting idea, but currently it has too many issues.
| import static java.util.stream.Collectors.toSet; | ||
|
|
||
| public abstract class FeatureNode extends SpockNode<FeatureInfo> { | ||
| private boolean alreadyPrepared = false; |
There was a problem hiding this comment.
This will probably cause issues when parallel execution is enabled. I don't know if it will suffice to make it into an AtomicBoolean/volatile.
There was a problem hiding this comment.
I thought about that when writing it.
But I think any sane usage of such dependencies need to use SAME_THREAD anyway which the @Stepwise also already implies.
So I can add a volatile but I don't think that would change much.
There was a problem hiding this comment.
Then, shouldn't adding dependencies imply the SAME_THREAD execution mode on all? If we would add this new feature then we should minimize the potential for problems.
(No need to fix this at the moment until the other issues are solved, just wanted to point it out.)
|
|
||
| private final List<FeatureInfo> dependencies = new ArrayList<>(); | ||
|
|
||
| private FeatureNode node; |
There was a problem hiding this comment.
This introduces a cyclic dependency between these classes.
There was a problem hiding this comment.
And would that be a problem?
There was a problem hiding this comment.
They are often considered a code smell.
There was a problem hiding this comment.
Ok, I replaced the explicit dependency causing the cycle with a search through the node-tree to find the according node.
| for (int i = features.size() - 1; i > 0; i--) { | ||
| FeatureInfo feature = features.get(i); | ||
| for (int j = i - 1; j >= 0; j--) { | ||
| feature.addDependency(features.get(j)); |
There was a problem hiding this comment.
Wouldn't it be enough to just depend on the previous feature?
There was a problem hiding this comment.
I had that first, but if step2 is ignored, step1 is still a dependency but would then not be executed.
| } | ||
|
|
||
| @Override | ||
| public SpockExecutionContext execute(SpockExecutionContext context, DynamicTestExecutor dynamicTestExecutor) throws Exception { |
There was a problem hiding this comment.
Running other things in execute is awkward as it will have already initialized the current test instance and executed its setup. This can lead to all kind of weird problems, e.g. @Shared int counter would show weird behavior if incremented in the setup.
Furthermore, I think this will cause issues with @ResourceLock, trying it threw this error.
org.junit.platform.commons.JUnitException: Dynamic test descriptors must not declare exclusive resources: [ExclusiveResource [key = 'foo', lockMode = READ_WRITE]]
There was a problem hiding this comment.
Hm, bad about the resource lock indeed, while usage wise the resource lock could of course be acquired on the spec as it has to be SAME_THREAD anyway as mentioned above.
Modifying shared fields in setup is indeed a bit unlucky.
Unfortunately, the DynamicTestExecutor (which was also Marcs first idea) is only available in the execute method. :-/
But due to the resource lock problem it might not be the best idea anyway.
6528e9a to
4f1528f
Compare
|
Ok, a different approach, that hopefully works better and is a bit less dirty. :-) |
| return dependencies; | ||
| } | ||
|
|
||
| public void addDependency(FeatureInfo featureInfo) { |
There was a problem hiding this comment.
One thing that is confusing, is that this naming suggest that the dependencies would be executed before this feature. However, that is not the case, the execution order is dependent on the executionOrder field and the ExecutionMode of the Spec/Feature.
There was a problem hiding this comment.
That's indeed correct.
I would indeed not impose any implicit ordering due to the dependency configuration.
This could easily conflict with explicitly defined order from another extension and actually the way it is right now it can also be used for other use-cases like "if this feature is executed, this other feature also always needs to be executed".
This could for example also be used for something like having a feature that does a cleanup for another feature. Then the cleanup feature would be the dependency but configured to run after the dependee.
Or for similar use-cases, whatever a user might come up with. :-D
The meaning is just that if the dependee is run, the dependency will also run, no matter whether before, after, or concurrently, and I think it would be best to keep it like that.
So what do you suggest?
Adding JavaDoc that explains that it does not impose order, just that it is run too?
Or a different name?
If the latter, any idea for good replacements for dependee and dependency?
There was a problem hiding this comment.
This could for example also be used for something like having a feature that does a cleanup for another feature.
That sounds like a terrible idea 😅.
I think it needs a JavaDoc in any case, explaining what it does and doesn't do. As for a name, maybe addRequiredExecution or addImpliedExecution? Not sure if those are better.
There was a problem hiding this comment.
We should also make sure that you can only depend on features in the same Spec hierarchy, it don't think cross spec relationships is something we should support.
There was a problem hiding this comment.
Why not, as long as it does not impose order?
There was a problem hiding this comment.
I think coupling between specs is a bad idea.
There was a problem hiding this comment.
Tbh, meanings about what is a bad idea and what isn't greatly vary from person to person.
I'm not too much of a fan of forbidding something that would work perfectly fine without any reason besides personal opinion.
There was a problem hiding this comment.
I renamed them to implied and implying features and added JavaDoc and @Beta
There was a problem hiding this comment.
And it would also prevent the need to traverse the whole test hierarchy for dependents, instead it would be contained to one SpecNode.
There was a problem hiding this comment.
Hm, yeah, with the explicit info->node dependency this was not a problem at all.
Now with the node-searching it would be bad, especially when always searching the whole tree from root if there are many tests.
Even if I would just search siblings, then parent and so on this would not help much as at some point the features might already be absent from the tree and it would then still search the whole tree.
So I changed it now, restricting to inner-spec implications and just looking for siblings.
| } | ||
|
|
||
| if (!getParent().equals(feature.getParent())) { | ||
| throw new IllegalArgumentException("Features can only imply features within the same specification"); |
There was a problem hiding this comment.
I think you need to be a bit more flexible here, I'm pretty sure that features will have the Spec they are declared on as parent, with this it would only accept other features on the same hierarchy level. This is fine for @Stepwise as it doesn't support inheritance, but it might be overly limiting.
Could you add a test that checks that impliedFeature works from Parent -> Child and vice-versa.
This should only be an issue on the *Info and not the *Node level.
There was a problem hiding this comment.
Yep, good point.
Changed.
|
Thanks @Vampire, good to see you back. |
Fixes #1593
With these changes, the dependency features are executed
and any extension could also define such dependencies.
It works perfectly fine for Maven and IntelliJ.
For Gradle it also works, as far as running is concerned,
the dependency tests are just not reported if they were successful
and reported awkwardly when they have a failure like being part of
UnknownClass. But that is most probably more a Gradle problem.