Skip to content

Commit

Permalink
Add try/catch to find the problem of the flaky test
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Feb 10, 2022
1 parent ed0437b commit 2f02051
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.opentripplanner.routing.algorithm.raptor.router;

import java.time.Duration;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -178,13 +177,7 @@ private AccessEgresses getAccessEgresses(
CompletableFuture.runAsync(egressCalculator)
).join();
} catch (CompletionException e) {
if (e.getCause() instanceof RoutingValidationException) {
throw (RoutingValidationException) e.getCause();
} else if (e.getCause() instanceof RuntimeException) {
LOG.warn("Unknown exception from access/egress calculation", e.getCause());
throw (RuntimeException) e.getCause();
}
throw e;
RoutingValidationException.unwrapAndRethrowCompletionException(e);
}
} else {
accessCalculator.run();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.opentripplanner.routing.error;

import java.util.concurrent.CompletionException;
import org.opentripplanner.routing.api.response.RoutingError;

import java.util.List;
Expand All @@ -21,4 +22,13 @@ public RoutingValidationException(List<RoutingError> routingErrors) {
public List<RoutingError> getRoutingErrors() {
return routingErrors;
}

public static void unwrapAndRethrowCompletionException(CompletionException e) {
if (e.getCause() instanceof RoutingValidationException) {
throw (RoutingValidationException) e.getCause();
} else if (e.getCause() instanceof RuntimeException) {
throw (RuntimeException) e.getCause();
}
throw e;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import au.com.origin.snapshots.junit5.SnapshotExtension;
import java.util.Locale;
import java.util.Set;
import java.util.concurrent.CompletionException;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
Expand All @@ -15,6 +16,7 @@
import org.opentripplanner.routing.api.request.RequestModes;
import org.opentripplanner.routing.api.request.RoutingRequest;
import org.opentripplanner.routing.api.request.StreetMode;
import org.opentripplanner.routing.error.RoutingValidationException;

@ExtendWith(SnapshotExtension.class)
@ResourceLock(Resources.LOCALE)
Expand Down Expand Up @@ -105,7 +107,11 @@ public void directBikeRental() {
request.from = p1;
request.to = p3;

expectArriveByToMatchDepartAtAndSnapshot(request);
try {
expectArriveByToMatchDepartAtAndSnapshot(request);
} catch (CompletionException e) {
RoutingValidationException.unwrapAndRethrowCompletionException(e);
}
}

@DisplayName("Egress BIKE_RENTAL")
Expand Down

0 comments on commit 2f02051

Please sign in to comment.