Skip to content

Commit

Permalink
Fix no valid test when sharding (#268)
Browse files Browse the repository at this point in the history
* Allow shards with no tests without error

* update default to check --changed-since

* Clarify number of actual tests vs number of files with tests

* Revert "update default to check --changed-since"

This reverts commit cd77749.

* fix

* test changed

* Fix error when trying to shard with no available tests

* revert testfile
  • Loading branch information
fellen31 authored Oct 25, 2024
1 parent c6fe219 commit 74a283f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
21 changes: 10 additions & 11 deletions src/main/java/com/askimed/nf/test/commands/RunTestsCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,16 +243,6 @@ public Integer execute() throws Exception {
DependencyExporter.generateDotFile(resolver, graph);
}


if (scripts.isEmpty()) {
System.out.println(AnsiColors
.yellow("No tests to execute."));
log.warn("No tests or directories found containing test files. Or all testcases were filtered.");
return 0;
} else {
log.info("Detected {} test files.", scripts.size());
}

loadPlugins(manager, plugins);

GroupTestExecutionListener listener = setupExecutionListeners();
Expand All @@ -267,13 +257,22 @@ public Integer execute() throws Exception {
List<ITestSuite> testSuits = testSuiteResolver.parse(scripts, new TagQuery(tags));

testSuits.sort(TestSuiteSorter.getDefault());
if (shard != null) {
if (shard != null && !testSuits.isEmpty()) {
if (shardStrategy.equalsIgnoreCase(SHARD_STRATEGY_ROUND_ROBIN)){
testSuits = TestSuiteSharder.shardWithRoundRobin(testSuits, shard);
} else {
testSuits = TestSuiteSharder.shard(testSuits, shard);
}
}

int totalTests = testSuits.stream().mapToInt(testSuite -> testSuite.getTests().size()).sum();
log.info("Found {} tests to execute.", totalTests);

if (testSuits.isEmpty()) {
System.out.println(AnsiColors
.yellow("No tests to execute."));
return 0;
}

TestExecutionEngine engine = new TestExecutionEngine();
engine.setListener(listener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public List<File> findAllTests() throws Exception {
}
}

log.info("Found {} tests.", results.size());
log.info("Found {} files containing tests.", results.size());

return results;
}
Expand All @@ -80,8 +80,8 @@ public List<File> findTestsByFiles(List<File> files) throws Exception {
}
}

log.info("Found {} tests.", results.size());
log.debug("Found tests: " + results);
log.info("Found {} files containing tests.", results.size());
log.debug("Found files: " + results);

return results;
}
Expand Down Expand Up @@ -111,7 +111,7 @@ public List<File> findRelatedTestsByFiles(File ... files) throws Exception {
results.addAll(findRelatedTestsByFile(file.getAbsoluteFile()));
}
long time1 = System.currentTimeMillis();
log.info("Found {} tests for file {} in {} sec", results.size(), files, (time1 - time0) / 1000.0);
log.info("Found {} files containing tests for file {} in {} sec", results.size(), files, (time1 - time0) / 1000.0);

return new Vector<File>(results);
}
Expand Down

0 comments on commit 74a283f

Please sign in to comment.