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

fix thread count issue when using karate.options #2444 #2481

Merged
merged 1 commit into from
Jan 20, 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
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);
}
}