From 033f9701c08d9ede1634e12ab884416f9e320995 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20K=C3=B6rber?= Date: Sun, 25 May 2025 15:44:18 +0200 Subject: [PATCH] Make some IT soft-fail --- .../org/shredzone/acme4j/it/ProviderIT.java | 4 +- .../org/shredzone/acme4j/it/SoftFail.java | 38 +++++++++++++++++++ .../acme4j/it/SoftFailExtension.java | 34 +++++++++++++++++ 3 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 acme4j-it/src/test/java/org/shredzone/acme4j/it/SoftFail.java create mode 100644 acme4j-it/src/test/java/org/shredzone/acme4j/it/SoftFailExtension.java diff --git a/acme4j-it/src/test/java/org/shredzone/acme4j/it/ProviderIT.java b/acme4j-it/src/test/java/org/shredzone/acme4j/it/ProviderIT.java index 21281edf..fcbeccc4 100644 --- a/acme4j-it/src/test/java/org/shredzone/acme4j/it/ProviderIT.java +++ b/acme4j-it/src/test/java/org/shredzone/acme4j/it/ProviderIT.java @@ -20,7 +20,6 @@ import java.net.MalformedURLException; import java.net.URI; import java.time.Duration; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.shredzone.acme4j.Session; import org.shredzone.acme4j.connector.Resource; @@ -140,7 +139,7 @@ public class ProviderIT { * Test ssl.com, staging server */ @Test - @Disabled("Instable due to frequent certificate expiration of acme-try.ssl.com") + @SoftFail("Frequent certificate expiration of acme-try.ssl.com") public void testSslComStaging() throws AcmeException, MalformedURLException { var sessionEccStage = new Session("acme://ssl.com/staging/ecc"); assertThat(sessionEccStage.getMetadata().getWebsite()).hasValue(URI.create("https://www.ssl.com").toURL()); @@ -166,6 +165,7 @@ public class ProviderIT { * Test ZeroSSL */ @Test + @SoftFail("Frequent network timeouts or HTTP errors") public void testZeroSsl() throws AcmeException, MalformedURLException { var session = new Session("acme://zerossl.com"); session.networkSettings().setTimeout(Duration.ofSeconds(120L)); diff --git a/acme4j-it/src/test/java/org/shredzone/acme4j/it/SoftFail.java b/acme4j-it/src/test/java/org/shredzone/acme4j/it/SoftFail.java new file mode 100644 index 00000000..d9557358 --- /dev/null +++ b/acme4j-it/src/test/java/org/shredzone/acme4j/it/SoftFail.java @@ -0,0 +1,38 @@ +/* + * acme4j - Java ACME client + * + * Copyright (C) 2025 Richard "Shred" Körber + * http://acme4j.shredzone.org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + */ +package org.shredzone.acme4j.it; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.junit.jupiter.api.extension.ExtendWith; +import org.shredzone.acme4j.exception.AcmeException; + +/** + * Marks a test to fail softly if an {@link AcmeException} is thrown. These are usually + * integration tests that fail frequently because the external server has stability + * issues. + */ +@Retention(RUNTIME) +@Target(METHOD) +@ExtendWith(SoftFailExtension.class) +public @interface SoftFail { + /** + * A human-readable reason why this test is marked as soft fail. + */ + String value(); +} diff --git a/acme4j-it/src/test/java/org/shredzone/acme4j/it/SoftFailExtension.java b/acme4j-it/src/test/java/org/shredzone/acme4j/it/SoftFailExtension.java new file mode 100644 index 00000000..26a878fb --- /dev/null +++ b/acme4j-it/src/test/java/org/shredzone/acme4j/it/SoftFailExtension.java @@ -0,0 +1,34 @@ +/* + * acme4j - Java ACME client + * + * Copyright (C) 2025 Richard "Shred" Körber + * http://acme4j.shredzone.org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + */ +package org.shredzone.acme4j.it; + +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.api.extension.TestExecutionExceptionHandler; +import org.opentest4j.TestAbortedException; +import org.shredzone.acme4j.exception.AcmeException; + +/** + * Aborts a @{@link SoftFail} annotated test when an {@link AcmeException} is thrown. + */ +public class SoftFailExtension implements TestExecutionExceptionHandler { + @Override + public void handleTestExecutionException(ExtensionContext ctx, Throwable ex) + throws Throwable { + if (ex instanceof AcmeException) { + throw new TestAbortedException("SOFT FAIL: " + ctx.getDisplayName() + + " - " + ex.getMessage(), ex); + } + throw ex; + } +}