diff --git a/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/OpcuaPlcDriverTest.java b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/OpcuaPlcDriverTest.java index 6e7ee0cb189..a9593ae4fad 100644 --- a/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/OpcuaPlcDriverTest.java +++ b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/OpcuaPlcDriverTest.java @@ -45,6 +45,7 @@ import org.apache.plc4x.java.opcua.security.MessageSecurity; import org.apache.plc4x.java.opcua.security.SecurityPolicy; import org.apache.plc4x.java.opcua.tag.OpcuaTag; +import org.apache.plc4x.test.DisableOnJenkinsFlag; import org.assertj.core.api.Condition; import org.assertj.core.api.SoftAssertions; import org.eclipse.milo.examples.server.TestMiloServer; @@ -66,7 +67,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; -@Disabled("Disabled as it seem this test only randomly succeeds on Jenkins") +@DisableOnJenkinsFlag public class OpcuaPlcDriverTest { private static final Logger LOGGER = LoggerFactory.getLogger(OpcuaPlcDriverTest.class); diff --git a/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/OpcuaSubscriptionHandleTest.java b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/OpcuaSubscriptionHandleTest.java index 0d2e825dba0..ba00609662d 100644 --- a/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/OpcuaSubscriptionHandleTest.java +++ b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/OpcuaSubscriptionHandleTest.java @@ -27,6 +27,7 @@ import org.apache.plc4x.java.api.types.PlcResponseCode; import org.apache.plc4x.java.opcua.OpcuaPlcDriverTest; import org.apache.plc4x.test.DisableInDockerFlag; +import org.apache.plc4x.test.DisableOnJenkinsFlag; import org.apache.plc4x.test.DisableOnParallelsVmFlag; import org.eclipse.milo.examples.server.ExampleServer; import org.junit.jupiter.api.*; @@ -53,7 +54,7 @@ // It's not a big issue as the GitHub runners and the Apache Jenkins still run the test. @DisableOnParallelsVmFlag @DisableInDockerFlag -@Disabled("Disabled as it seem this test only randomly succeeds on Jenkins") +@DisableOnJenkinsFlag public class OpcuaSubscriptionHandleTest { private static final Logger LOGGER = LoggerFactory.getLogger(OpcuaPlcDriverTest.class); diff --git a/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/chunk/ChunkFactoryTest.java b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/chunk/ChunkFactoryTest.java index 484bcaf5c7f..b97632b1a1d 100644 --- a/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/chunk/ChunkFactoryTest.java +++ b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/chunk/ChunkFactoryTest.java @@ -30,12 +30,12 @@ import org.apache.plc4x.java.opcua.readwrite.MessageSecurityMode; import org.apache.plc4x.java.opcua.readwrite.OpcuaProtocolLimits; import org.apache.plc4x.java.opcua.security.SecurityPolicy; +import org.apache.plc4x.test.DisableOnJenkinsFlag; import org.junit.jupiter.api.Assumptions; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvFileSource; -@Disabled("Disabled as it seem this test only randomly succeeds on Jenkins") +@DisableOnJenkinsFlag class ChunkFactoryTest { public static final Map> CERTIFICATES = new HashMap<>(); diff --git a/plc4j/utils/test-utils/src/main/java/org/apache/plc4x/test/DisableOnJenkinsFlag.java b/plc4j/utils/test-utils/src/main/java/org/apache/plc4x/test/DisableOnJenkinsFlag.java new file mode 100644 index 00000000000..f72ff7e8bba --- /dev/null +++ b/plc4j/utils/test-utils/src/main/java/org/apache/plc4x/test/DisableOnJenkinsFlag.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.plc4x.test; + +import org.junit.jupiter.api.extension.ExtendWith; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Some tests seem to only fail or block when run on Jenkins. + * Instead of trying to fix this problem, we'll try this for the + * time till someone finds the problem. + */ +@Target({ElementType.TYPE, ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@ExtendWith(DisableOnJenkinsFlagCondition.class) +public @interface DisableOnJenkinsFlag { +} diff --git a/plc4j/utils/test-utils/src/main/java/org/apache/plc4x/test/DisableOnJenkinsFlagCondition.java b/plc4j/utils/test-utils/src/main/java/org/apache/plc4x/test/DisableOnJenkinsFlagCondition.java new file mode 100644 index 00000000000..95c550bb626 --- /dev/null +++ b/plc4j/utils/test-utils/src/main/java/org/apache/plc4x/test/DisableOnJenkinsFlagCondition.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.plc4x.test; + +import org.junit.jupiter.api.extension.ConditionEvaluationResult; +import org.junit.jupiter.api.extension.ExecutionCondition; +import org.junit.jupiter.api.extension.ExtensionContext; + +public class DisableOnJenkinsFlagCondition implements ExecutionCondition { + + private static final boolean isJenkins; + static { + // This environment variable is set in Jenkinsfile. + String propertyValue = System.getenv("PLC4X_BUILD_ON_JENKINS"); + isJenkins = "true".equalsIgnoreCase(propertyValue); + } + + @Override + public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext extensionContext) { + if(isJenkins) { + return ConditionEvaluationResult.disabled("Jenkins detected"); + } + return ConditionEvaluationResult.enabled("Jenkins not detected"); + } + +}