-
Notifications
You must be signed in to change notification settings - Fork 28
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
Catch known exceptions (broken pipe) #1042
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.quarkus.test.listener; | ||
|
||
import org.junit.jupiter.api.Assumptions; | ||
import org.junit.jupiter.api.extension.ExtensionContext; | ||
import org.junit.jupiter.api.extension.TestExecutionExceptionHandler; | ||
|
||
import io.quarkus.test.logging.Log; | ||
import io.quarkus.test.utils.KnownExceptionChecker; | ||
|
||
/** | ||
* Extension is masking exceptions, caused by known issues which cannot be easily disabled. | ||
* Originally created for <a href="https://github.com/quarkusio/quarkus/issues/38334">Broken pipe</a> issue. | ||
* In case that related exception is thrown, this extension will swallow it, and make test marked as skipped. | ||
*/ | ||
public class QuarkusTestExceptionFilter implements TestExecutionExceptionHandler { | ||
|
||
@Override | ||
public void handleTestExecutionException(ExtensionContext context, Throwable throwable) throws Throwable { | ||
// if exception is caused by known issue, swallow it, otherwise propagate it | ||
if (KnownExceptionChecker.checkForKnownException(throwable)) { | ||
Log.error("Skipping test " + context.getDisplayName() + " known exception found. Printing stack trace"); | ||
throwable.printStackTrace(); | ||
// skip the test | ||
Assumptions.abort(); | ||
} else { | ||
throw throwable; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package io.quarkus.test.utils; | ||
|
||
import java.util.List; | ||
|
||
public final class KnownExceptionChecker { | ||
/** | ||
* List of known exception messages. If you want to mask any exception, add its message here | ||
*/ | ||
private static final List<String> KNOWN_EXCEPTION_MESSAGES = List.of("Broken pipe"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the approach of making this a Junit extension, but I really think this bit should be configurable from testsuite or command line. Can it be configured from properties? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 though it's hard to combine with my suggestion, you can treat it as one of, I'll leave it on you |
||
|
||
private KnownExceptionChecker() { | ||
} | ||
|
||
/** | ||
* Check if thrown message contains any of the known exception messages. | ||
* Method is recursive, it will check the exception itself and all causes and suppressed ones as well. | ||
* | ||
* @param throwable Exception to check | ||
* @return true if any known exception message is included, false otherwise | ||
*/ | ||
public static boolean checkForKnownException(Throwable throwable) { | ||
if (KNOWN_EXCEPTION_MESSAGES.stream().anyMatch(throwable.getMessage()::contains)) { | ||
return true; | ||
} | ||
if (throwable.getCause() != null && checkForKnownException(throwable.getCause())) { | ||
return true; | ||
} | ||
for (Throwable t : throwable.getSuppressed()) { | ||
if (checkForKnownException(t)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
Broken pipe
will be included in the issues we are experiencing now on Podman, but if we ever experience it in a different context then we do right now, it will be logged and skipped. I won't pretend I really do read logs of green jobs.This, very unlikely, could hide problems. I'm not sure about:
Maybe you could make it a predicate consuming throwable?