-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Core] Add reverse and random scenario execution order #1645
[Core] Add reverse and random scenario execution order #1645
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heya, looks pretty neat!
I'd say that my major objection is that different concerns are all united in the implementation of OrderType
. I think it would be better to separate the CLI parsing from the implementation separate the implementation of --count
and --order
.
@@ -180,6 +184,10 @@ private void parse(List<String> args) { | |||
parsedJunitOptions.addAll(asList(arg.substring("--junit,".length()).split(","))); | |||
} else if (arg.equals("--wip") || arg.equals("-w")) { | |||
wip = true; | |||
} else if (arg.equals("--order")) { | |||
orderTypeData.put(OrderType.TYPE_NAME, args.remove(0)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The names of the CLI commands are specific to the runtime options parser. It is not necessary for the OrderType
to know what it is named on the CLI. It is okay to inline this string here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will change it.
@@ -214,6 +222,10 @@ private void parse(List<String> args) { | |||
junitOptions.clear(); | |||
junitOptions.addAll(parsedJunitOptions); | |||
} | |||
if(orderTypeData.containsKey(OrderType.TYPE_NAME)) { | |||
orderType = OrderTypeFactory.getOrderType(orderTypeData); | |||
orderType.checkVariableValues(orderTypeData); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The exact syntax of CLI commands is also specific to the runtime options parser. Checking if the input is valid should be done here.
Additionally any time when --count
is used it's argument should be a number and should non-negative. Tying the validation to the order type makes this more complex then needed.
I think it might be better to make --count
and --order
independent variables and simply ignore --count
when not relevant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The --count
is used only for the RandomOrderType
thus the check was specific to that type. That required the test for number etc to be done later.
Idea of making --count
applicable for all types, to be used if required, does simplifies things. If so then the orderTypeData
map is also redundant and can be removed. Also no need of checkVariableValues
method.
Later on if a future OrderType
requires an additional variable from CLI it needs to be handled accordingly.
|
||
public abstract class OrderType { | ||
|
||
public static final String NONE_ORDER_TYPE = "None"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type names should be lower case or case insensitive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will change it.
|
||
import gherkin.events.PickleEvent; | ||
|
||
public abstract class OrderType { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this class can be turned into an interface. The default implementation for orderPickleEvents
is only used by none
order.
|
||
import cucumber.runtime.CucumberException; | ||
|
||
public class OrderTypeFactory { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This mapping belongs in RuntimeOptions
. Additionally I think the different orders, could be turned into an enum that implements/extends the OrderType
interface/class.
import cucumber.runtime.CucumberException; | ||
import gherkin.events.PickleEvent; | ||
|
||
public class RandomOrderType extends OrderType { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be an Enum that implements/extends OrderType
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will convert into enum. No need of Factory.
@Override | ||
public List<PickleEvent> orderPickleEvents(List<PickleEvent> pickleEvents) { | ||
Collections.shuffle(pickleEvents); | ||
return pickleEvents.subList(0, ((count > pickleEvents.size() || count == 0) ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nifty but way to hard to follow.
I think this class is doing too much. It's both ordering and selecting pickles. It should only order pickles. By making --order
and --count
independent of each other you can remove this complexity all together.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah my bad. Though this logic needs to remain, as need to make sure that the count
is less or equal to the size of the incoming PickleEvents to avoid exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries!
} | ||
} | ||
} | ||
|
||
final List<Future<?>> executingPickles = new ArrayList<>(); | ||
for(final PickleEvent pickleEvent : runtimeOptions.getOrderType().orderPickleEvents(filteredEvents)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally the order is injected into the Runtime
via the builder. This allows us and other implementations to create Runtime
instances without passing in CLI based RuntimeOptions
.
This will in the long run let us separate the parsing of CLI options from executing pickles.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example:
List<PickleEvent> allPickles = new ArrayList<>();
for (CucumberFeature feature : features) {
allPickles.addAll(feature.getPickles());
}
List<PickleEvent> orderedPickles = pickleOrder.order(allPickles);
List<PickleEvent> filteredPickles = pickleFilter.filter(orderedPickles);
final List<Future<?>> executingPickles = new ArrayList<>();
for (PickleEvent filtredPickle : filteredPickles) {
executingPickles.add(executor.submit(new Runnable() {
@Override
public void run() {
runnerSupplier.get().runPickle(pickleEvent);
}
}));
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To implement the above the existing iteration for the filters will need to be moved to the Filters
class. Are you suggesting above that the pickles need to be ordered first and then filtered?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. It'd be much easier to implement this with a Java8 Stream
but we don't have those at the moment. So I don't mind too much where the iteration ends up.
Implemented Separated Updated the test classes accordingly. |
Looks good! I'll need a bit more time to give this a proper once over. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good, just a few nit picks.
Suppose a test run fails, how would you reproduce this test run? The random order will be different on the next execution. Perhaps we can have the RANDOM
option print out the seed use to shuffle the pickles? Then you could read it back again using --order random:<seed>
.
If you can move the last bit of option parsing into RuntimeOptions
we don't need to add that now though. It can be added later.
|
||
public Filters(FilterOptions filterOPtions) { | ||
public Filters(FilterOptions filterOptions) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cheers.
|
||
public Runtime(final Plugins plugins, | ||
final RuntimeOptions runtimeOptions, | ||
final EventBus bus, | ||
final Filters filters, | ||
final RunnerSupplier runnerSupplier, | ||
final FeatureSupplier featureSupplier, | ||
final ExecutorService executor) { | ||
final ExecutorService executor, | ||
final OrderType orderType) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean to use OrderPickleEvents
here?
|
||
public static OrderType getOrderType(String name) { | ||
for (OrderType orderType : OrderType.values()) { | ||
if (name.equalsIgnoreCase(orderType.name())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally we parse the different order names in runtime options too. This would avoid having to support both lower and uppercase options in future versions.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
Allows scenarios to be executed in random or reverse order. Custom execution orders can also be created.
Details
All scenarios can be run in random order.
java <classpath> cucumber.api.cli.Main --order random -g <glue path> <feature file path>
The number of scenarios to be run in random can also be mentioned.
java <classpath> cucumber.api.cli.Main --order random --count <number> -g <glue> <feature file>
All scenarios can be run in reverse order.
java <classpath> cucumber.api.cli.Main --order reverse -g <glue path> <feature file path>
Custom orders can be created by implementing the
PickleOrder
interface in thecucumber.runtime.order
package.Motivation and Context
Scenarios can be executed in random order. Aids in finding out if their is any dependency between scenarios.
How Has This Been Tested?
Tests for
RuntimeOptions
are added inRuntimeOptionsTest
for testing options in the command.OrderTypeFactoryTest
tests theOrderTypeFactory
class.RandomOrderTypeTest
tests theRandomOrderType
class. No test forReverseOrderType
as it will test thereverse
method ofCollections
class.Types of changes
Checklist: