Skip to content

Commit 8e4378d

Browse files
chore: Fix flaky IT test cases (#8260)
* chore: Busy wait java-container CREATE operation to finish * chore: Delete any existing java-notebook instances * chore: Use ListInstanceRequest with parent * chore: Delete gapic compute instances * chore: Use ZonedDateTime for RFC3339 with Zone * chore: Setup the correct Request object field * chore: Create new IT profile * chore: Move shared deps profile to root pom.xml * chore: Use test lifecycle phase for graalvm tests * chore: Use old pom configs * chore: Use correct path to vision resources * chore: Remove unused pom.xml * chore: Move busy wait after CREATE operation * chore: Add specific names for IT compute instances * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * chore: Clean up compute instances names * chore: Clean up instances * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * chore: Add checks for deletion * chore: Add missing import * chore: Add missing import for notebooks Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent db7c7d1 commit 8e4378d

File tree

11 files changed

+144
-57
lines changed

11 files changed

+144
-57
lines changed

.kokoro/build.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ case ${JOB_TYPE} in
156156
-Penable-integration-tests \
157157
-Pnative \
158158
-fae \
159-
verify
159+
test
160160
RETURN_CODE=$?
161161
printf "Finished Unit and Integration Tests for GraalVM Native:\n%s\n" "${module_list}"
162162
else
@@ -182,7 +182,7 @@ case ${JOB_TYPE} in
182182
-Penable-integration-tests \
183183
-Pnative \
184184
-fae \
185-
verify
185+
test
186186
RETURN_CODE=$?
187187
printf "Finished Unit and Integration Tests for GraalVM Native 17:\n%s\n" "${module_list}"
188188
else

java-compute/google-cloud-compute/src/test/java/com/google/cloud/compute/v1/integration/BaseTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ public class BaseTest {
2222
protected static final String DEFAULT_PROJECT = ServiceOptions.getDefaultProjectId();
2323
protected static final String DEFAULT_ZONE = "us-central1-a";
2424
protected static final String DEFAULT_REGION = "us-west1";
25+
protected static final String COMPUTE_PREFIX = "it-test-compute";
2526

2627
public static String generateRandomName(String placeholder) {
27-
return "gapic-" + placeholder + UUID.randomUUID().toString().substring(0, 8);
28+
return COMPUTE_PREFIX + "-" + placeholder + "-" + UUID.randomUUID().toString().substring(0, 8);
2829
}
2930
}

java-compute/google-cloud-compute/src/test/java/com/google/cloud/compute/v1/integration/ITSmokeInstancesTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ public static void setUp() throws IOException {
7272
instances = new ArrayList<>();
7373
InstancesSettings instanceSettings = InstancesSettings.newBuilder().build();
7474
instancesClient = InstancesClient.create(instanceSettings);
75+
76+
Util.cleanUpComputeInstances(instancesClient, DEFAULT_PROJECT, DEFAULT_ZONE);
7577
}
7678

7779
@Before
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.google.cloud.compute.v1.integration;
2+
3+
import com.google.cloud.compute.v1.DeleteInstanceRequest;
4+
import com.google.cloud.compute.v1.Instance;
5+
import com.google.cloud.compute.v1.InstancesClient;
6+
import com.google.cloud.compute.v1.InstancesClient.ListPagedResponse;
7+
import java.time.Instant;
8+
import java.time.ZonedDateTime;
9+
import java.time.temporal.ChronoUnit;
10+
11+
public class Util {
12+
13+
// Cleans existing test resources if any.
14+
private static final int DELETION_THRESHOLD_TIME_HOURS = 24;
15+
16+
/** Bring down any instances that are older than 24 hours */
17+
public static void cleanUpComputeInstances(
18+
InstancesClient instancesClient, String project, String zone) {
19+
ListPagedResponse listPagedResponse = instancesClient.list(project, zone);
20+
for (Instance instance : listPagedResponse.iterateAll()) {
21+
if (isCreatedBeforeThresholdTime(
22+
ZonedDateTime.parse(instance.getCreationTimestamp()).toInstant())
23+
&& instance.getName().startsWith(BaseTest.COMPUTE_PREFIX)) {
24+
instancesClient.deleteAsync(
25+
DeleteInstanceRequest.newBuilder()
26+
.setInstance(instance.getName())
27+
.setProject(project)
28+
.setZone(zone)
29+
.build());
30+
}
31+
}
32+
}
33+
34+
private static boolean isCreatedBeforeThresholdTime(Instant instant) {
35+
return instant.isBefore(Instant.now().minus(DELETION_THRESHOLD_TIME_HOURS, ChronoUnit.HOURS));
36+
}
37+
}

java-container/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ If you are using Maven with [BOM][libraries-bom], add this to your pom.xml file:
1919
<dependency>
2020
<groupId>com.google.cloud</groupId>
2121
<artifactId>libraries-bom</artifactId>
22-
<version>26.1.0</version>
22+
<version>26.1.1</version>
2323
<type>pom</type>
2424
<scope>import</scope>
2525
</dependency>
@@ -49,7 +49,7 @@ If you are using Maven without BOM, add this to your dependencies:
4949
If you are using Gradle 5.x or later, add this to your dependencies:
5050

5151
```Groovy
52-
implementation platform('com.google.cloud:libraries-bom:26.1.0')
52+
implementation platform('com.google.cloud:libraries-bom:26.1.1')
5353
5454
implementation 'com.google.cloud:google-cloud-container'
5555
```

java-container/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/ITSystemTest.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.google.container.v1.ListOperationsResponse;
2727
import com.google.container.v1.NodePool;
2828
import com.google.container.v1.Operation;
29+
import com.google.container.v1.Operation.Status;
2930
import com.google.container.v1.ServerConfig;
3031
import java.util.List;
3132
import java.util.UUID;
@@ -37,16 +38,18 @@
3738

3839
public class ITSystemTest {
3940

41+
protected static final String CONTAINER_PREFIX = "it-test-container";
42+
4043
private static ClusterManagerClient client;
4144
private static Operation operation;
4245

4346
private static final Logger LOG = Logger.getLogger(ITSystemTest.class.getName());
4447
private static final String PROJECT_ID = ServiceOptions.getDefaultProjectId();
4548
private static final String ZONE = "us-central1-a";
4649
private static final String CLUSTER_NAME =
47-
"test-cluster-" + UUID.randomUUID().toString().substring(0, 8);
50+
CONTAINER_PREFIX + "-cluster-" + UUID.randomUUID().toString().substring(0, 8);
4851
private static final String NODE_POOL_NAME =
49-
"test-node-pool-" + UUID.randomUUID().toString().substring(0, 8);
52+
CONTAINER_PREFIX + "-node-pool-" + UUID.randomUUID().toString().substring(0, 8);
5053
private static final String DETAIL = "test-detail";
5154
private static final String STATUS_MESSAGE = "test-status-message";
5255
private static final String SELF_LINK =
@@ -63,7 +66,7 @@ public static void beforeClass() throws Exception {
6366
client = ClusterManagerClient.create();
6467
Util.cleanUpExistingInstanceCluster(PROJECT_ID, ZONE, client);
6568

66-
/** create node pool* */
69+
/* create node pool* */
6770
NodePool nodePool =
6871
NodePool.newBuilder()
6972
.setInitialNodeCount(INITIAL_NODE_COUNT)
@@ -72,7 +75,7 @@ public static void beforeClass() throws Exception {
7275
.setStatusMessage(STATUS_MESSAGE)
7376
.build();
7477

75-
/** create cluster */
78+
/* create cluster */
7679
Cluster cluster =
7780
Cluster.newBuilder()
7881
.setName(CLUSTER_NAME)
@@ -84,13 +87,20 @@ public static void beforeClass() throws Exception {
8487
.setNetwork(NETWORK)
8588
.build();
8689
operation = client.createCluster(PROJECT_ID, ZONE, cluster);
90+
91+
Operation response = client.getOperation(PROJECT_ID, ZONE, operation.getName());
92+
// Busy Wait for one minute at a time until Cluster CREATE operation is complete
93+
while (response.getStatus() != Status.DONE) {
94+
LOG.info(String.format("Cluster CREATE Operation Status: %s", response.getStatus()));
95+
Thread.sleep(TimeUnit.MINUTES.toMillis(1));
96+
response = client.getOperation(PROJECT_ID, ZONE, operation.getName());
97+
}
8798
LOG.info(String.format("%s cluster created successfully.", CLUSTER_NAME));
8899
LOG.info(String.format("%s node pool created successfully.", NODE_POOL_NAME));
89100
}
90101

91102
@AfterClass
92-
public static void afterClass() throws Exception {
93-
Thread.sleep(TimeUnit.MINUTES.toMillis(5));
103+
public static void afterClass() {
94104
client.deleteCluster(PROJECT_ID, ZONE, CLUSTER_NAME);
95105
LOG.info(String.format("%s cluster deleted successfully.", CLUSTER_NAME));
96106
client.close();

java-container/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/Util.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,26 @@
1919
import com.google.cloud.container.v1.ClusterManagerClient;
2020
import com.google.container.v1.Cluster;
2121
import com.google.container.v1.ListClustersResponse;
22-
import java.io.IOException;
2322
import java.time.Instant;
2423
import java.time.OffsetDateTime;
2524
import java.time.temporal.ChronoUnit;
2625
import java.util.List;
27-
import java.util.concurrent.ExecutionException;
2826

2927
public class Util {
28+
3029
// Cleans existing test resources if any.
3130
private static final int DELETION_THRESHOLD_TIME_HOURS = 24;
3231

3332
/** tear down any clusters that are older than 24 hours * */
3433
public static void cleanUpExistingInstanceCluster(
35-
String projectId, String zone, ClusterManagerClient client)
36-
throws IOException, ExecutionException, InterruptedException {
34+
String projectId, String zone, ClusterManagerClient client) {
3735

3836
ListClustersResponse clustersResponse = client.listClusters(projectId, zone);
3937
List<Cluster> clusters = clustersResponse.getClustersList();
4038

4139
for (Cluster cluster : clusters) {
42-
if (isCreatedBeforeThresholdTime(cluster.getCreateTime())) {
40+
if (isCreatedBeforeThresholdTime(cluster.getCreateTime())
41+
&& cluster.getName().startsWith(ITSystemTest.CONTAINER_PREFIX)) {
4342
client.deleteCluster(projectId, zone, cluster.getName());
4443
}
4544
}

java-notebooks/google-cloud-notebooks/src/test/java/com/google/cloud/notebooks/v1beta1/it/ITNotebookServiceClientTest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,15 @@
4848

4949
public class ITNotebookServiceClientTest {
5050

51+
protected static final String NOTEBOOK_PREFIX = "it-test-notebook";
52+
5153
private static final String PROJECT_ID = ServiceOptions.getDefaultProjectId();
5254
private static final String LOCATION = "us-central1-a";
5355
private static final String PARENT = "projects/" + PROJECT_ID + "/locations/" + LOCATION;
5456
private static NotebookServiceClient client;
5557
private static final String ID = UUID.randomUUID().toString().substring(0, 8);
56-
private static final String NOTEBOOK_INSTANCE_ID = "test-notebook-instance-id-" + ID;
57-
private static final String ENVIRONMENT_ID = "test-environment-id-" + ID;
58+
private static final String NOTEBOOK_INSTANCE_ID = NOTEBOOK_PREFIX + "-instance-id-" + ID;
59+
private static final String ENVIRONMENT_ID = NOTEBOOK_PREFIX + "-environment-id-" + ID;
5860
private static final String INSTANCE_NAME = PARENT + "/instances/" + NOTEBOOK_INSTANCE_ID;
5961
private static final String ENVIRONMENT_NAME = PARENT + "/environments/" + ENVIRONMENT_ID;
6062
private static Instance expectedNotebookInstance;
@@ -66,6 +68,8 @@ public class ITNotebookServiceClientTest {
6668
public static void setUp() throws IOException, ExecutionException, InterruptedException {
6769
// Create Test Notebook Instance
6870
client = NotebookServiceClient.create();
71+
Util.cleanUpNotebookInstances(client, PARENT);
72+
6973
ContainerImage containerImage =
7074
ContainerImage.newBuilder().setRepository(FieldBehavior.OPTIONAL.name()).build();
7175

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.google.cloud.notebooks.v1beta1.it;
2+
3+
import com.google.cloud.notebooks.v1beta1.DeleteInstanceRequest;
4+
import com.google.cloud.notebooks.v1beta1.Instance;
5+
import com.google.cloud.notebooks.v1beta1.ListInstancesRequest;
6+
import com.google.cloud.notebooks.v1beta1.NotebookServiceClient;
7+
import com.google.cloud.notebooks.v1beta1.NotebookServiceClient.ListInstancesPagedResponse;
8+
import com.google.protobuf.util.Timestamps;
9+
import java.time.Instant;
10+
import java.time.temporal.ChronoUnit;
11+
12+
public class Util {
13+
14+
// Cleans existing test resources if any.
15+
private static final int DELETION_THRESHOLD_TIME_HOURS = 24;
16+
17+
/** Bring down any instances that are older than 24 hours */
18+
public static void cleanUpNotebookInstances(NotebookServiceClient client, String parent) {
19+
ListInstancesPagedResponse listInstancesPagedResponse =
20+
client.listInstances(ListInstancesRequest.newBuilder().setParent(parent).build());
21+
for (Instance instance : listInstancesPagedResponse.iterateAll()) {
22+
if (isCreatedBeforeThresholdTime(
23+
Instant.ofEpochMilli(Timestamps.toMillis(instance.getCreateTime())))
24+
&& instance.getName().startsWith(ITNotebookServiceClientTest.NOTEBOOK_PREFIX)) {
25+
client.deleteInstanceAsync(
26+
DeleteInstanceRequest.newBuilder().setName(instance.getName()).build());
27+
}
28+
}
29+
}
30+
31+
private static boolean isCreatedBeforeThresholdTime(Instant instant) {
32+
return instant.isBefore(Instant.now().minus(DELETION_THRESHOLD_TIME_HOURS, ChronoUnit.HOURS));
33+
}
34+
}

java-vision/google-cloud-vision/src/test/java/com/google/cloud/vision/it/ITSystemTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ public class ITSystemTest {
9999
private static final String ID = UUID.randomUUID().toString().substring(0, 8);
100100
// GraalVM native-image test uses the project root as working directory, not google-cloud-vision
101101
private static final String RESOURCES =
102-
Files.exists(Paths.get("google-cloud-vision", "src", "test", "resources"))
103-
? "google-cloud-vision/src/test/resources/"
102+
Files.exists(Paths.get("java-vision","google-cloud-vision", "src", "test", "resources"))
103+
? "java-vision/google-cloud-vision/src/test/resources/"
104104
: "src/test/resources/";
105105

106106
private static final String GCS_BUCKET_ENV_VAR = "GOOGLE_CLOUD_TESTS_VISION_BUCKET";

0 commit comments

Comments
 (0)