Skip to content

Commit

Permalink
feat: Added a new flag allowing to disable tests on Jenkins. Added th…
Browse files Browse the repository at this point in the history
…is to the flaky OPC-UA tests and re-enabled them.
  • Loading branch information
chrisdutz committed Mar 18, 2024
1 parent 9ce5a2f commit b26b686
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Integer, Entry<PrivateKey, X509Certificate>> CERTIFICATES = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
}
Original file line number Diff line number Diff line change
@@ -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");
}

}

0 comments on commit b26b686

Please sign in to comment.