Skip to content

Commit

Permalink
fix: Made sure the OpcuaSubscriptionHandleTest doesn't run on Docker.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdutz committed Oct 2, 2023
1 parent e4dec50 commit a5e78c8
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,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.DisableOnParallelsVmFlag;
import org.eclipse.milo.examples.server.ExampleServer;
import org.junit.jupiter.api.*;
Expand All @@ -42,6 +43,7 @@
// I tracked it down into the core of Milo several times now, but got lost in there.
// It's not a big issue as the GitHub runners and the Apache Jenkins still run the test.
@DisableOnParallelsVmFlag
@DisableInDockerFlag
public class OpcuaSubscriptionHandleTest {

private static final Logger LOGGER = LoggerFactory.getLogger(OpcuaPlcDriverTest.class);
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 in Docker.
* 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(DisableInDockerFlagCondition.class)
public @interface DisableInDockerFlag {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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.apache.commons.lang3.SystemUtils;
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
import org.junit.jupiter.api.extension.ExecutionCondition;
import org.junit.jupiter.api.extension.ExtensionContext;

import java.io.*;

public class DisableInDockerFlagCondition implements ExecutionCondition {

private static final boolean isDocker;
static {
boolean localIsDocker = false;
if (SystemUtils.IS_OS_LINUX) {
File dockerEnvFile = new File("/.dockerenv");
if(dockerEnvFile.exists()) {
localIsDocker = true;
}
}
isDocker = localIsDocker;
}

@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext extensionContext) {
if(isDocker) {
return ConditionEvaluationResult.disabled("Docker detected");
}
return ConditionEvaluationResult.enabled("Docker not detected");
}

}

0 comments on commit a5e78c8

Please sign in to comment.