File tree Expand file tree Collapse file tree 5 files changed +69
-1
lines changed
main/java/com/intuit/karate
test/java/com/intuit/karate/core/features Expand file tree Collapse file tree 5 files changed +69
-1
lines changed Original file line number Diff line number Diff line change @@ -224,6 +224,7 @@ public void run() {
224
224
}
225
225
hooks .forEach (h -> h .beforeSuite (this ));
226
226
int index = 0 ;
227
+ List <FeatureRuntime > featureRuntimes = new ArrayList <>(featuresFound );
227
228
for (FeatureCall feature : features ) {
228
229
final int featureNum = ++index ;
229
230
FeatureRuntime fr = FeatureRuntime .of (this , feature );
@@ -233,11 +234,12 @@ public void run() {
233
234
onFeatureDone (fr .result , featureNum );
234
235
future .complete (Boolean .TRUE );
235
236
});
236
- pendingTasks . submit (fr );
237
+ featureRuntimes . add (fr );
237
238
}
238
239
if (featuresFound > 1 ) {
239
240
logger .debug ("waiting for {} features to complete" , featuresFound );
240
241
}
242
+ featureRuntimes .forEach (pendingTasks ::submit );
241
243
CompletableFuture [] futuresArray = futures .toArray (new CompletableFuture [futures .size ()]);
242
244
if (timeoutMinutes > 0 ) {
243
245
CompletableFuture .allOf (futuresArray ).get (timeoutMinutes , TimeUnit .MINUTES );
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments