-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
1 parent
db7c7d1
commit 8e4378d
Showing
11 changed files
with
144 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...pute/google-cloud-compute/src/test/java/com/google/cloud/compute/v1/integration/Util.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.google.cloud.compute.v1.integration; | ||
|
||
import com.google.cloud.compute.v1.DeleteInstanceRequest; | ||
import com.google.cloud.compute.v1.Instance; | ||
import com.google.cloud.compute.v1.InstancesClient; | ||
import com.google.cloud.compute.v1.InstancesClient.ListPagedResponse; | ||
import java.time.Instant; | ||
import java.time.ZonedDateTime; | ||
import java.time.temporal.ChronoUnit; | ||
|
||
public class Util { | ||
|
||
// Cleans existing test resources if any. | ||
private static final int DELETION_THRESHOLD_TIME_HOURS = 24; | ||
|
||
/** Bring down any instances that are older than 24 hours */ | ||
public static void cleanUpComputeInstances( | ||
InstancesClient instancesClient, String project, String zone) { | ||
ListPagedResponse listPagedResponse = instancesClient.list(project, zone); | ||
for (Instance instance : listPagedResponse.iterateAll()) { | ||
if (isCreatedBeforeThresholdTime( | ||
ZonedDateTime.parse(instance.getCreationTimestamp()).toInstant()) | ||
&& instance.getName().startsWith(BaseTest.COMPUTE_PREFIX)) { | ||
instancesClient.deleteAsync( | ||
DeleteInstanceRequest.newBuilder() | ||
.setInstance(instance.getName()) | ||
.setProject(project) | ||
.setZone(zone) | ||
.build()); | ||
} | ||
} | ||
} | ||
|
||
private static boolean isCreatedBeforeThresholdTime(Instant instant) { | ||
return instant.isBefore(Instant.now().minus(DELETION_THRESHOLD_TIME_HOURS, ChronoUnit.HOURS)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...ooks/google-cloud-notebooks/src/test/java/com/google/cloud/notebooks/v1beta1/it/Util.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.google.cloud.notebooks.v1beta1.it; | ||
|
||
import com.google.cloud.notebooks.v1beta1.DeleteInstanceRequest; | ||
import com.google.cloud.notebooks.v1beta1.Instance; | ||
import com.google.cloud.notebooks.v1beta1.ListInstancesRequest; | ||
import com.google.cloud.notebooks.v1beta1.NotebookServiceClient; | ||
import com.google.cloud.notebooks.v1beta1.NotebookServiceClient.ListInstancesPagedResponse; | ||
import com.google.protobuf.util.Timestamps; | ||
import java.time.Instant; | ||
import java.time.temporal.ChronoUnit; | ||
|
||
public class Util { | ||
|
||
// Cleans existing test resources if any. | ||
private static final int DELETION_THRESHOLD_TIME_HOURS = 24; | ||
|
||
/** Bring down any instances that are older than 24 hours */ | ||
public static void cleanUpNotebookInstances(NotebookServiceClient client, String parent) { | ||
ListInstancesPagedResponse listInstancesPagedResponse = | ||
client.listInstances(ListInstancesRequest.newBuilder().setParent(parent).build()); | ||
for (Instance instance : listInstancesPagedResponse.iterateAll()) { | ||
if (isCreatedBeforeThresholdTime( | ||
Instant.ofEpochMilli(Timestamps.toMillis(instance.getCreateTime()))) | ||
&& instance.getName().startsWith(ITNotebookServiceClientTest.NOTEBOOK_PREFIX)) { | ||
client.deleteInstanceAsync( | ||
DeleteInstanceRequest.newBuilder().setName(instance.getName()).build()); | ||
} | ||
} | ||
} | ||
|
||
private static boolean isCreatedBeforeThresholdTime(Instant instant) { | ||
return instant.isBefore(Instant.now().minus(DELETION_THRESHOLD_TIME_HOURS, ChronoUnit.HOURS)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters