Skip to content

Commit

Permalink
Merge pull request #2518 from dvargas46/develop
Browse files Browse the repository at this point in the history
reamining features fix #2432
  • Loading branch information
ptrthomas authored Feb 24, 2024
2 parents b8804cf + ada1b4b commit c2fc1a3
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 1 deletion.
4 changes: 3 additions & 1 deletion karate-core/src/main/java/com/intuit/karate/Suite.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ public void run() {
}
hooks.forEach(h -> h.beforeSuite(this));
int index = 0;
List<FeatureRuntime> featureRuntimes = new ArrayList<>(featuresFound);
for (FeatureCall feature : features) {
final int featureNum = ++index;
FeatureRuntime fr = FeatureRuntime.of(this, feature);
Expand All @@ -233,11 +234,12 @@ public void run() {
onFeatureDone(fr.result, featureNum);
future.complete(Boolean.TRUE);
});
pendingTasks.submit(fr);
featureRuntimes.add(fr);
}
if (featuresFound > 1) {
logger.debug("waiting for {} features to complete", featuresFound);
}
featureRuntimes.forEach(pendingTasks::submit);
CompletableFuture[] futuresArray = futures.toArray(new CompletableFuture[futures.size()]);
if (timeoutMinutes > 0) {
CompletableFuture.allOf(futuresArray).get(timeoutMinutes, TimeUnit.MINUTES);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.intuit.karate.core.features;

import com.intuit.karate.Results;
import com.intuit.karate.Runner;
import com.intuit.karate.Suite;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class RemainingFeaturesTest {

private static Suite suite;

@Test
void testRemainingFeaturesSingleThread() {
verifyRemainingFeaturesWithThreads(1);
}

@Test
void testRemainingFeaturesParallel() {
verifyRemainingFeaturesWithThreads(2);
}

/**
* Hooks into the current suite to return the remaining features within the test
* @return Remaining features count
*/
public static long remainingFeatures() {
return suite.getFeaturesRemaining();
}

private void verifyRemainingFeaturesWithThreads(int threads) {
Runner.Builder<?> builder = Runner.builder()
.path("classpath:com/intuit/karate/core/features")
.configDir("classpath:com/intuit/karate/core/features")
.threads(threads);
builder.resolveAll();
suite = new Suite(builder);
suite.run();
Results results = suite.buildResults();
assertEquals(0, results.getFailCount(), results.getErrorMessages());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Feature:

Scenario: feature test 1
* def numOfFeaturesLeft = remainingFeatures()
* print 'Features left (including this one):', numOfFeaturesLeft
# this is the first feature that runs, so there should be more than 1 feature running
* assert numOfFeaturesLeft > 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Feature:

Scenario: feature test 2
* def numOfFeaturesLeft = remainingFeatures()
* print 'Features left (including this one):', numOfFeaturesLeft
# there should always be at least 1 feature left, even if it's the current feature running
* assert numOfFeaturesLeft >= 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function karateConfig() {
const config = {}

const RemainingFeaturesTest = Java.type('com.intuit.karate.core.features.RemainingFeaturesTest')
config.remainingFeatures = RemainingFeaturesTest.remainingFeatures

return config
}

0 comments on commit c2fc1a3

Please sign in to comment.