Skip to content

Commit

Permalink
Merge pull request #2481 from dvargas46/develop
Browse files Browse the repository at this point in the history
fix thread count issue when using karate.options #2444
  • Loading branch information
ptrthomas committed Jan 20, 2024
2 parents 6d80da8 + f5a3292 commit c6b2c62
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
5 changes: 4 additions & 1 deletion karate-core/src/main/java/com/intuit/karate/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public class Main implements Callable<Void> {
List<String> tags;

@Option(names = {"-T", "--threads"}, description = "number of threads when running tests")
int threads = 1;
Integer threads;

@Option(names = {"-o", "--output"}, description = "directory where logs and reports are output (default 'target')")
String output = FileUtils.getBuildDir();
Expand Down Expand Up @@ -329,6 +329,9 @@ public Void call() throws Exception {
}
return null;
}
if (threads == null) {
threads = 1;
}
if (paths != null) {
Results results = Runner
.path(paths).tags(tags).scenarioName(name)
Expand Down
2 changes: 1 addition & 1 deletion karate-core/src/main/java/com/intuit/karate/Runner.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public List<FeatureCall> resolveAll() {
if (ko.paths != null) {
paths = ko.paths;
}
if (ko.threads != threadCount) { // 1 by default
if (ko.threads != null) {
threadCount = ko.threads;
}
dryRun = ko.dryRun || dryRun;
Expand Down
48 changes: 48 additions & 0 deletions karate-core/src/test/java/com/intuit/karate/ThreadCountTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.intuit.karate;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;

import static com.intuit.karate.Constants.KARATE_OPTIONS;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class ThreadCountTest {

private static final int THREAD_COUNT = 20;

@AfterEach
void clearKarateOptionsProperty() {
System.clearProperty(KARATE_OPTIONS);
}

@Test
void testThreadCountFromRunner() {
Runner.Builder<?> builder = Runner.builder();
builder.path("does-not-exist").parallel(THREAD_COUNT);
assertEquals(builder.threadCount, THREAD_COUNT);
}

@Test
void testThreadCountFromKarateOptionsShortName() {
System.setProperty(KARATE_OPTIONS, "-T" + THREAD_COUNT);
Runner.Builder<?> builder = Runner.builder();
builder.path("does-not-exist").parallel(1);
assertEquals(builder.threadCount, THREAD_COUNT);
}

@Test
void testThreadCountFromKarateOptionsLongName() {
System.setProperty(KARATE_OPTIONS, "--threads=" + THREAD_COUNT);
Runner.Builder<?> builder = Runner.builder();
builder.path("does-not-exist").parallel(1);
assertEquals(builder.threadCount, THREAD_COUNT);
}

@Test
void testThreadCountFromRunnerAndKarateOptionsWithoutThreadOption() {
System.setProperty(KARATE_OPTIONS, "--tags=@does-not-exist");
Runner.Builder<?> builder = Runner.builder();
builder.path("does-not-exist").parallel(THREAD_COUNT);
assertEquals(builder.threadCount, THREAD_COUNT);
}
}

0 comments on commit c6b2c62

Please sign in to comment.