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

Catch known exceptions (broken pipe) #1042

Merged
merged 2 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import jakarta.inject.Inject;

import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.extension.AfterAllCallback;
import org.junit.jupiter.api.extension.AfterEachCallback;
import org.junit.jupiter.api.extension.BeforeAllCallback;
Expand All @@ -26,6 +27,7 @@
import io.quarkus.test.configuration.PropertyLookup;
import io.quarkus.test.logging.Log;
import io.quarkus.test.services.quarkus.ProdQuarkusApplicationManagedResourceBuilder;
import io.quarkus.test.utils.KnownExceptionChecker;
import io.quarkus.test.utils.ReflectionUtils;

public class QuarkusScenarioBootstrap
Expand Down Expand Up @@ -168,6 +170,18 @@ private void launchService(Service service) {
extensions.forEach(ext -> ext.onServiceLaunch(scenario, service));
try {
service.start();
} catch (RuntimeException runtimeException) {
// catch known failures is service launch.
// mostly searching for "Broken pipe" failure - https://github.com/quarkusio/quarkus/issues/38334
if (KnownExceptionChecker.checkForKnownException(runtimeException)) {
Log.error("Known exception catched, printing it");
runtimeException.printStackTrace();
// abort test execution
Assumptions.abort();
} else {
scenarioOnError(runtimeException);
throw runtimeException;
}
} catch (Throwable throwable) {
scenarioOnError(throwable);
throw throwable;
Expand Down
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
Expand Up @@ -9,12 +9,14 @@
import org.junit.jupiter.api.extension.ExtendWith;

import io.quarkus.test.bootstrap.QuarkusScenarioBootstrap;
import io.quarkus.test.listener.QuarkusTestExceptionFilter;
import io.quarkus.test.scenarios.execution.condition.QuarkusScenarioExecutionConditions;

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@ExtendWith(QuarkusScenarioBootstrap.class)
@ExtendWith(QuarkusScenarioExecutionConditions.class)
@ExtendWith(QuarkusTestExceptionFilter.class)
@Inherited
public @interface QuarkusScenario {
}
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");
Copy link
Member

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:

  1. plain string which doesn't allow for complex pattern like parts of stack trace
  2. if we go by log lines, you will probably have a hard time to determine what is in the stack trace as it is not one line?
  3. if we only experience this on Podman, you could only make it known problem on Podman. Our FW already knows whether it is Podman or Docker as we check it on every single run where containers are used.

Maybe you could make it a predicate consuming throwable?

Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Member

Choose a reason for hiding this comment

The 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
import org.junit.jupiter.api.extension.ExtendWith;

import io.quarkus.test.bootstrap.QuarkusScenarioBootstrap;
import io.quarkus.test.listener.QuarkusTestExceptionFilter;
import io.quarkus.test.services.Operator;

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@ExtendWith(QuarkusScenarioBootstrap.class)
@ExtendWith(QuarkusTestExceptionFilter.class)
@Inherited
public @interface OpenShiftScenario {
OpenShiftDeploymentStrategy deployment() default OpenShiftDeploymentStrategy.Build;
Expand Down
Loading