Skip to content

Commit 2853033

Browse files
no-issue: disable tests conditionally when binary is not present (#1191)
* no-issue: disable tests conditionally when binary is not present Signed-off-by: Ricardo Zanini <ricardozanini@gmail.com> * Remove utils Signed-off-by: Ricardo Zanini <ricardozanini@gmail.com> * Incorporating copilot comments Signed-off-by: Ricardo Zanini <ricardozanini@gmail.com> * Check protoc via jar first Signed-off-by: Ricardo Zanini <ricardozanini@gmail.com> * Adding Javi's comment Signed-off-by: Ricardo Zanini <ricardozanini@gmail.com> * Fixing leftovers Signed-off-by: Ricardo Zanini <ricardozanini@gmail.com> --------- Signed-off-by: Ricardo Zanini <ricardozanini@gmail.com>
1 parent b9351b2 commit 2853033

11 files changed

Lines changed: 209 additions & 0 deletions

impl/test/src/test/java/io/serverlessworkflow/impl/test/CustomFunctionTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import io.serverlessworkflow.impl.WorkflowApplication;
2323
import io.serverlessworkflow.impl.WorkflowException;
24+
import io.serverlessworkflow.impl.test.junit.DisabledIfPythonUnavailable;
2425
import java.io.IOException;
2526
import java.util.Map;
2627
import org.junit.jupiter.api.AfterAll;
@@ -58,6 +59,7 @@ void testCustomFunction() {
5859
.isEqualTo(404);
5960
}
6061

62+
@DisabledIfPythonUnavailable()
6163
@ParameterizedTest
6264
@ValueSource(
6365
strings = {

impl/test/src/test/java/io/serverlessworkflow/impl/test/grpc/GrpcBiDirectionalStreamingTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import io.serverlessworkflow.impl.WorkflowDefinition;
2424
import io.serverlessworkflow.impl.WorkflowModel;
2525
import io.serverlessworkflow.impl.test.grpc.handlers.ContributorBiDiStreamingHandler;
26+
import io.serverlessworkflow.impl.test.junit.DisabledIfProtocUnavailable;
2627
import java.io.IOException;
2728
import java.util.Collection;
2829
import java.util.Map;
@@ -31,6 +32,7 @@
3132
import org.junit.jupiter.api.BeforeAll;
3233
import org.junit.jupiter.api.Test;
3334

35+
@DisabledIfProtocUnavailable
3436
public class GrpcBiDirectionalStreamingTest {
3537

3638
private static final int PORT_FOR_EXAMPLES = 5011;

impl/test/src/test/java/io/serverlessworkflow/impl/test/grpc/GrpcClientStreamingTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import io.serverlessworkflow.impl.WorkflowApplication;
2323
import io.serverlessworkflow.impl.WorkflowDefinition;
2424
import io.serverlessworkflow.impl.test.grpc.handlers.ContributorClientStreamingHandler;
25+
import io.serverlessworkflow.impl.test.junit.DisabledIfProtocUnavailable;
2526
import java.io.IOException;
2627
import java.util.List;
2728
import java.util.Map;
@@ -30,6 +31,7 @@
3031
import org.junit.jupiter.api.BeforeAll;
3132
import org.junit.jupiter.api.Test;
3233

34+
@DisabledIfProtocUnavailable
3335
public class GrpcClientStreamingTest {
3436

3537
private static final int PORT_FOR_EXAMPLES = 5011;

impl/test/src/test/java/io/serverlessworkflow/impl/test/grpc/GrpcServerStreamingTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import io.serverlessworkflow.impl.WorkflowDefinition;
2424
import io.serverlessworkflow.impl.WorkflowModel;
2525
import io.serverlessworkflow.impl.test.grpc.handlers.ContributorServerStreamingHandler;
26+
import io.serverlessworkflow.impl.test.junit.DisabledIfProtocUnavailable;
2627
import java.io.IOException;
2728
import java.util.Collection;
2829
import java.util.Map;
@@ -31,6 +32,7 @@
3132
import org.junit.jupiter.api.BeforeAll;
3233
import org.junit.jupiter.api.Test;
3334

35+
@DisabledIfProtocUnavailable
3436
public class GrpcServerStreamingTest {
3537

3638
private static final int PORT_FOR_EXAMPLES = 5011;

impl/test/src/test/java/io/serverlessworkflow/impl/test/grpc/GrpcUnaryArgsExprTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@
2222
import io.serverlessworkflow.impl.WorkflowApplication;
2323
import io.serverlessworkflow.impl.WorkflowDefinition;
2424
import io.serverlessworkflow.impl.test.grpc.handlers.ContributorUnaryArgsExprHandler;
25+
import io.serverlessworkflow.impl.test.junit.DisabledIfProtocUnavailable;
2526
import java.io.IOException;
2627
import java.util.Map;
2728
import org.assertj.core.api.Assertions;
2829
import org.junit.jupiter.api.AfterEach;
2930
import org.junit.jupiter.api.BeforeAll;
3031
import org.junit.jupiter.api.Test;
3132

33+
@DisabledIfProtocUnavailable
3234
public class GrpcUnaryArgsExprTest {
3335

3436
private static final int PORT_FOR_EXAMPLES = 5011;

impl/test/src/test/java/io/serverlessworkflow/impl/test/grpc/GrpcUnaryTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@
2222
import io.serverlessworkflow.impl.WorkflowApplication;
2323
import io.serverlessworkflow.impl.WorkflowDefinition;
2424
import io.serverlessworkflow.impl.test.grpc.handlers.PersonUnaryHandler;
25+
import io.serverlessworkflow.impl.test.junit.DisabledIfProtocUnavailable;
2526
import java.io.IOException;
2627
import java.util.Map;
2728
import org.assertj.core.api.Assertions;
2829
import org.junit.jupiter.api.AfterEach;
2930
import org.junit.jupiter.api.BeforeAll;
3031
import org.junit.jupiter.api.Test;
3132

33+
@DisabledIfProtocUnavailable
3234
public class GrpcUnaryTest {
3335

3436
private static final int PORT_FOR_EXAMPLES = 5011;
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright 2020-Present The Serverless Workflow Specification Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.serverlessworkflow.impl.test.junit;
17+
18+
import java.io.IOException;
19+
import java.util.concurrent.ConcurrentHashMap;
20+
import java.util.concurrent.ConcurrentMap;
21+
import java.util.concurrent.TimeUnit;
22+
23+
public final class BinaryCheckUtil {
24+
25+
private static final ConcurrentMap<String, Boolean> BINARY_CHECKS = new ConcurrentHashMap<>();
26+
27+
private BinaryCheckUtil() {}
28+
29+
public static boolean isBinaryAvailable(String... command) {
30+
return BINARY_CHECKS.computeIfAbsent(
31+
String.join(" ", command),
32+
__ -> {
33+
Process process;
34+
try {
35+
process =
36+
new ProcessBuilder(command)
37+
.redirectErrorStream(true)
38+
.redirectOutput(ProcessBuilder.Redirect.DISCARD)
39+
.start();
40+
} catch (IOException e) {
41+
return false;
42+
}
43+
try {
44+
return process.waitFor(2, TimeUnit.SECONDS) && process.exitValue() == 0;
45+
} catch (InterruptedException e) {
46+
Thread.currentThread().interrupt();
47+
return false;
48+
} finally {
49+
process.destroyForcibly();
50+
}
51+
});
52+
}
53+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2020-Present The Serverless Workflow Specification Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.serverlessworkflow.impl.test.junit;
17+
18+
import java.lang.annotation.ElementType;
19+
import java.lang.annotation.Retention;
20+
import java.lang.annotation.RetentionPolicy;
21+
import java.lang.annotation.Target;
22+
import org.junit.jupiter.api.extension.ExtendWith;
23+
24+
@Target({ElementType.TYPE, ElementType.METHOD})
25+
@Retention(RetentionPolicy.RUNTIME)
26+
@ExtendWith(ProtocCheckCondition.class)
27+
public @interface DisabledIfProtocUnavailable {}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2020-Present The Serverless Workflow Specification Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.serverlessworkflow.impl.test.junit;
17+
18+
import java.lang.annotation.ElementType;
19+
import java.lang.annotation.Retention;
20+
import java.lang.annotation.RetentionPolicy;
21+
import java.lang.annotation.Target;
22+
import org.junit.jupiter.api.extension.ExtendWith;
23+
24+
@Target({ElementType.TYPE, ElementType.METHOD})
25+
@Retention(RetentionPolicy.RUNTIME)
26+
@ExtendWith(PythonCheckCondition.class)
27+
public @interface DisabledIfPythonUnavailable {}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright 2020-Present The Serverless Workflow Specification Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.serverlessworkflow.impl.test.junit;
17+
18+
import static io.serverlessworkflow.impl.test.junit.BinaryCheckUtil.isBinaryAvailable;
19+
20+
import com.github.os72.protocjar.Protoc;
21+
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
22+
import org.junit.jupiter.api.extension.ExecutionCondition;
23+
import org.junit.jupiter.api.extension.ExtensionContext;
24+
import org.junit.platform.commons.util.AnnotationUtils;
25+
26+
public class ProtocCheckCondition implements ExecutionCondition {
27+
28+
private static boolean protocAvailable = false;
29+
30+
static {
31+
try {
32+
protocAvailable = Protoc.runProtoc(new String[] {"--version"}) == 0;
33+
} catch (Exception e) {
34+
// ignore
35+
}
36+
if (!protocAvailable) {
37+
protocAvailable = isBinaryAvailable("protoc", "--version");
38+
}
39+
}
40+
41+
@Override
42+
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
43+
return AnnotationUtils.findAnnotation(context.getElement(), DisabledIfProtocUnavailable.class)
44+
.map(
45+
annotation ->
46+
protocAvailable
47+
? ConditionEvaluationResult.enabled(
48+
"Protoc is available for the current platform.")
49+
: ConditionEvaluationResult.disabled(
50+
"Test disabled: Protoc not currently available not found."))
51+
.orElse(ConditionEvaluationResult.enabled("No @DisabledIfProtocUnavailable found."));
52+
}
53+
}

0 commit comments

Comments
 (0)