Skip to content

Commit

Permalink
Merge pull request #5766 from pkriens/issue/5715-indefinitely-waiting…
Browse files Browse the repository at this point in the history
…-for-tests

Moved check for empty queue to top
  • Loading branch information
pkriens authored Sep 5, 2023
2 parents abdead0 + 4061cd3 commit d642f12
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -338,19 +338,29 @@ public void removedBundle(Bundle bundle, BundleEvent event, Bundle object) {

trace("starting queue");
long result = 0;
long timeout = continuous ? Long.MAX_VALUE : 5000;
while (active()) {
try {
List<DiscoverySelector> selectors = new ArrayList<>();
for (DiscoverySelector selector = queue.takeFirst(); //

//
// it would be more logical to check for an empty queue here
// and !continuous but many tests cases assume that we
// will wait for at least 1 test case.
//

for (DiscoverySelector selector = queue.pollFirst(timeout, TimeUnit.MILLISECONDS); //
selector != null; //
selector = queue.pollFirst(100, TimeUnit.MILLISECONDS)) {
selectors.add(selector);
queue.drainTo(selectors);
}
LauncherDiscoveryRequest testRequest = buildRequest(selectors);
trace("test will run");
result += test(testRequest);
trace("test ran");
if (!selectors.isEmpty()) {
LauncherDiscoveryRequest testRequest = buildRequest(selectors);
trace("test will run");
result += test(testRequest);
trace("test ran");
}
if (queue.isEmpty() && !continuous) {
trace("queue %s", queue);
BndSystem.exit((int) result);
Expand Down
23 changes: 17 additions & 6 deletions biz.aQute.tester/src/aQute/junit/Activator.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.Set;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
import java.util.regex.Pattern;
import java.util.stream.Stream;
Expand Down Expand Up @@ -258,14 +259,24 @@ public void removedBundle(Bundle bundle, BundleEvent event, Bundle object) {

trace("starting queue");
int result = 0;
long timeout = continuous ? Long.MAX_VALUE : 5000;
while (active()) {
try {
Bundle bundle = queue.takeFirst();
trace("received bundle to test: %s", bundle.getLocation());
try (Writer report = getReportWriter(reportDir, bundleReportName(bundle))) {
trace("test will run");
result += test(bundle, testCases(bundle), report);
trace("test ran");

//
// it would be more logical to check for an empty queue here
// and !continuous but many tests cases assume that we
// will wait for at least 1 test case.
//

Bundle bundle = queue.pollFirst(timeout, TimeUnit.MILLISECONDS);
if (bundle != null) {
trace("received bundle to test: %s", bundle.getLocation());
try (Writer report = getReportWriter(reportDir, bundleReportName(bundle))) {
trace("test will run");
result += test(bundle, testCases(bundle), report);
trace("test ran");
}
}
if (queue.isEmpty() && !continuous) {
trace("queue %s", queue);
Expand Down

0 comments on commit d642f12

Please sign in to comment.