Skip to content

Commit d1514d3

Browse files
authored
samples: fixed flaky test on getOper sample (GoogleCloudPlatform#3675)
- [X] Please **merge** this PR for me once it is approved.
1 parent e6b6999 commit d1514d3

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

automl/cloud-client/src/main/java/com/example/automl/GetOperationStatus.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
// [START automl_get_operation_status]
2020
import com.google.cloud.automl.v1.AutoMlClient;
2121
import com.google.longrunning.Operation;
22+
import io.grpc.StatusRuntimeException;
2223
import java.io.IOException;
2324

2425
class GetOperationStatus {
@@ -30,7 +31,8 @@ static void getOperationStatus() throws IOException {
3031
}
3132

3233
// Get the status of an operation
33-
static void getOperationStatus(String operationFullId) throws IOException {
34+
static void getOperationStatus(String operationFullId)
35+
throws IOException, StatusRuntimeException {
3436
// Initialize client that will be used to send requests. This client only needs to be created
3537
// once, and can be reused for multiple requests. After completing all of your requests, call
3638
// the "close" method on the client to safely clean up any remaining background resources.

automl/cloud-client/src/test/java/com/example/automl/GetOperationStatusTest.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void setUp() throws IOException, ExecutionException, InterruptedException
6767
out = new PrintStream(bout);
6868
System.setOut(out);
6969

70-
// start a export data into dataset and cancel it before it finishes.
70+
// start a import data into dataset and cancel it before it finishes.
7171
try (AutoMlClient client = AutoMlClient.create()) {
7272
// Get the complete path of the dataset.
7373
DatasetName datasetFullId = DatasetName.of(PROJECT_ID, "us-central1", DATASET_ID);
@@ -99,9 +99,11 @@ public void testGetOperationStatus() throws IOException {
9999
@After
100100
public void tearDown() throws IOException, InterruptedException {
101101
try (AutoMlClient client = AutoMlClient.create()) {
102-
// terminate export data LRO.
102+
// terminate import data LRO.
103103
client.getOperationsClient().cancelOperation(operationFullName);
104-
client.getOperationsClient().awaitTermination(5, TimeUnit.SECONDS);
104+
while (!client.getOperationsClient().getOperation(operationFullName).getDone()) {
105+
TimeUnit.SECONDS.sleep(5);
106+
}
105107
}
106108

107109
System.setOut(null);

0 commit comments

Comments
 (0)