Skip to content

Commit 65367c7

Browse files
author
Ace Nassri
authored
chore(functions): fix flaky tests + update dir property (GoogleCloudPlatform#5305)
* chore(functions): fix flaky tests + update dir property * Remove debugging change * Add requested comment * Double underscore -> single letter param
1 parent bc9cdb8 commit 65367c7

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

functions/helloworld/hello-gcs/src/test/java/functions/ExampleIT.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public class ExampleIT {
5555
@BeforeClass
5656
public static void setUp() throws IOException {
5757
// Get the sample's base directory (the one containing a pom.xml file)
58-
String baseDir = System.getProperty("basedir");
58+
String baseDir = System.getProperty("user.dir");
5959

6060
// Emulate the function locally by running the Functions Framework Maven plugin
6161
emulatorProcess = new ProcessBuilder()
@@ -93,6 +93,15 @@ public void helloGcs_shouldRunWithFunctionsFramework() throws Throwable {
9393
RetryRegistry registry = RetryRegistry.of(RetryConfig.custom()
9494
.maxAttempts(8)
9595
.retryExceptions(HttpHostConnectException.class)
96+
.retryOnResult(u -> {
97+
// Retry if the Functions Framework process has no stdout content
98+
// See `retryOnResultPredicate` here: https://resilience4j.readme.io/docs/retry
99+
try {
100+
return emulatorProcess.getErrorStream().available() == 0;
101+
} catch (IOException e) {
102+
return true;
103+
}
104+
})
96105
.intervalFunction(IntervalFunction.ofExponentialBackoff(200, 2))
97106
.build());
98107
Retry retry = registry.retry("my");

functions/helloworld/hello-http/src/test/java/functions/ExampleIT.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class ExampleIT {
4949
@BeforeClass
5050
public static void setUp() throws IOException {
5151
// Get the sample's base directory (the one containing a pom.xml file)
52-
String baseDir = System.getProperty("basedir");
52+
String baseDir = System.getProperty("user.dir");
5353

5454
// Emulate the function locally by running the Functions Framework Maven plugin
5555
emulatorProcess = new ProcessBuilder()
@@ -72,10 +72,12 @@ public void helloHttp_shouldRunWithFunctionsFramework() throws Throwable {
7272

7373
// The Functions Framework Maven plugin process takes time to start up
7474
// Use resilience4j to retry the test HTTP request until the plugin responds
75+
// See `retryOnResultPredicate` here: https://resilience4j.readme.io/docs/retry
7576
RetryRegistry registry = RetryRegistry.of(RetryConfig.custom()
7677
.maxAttempts(8)
7778
.intervalFunction(IntervalFunction.ofExponentialBackoff(200, 2))
7879
.retryExceptions(IOException.class)
80+
.retryOnResult(body -> body.toString().length() == 0)
7981
.build());
8082
Retry retry = registry.retry("my");
8183

functions/helloworld/hello-pubsub/src/test/java/functions/ExampleIT.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class ExampleIT {
5656
@BeforeClass
5757
public static void setUp() throws IOException {
5858
// Get the sample's base directory (the one containing a pom.xml file)
59-
String baseDir = System.getProperty("basedir");
59+
String baseDir = System.getProperty("user.dir");
6060

6161
// Emulate the function locally by running the Functions Framework Maven plugin
6262
emulatorProcess = new ProcessBuilder()
@@ -91,6 +91,15 @@ public void helloPubSub_shouldRunWithFunctionsFramework() throws Throwable {
9191
RetryRegistry registry = RetryRegistry.of(RetryConfig.custom()
9292
.maxAttempts(8)
9393
.retryExceptions(HttpHostConnectException.class)
94+
.retryOnResult(u -> {
95+
// Retry if the Functions Framework process has no stdout content
96+
// See `retryOnResultPredicate` here: https://resilience4j.readme.io/docs/retry
97+
try {
98+
return emulatorProcess.getErrorStream().available() == 0;
99+
} catch (IOException e) {
100+
return true;
101+
}
102+
})
94103
.intervalFunction(IntervalFunction.ofExponentialBackoff(200, 2))
95104
.build());
96105
Retry retry = registry.retry("my");

0 commit comments

Comments
 (0)