This is an automated email from the ASF dual-hosted git repository.

cdutz pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git


The following commit(s) were added to refs/heads/develop by this push:
     new b26b686eee feat: Added a new flag allowing to disable tests on 
Jenkins. Added this to the flaky OPC-UA tests and re-enabled them.
b26b686eee is described below

commit b26b686eeec526d2ed528a27f0fc389215fa71f3
Author: Christofer Dutz <cd...@apache.org>
AuthorDate: Mon Mar 18 16:57:13 2024 +0100

    feat: Added a new flag allowing to disable tests on Jenkins. Added this to 
the flaky OPC-UA tests and re-enabled them.
---
 .../plc4x/java/opcua/OpcuaPlcDriverTest.java       |  3 +-
 .../protocol/OpcuaSubscriptionHandleTest.java      |  3 +-
 .../opcua/protocol/chunk/ChunkFactoryTest.java     |  4 +--
 .../apache/plc4x/test/DisableOnJenkinsFlag.java    | 37 +++++++++++++++++++
 .../plc4x/test/DisableOnJenkinsFlagCondition.java  | 42 ++++++++++++++++++++++
 5 files changed, 85 insertions(+), 4 deletions(-)

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 6e7ee0cb18..a9593ae4fa 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.api.types.PlcResponseCode;
 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 java.util.Map.entry;
 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 0d2e825dba..ba00609662 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.messages.PlcSubscriptionResponse;
 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 @@ import static org.junit.jupiter.api.Assertions.fail;
 // 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 484bcaf5c7..b97632b1a1 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.TestCertificateGenerator;
 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<Integer, Entry<PrivateKey, X509Certificate>> 
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 0000000000..f72ff7e8bb
--- /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 0000000000..95c550bb62
--- /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");
+    }
+
+}

Reply via email to