Skip to content

Commit 2b836bb

Browse files
authored
healthcare API: fix flaky test (GoogleCloudPlatform#3333)
* healthcare API: fix flaky test * add comments
1 parent b9eeb62 commit 2b836bb

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

healthcare/v1/src/main/java/snippets/healthcare/hl7v2/messages/HL7v2MessageList.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import com.google.auth.oauth2.GoogleCredentials;
3030
import java.io.IOException;
3131
import java.util.Collections;
32-
import java.util.List;
3332

3433
public class HL7v2MessageList {
3534
private static final String HL7v2_NAME = "projects/%s/locations/%s/datasets/%s/hl7V2Stores/%s";
@@ -47,8 +46,6 @@ public static void hl7v2MessageList(String hl7v2StoreName) throws IOException {
4746
// Results are paginated, so multiple queries may be required.
4847
String pageToken = null;
4948

50-
List<Message> hl7v2Messages;
51-
5249
do {
5350
// Create request and execute.
5451
ListMessagesResponse messageResponse =
@@ -63,17 +60,17 @@ public static void hl7v2MessageList(String hl7v2StoreName) throws IOException {
6360
.setPageToken(pageToken)
6461
.execute();
6562

66-
// Collect results.
67-
hl7v2Messages = messageResponse.getHl7V2Messages();
68-
63+
if (messageResponse.getHl7V2Messages() != null) {
64+
// Print results.
65+
System.out.printf(
66+
"Retrieved %s HL7v2 messages: \n", messageResponse.getHl7V2Messages().size());
67+
for (Message message : messageResponse.getHl7V2Messages()) {
68+
System.out.println(message);
69+
}
70+
}
6971
// Update the page token for the next request.
7072
pageToken = messageResponse.getNextPageToken();
7173
} while (pageToken != null);
72-
// Print results.
73-
System.out.printf("Retrieved %s HL7v2 messages: \n", hl7v2Messages.size());
74-
for (Message message : hl7v2Messages) {
75-
System.out.printf("%s\n", message.getName());
76-
}
7774
}
7875

7976
private static CloudHealthcare createClient() throws IOException {

healthcare/v1/src/test/java/snippets/healthcare/Hl7v2MessageTests.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ public void test_GetHL7v2Message() throws Exception {
136136

137137
@Test
138138
public void test_Hl7v2MessageList() throws Exception {
139+
// There can be a delay between when a message is created
140+
// or ingested and when it's viewable when listing messages
141+
// in a store, so sleep for 10 seconds while waiting for
142+
// the message to fully propagate.
143+
Thread.sleep(10000);
139144
HL7v2MessageList.hl7v2MessageList(hl7v2StoreName);
140145

141146
String output = bout.toString();

0 commit comments

Comments
 (0)