[英]Executing Feature in isolation, but contained Scenarios in parallel
I have a large-ish and rapidly growing body of karate tests and use the parallel execution to speed up processing, which basically works great in different configurations:我有一个庞大且快速增长的空手道测试主体,并使用并行执行来加速处理,这在不同的配置中基本上工作得很好:
parallel=false
) for very few special cases在极少数特殊情况下,在功能 ( parallel=false
) 中顺序执行场景@sequential
tag) for things that modify configuration settings, global lookups etc完全顺序执行(通过单独的单线程运行器,由自定义@sequential
标记触发)修改配置设置、全局查找等There's however also a parameterized (Scenario Outline) feature for the basic functionality of many types of global lookups.然而,对于许多类型的全局查找的基本功能,还有一个参数化(场景大纲)功能。 Currently it runs in the "completely sequential" mode because it affects other tests.目前它以“完全顺序”模式运行,因为它会影响其他测试。 But actually the scenarios inside that feature could be executed in parallel (they don't affect each other) as long as the Feature as a whole is executed in isolation (because the tests do affect other Features).但实际上该功能中的场景可以并行执行(它们不会相互影响),只要该功能作为一个整体是隔离执行的(因为测试确实会影响其他功能)。
So - is there a way to implement "sequential Features with parallel Scenarios" execution?那么 - 有没有办法实现“具有并行场景的顺序功能”执行? I admit that this is likely a niche case, but it would speed up tests execution quite a bit in my case.我承认这可能是一个小众案例,但在我的案例中它会大大加快测试执行速度。
... and posting this question already got the ideas flowing and pointed me to a possible way to implement this: ...并发布这个问题已经让想法流动起来,并指出了一种可能的实现方式:
private static void runLocalParallel(Builder<?> builder) {
final List<Feature> features = builder.tags("@local_parallel").resolveAll();
for (Feature feature : features) {
builder.features(feature).parallel(8);
}
}
This identifies all features tagged with @local_parallel
, iterates over them and executes a parallel runner for each individually.这会识别所有标记有@local_parallel
的特征,迭代它们并为每个单独执行一个并行运行器。 Result handling, report output etc still needs to be implemented in an elegant manner, but that's doable as well.结果处理、报告 output 等仍然需要以优雅的方式实现,但这也是可行的。
Yes, indeed an edge case - but it has come up a few times.是的,确实是一个边缘案例——但它出现过几次。 We've wondered about a way to "bucketize" threads, which means we can do things like say that certain tags have to be run only on particular thread.我们想知道一种“分桶”线程的方法,这意味着我们可以做一些事情,比如说某些标签必须只在特定线程上运行。 Come to think of it, that's a good feature request, so I opened one, feel free to comment.想想看,这是一个很好的功能请求,所以我打开了一个,请随时发表评论。 https://github.com/karatelabs/karate/issues/2235 https://github.com/karatelabs/karate/issues/2235
In theory if you write some Java glue code that holds a lock, you can call that code before entering any "critical" feature.理论上,如果您编写一些持有锁的 Java 粘合代码,您可以在输入任何“关键”功能之前调用该代码。 I haven't tried it, but may be worth experimenting.我没有尝试过,但可能值得尝试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.