Skip to content

Commit c2fc1a3

Browse files
authored
Merge pull request #2518 from dvargas46/develop
reamining features fix #2432
2 parents b8804cf + ada1b4b commit c2fc1a3

File tree

5 files changed

+69
-1
lines changed

5 files changed

+69
-1
lines changed

karate-core/src/main/java/com/intuit/karate/Suite.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ public void run() {
224224
}
225225
hooks.forEach(h -> h.beforeSuite(this));
226226
int index = 0;
227+
List<FeatureRuntime> featureRuntimes = new ArrayList<>(featuresFound);
227228
for (FeatureCall feature : features) {
228229
final int featureNum = ++index;
229230
FeatureRuntime fr = FeatureRuntime.of(this, feature);
@@ -233,11 +234,12 @@ public void run() {
233234
onFeatureDone(fr.result, featureNum);
234235
future.complete(Boolean.TRUE);
235236
});
236-
pendingTasks.submit(fr);
237+
featureRuntimes.add(fr);
237238
}
238239
if (featuresFound > 1) {
239240
logger.debug("waiting for {} features to complete", featuresFound);
240241
}
242+
featureRuntimes.forEach(pendingTasks::submit);
241243
CompletableFuture[] futuresArray = futures.toArray(new CompletableFuture[futures.size()]);
242244
if (timeoutMinutes > 0) {
243245
CompletableFuture.allOf(futuresArray).get(timeoutMinutes, TimeUnit.MINUTES);
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.intuit.karate.core.features;
2+
3+
import com.intuit.karate.Results;
4+
import com.intuit.karate.Runner;
5+
import com.intuit.karate.Suite;
6+
import org.junit.jupiter.api.Test;
7+
8+
import static org.junit.jupiter.api.Assertions.assertEquals;
9+
10+
public class RemainingFeaturesTest {
11+
12+
private static Suite suite;
13+
14+
@Test
15+
void testRemainingFeaturesSingleThread() {
16+
verifyRemainingFeaturesWithThreads(1);
17+
}
18+
19+
@Test
20+
void testRemainingFeaturesParallel() {
21+
verifyRemainingFeaturesWithThreads(2);
22+
}
23+
24+
/**
25+
* Hooks into the current suite to return the remaining features within the test
26+
* @return Remaining features count
27+
*/
28+
public static long remainingFeatures() {
29+
return suite.getFeaturesRemaining();
30+
}
31+
32+
private void verifyRemainingFeaturesWithThreads(int threads) {
33+
Runner.Builder<?> builder = Runner.builder()
34+
.path("classpath:com/intuit/karate/core/features")
35+
.configDir("classpath:com/intuit/karate/core/features")
36+
.threads(threads);
37+
builder.resolveAll();
38+
suite = new Suite(builder);
39+
suite.run();
40+
Results results = suite.buildResults();
41+
assertEquals(0, results.getFailCount(), results.getErrorMessages());
42+
}
43+
44+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Feature:
2+
3+
Scenario: feature test 1
4+
* def numOfFeaturesLeft = remainingFeatures()
5+
* print 'Features left (including this one):', numOfFeaturesLeft
6+
# this is the first feature that runs, so there should be more than 1 feature running
7+
* assert numOfFeaturesLeft > 1
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Feature:
2+
3+
Scenario: feature test 2
4+
* def numOfFeaturesLeft = remainingFeatures()
5+
* print 'Features left (including this one):', numOfFeaturesLeft
6+
# there should always be at least 1 feature left, even if it's the current feature running
7+
* assert numOfFeaturesLeft >= 1
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
function karateConfig() {
2+
const config = {}
3+
4+
const RemainingFeaturesTest = Java.type('com.intuit.karate.core.features.RemainingFeaturesTest')
5+
config.remainingFeatures = RemainingFeaturesTest.remainingFeatures
6+
7+
return config
8+
}

0 commit comments

Comments
 (0)