Skip to content
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

reamining features fix #2432 #2518

Merged
merged 2 commits into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading