Skip to content

Commit b0624b3

Browse files
committed
test(dialogflow): deflake and re-enable test cases in ITSystemTest
1 parent 5b8e295 commit b0624b3

2 files changed

Lines changed: 25 additions & 12 deletions

File tree

java-dialogflow/google-cloud-dialogflow/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@
8787
<artifactId>google-cloud-core</artifactId>
8888
<scope>test</scope>
8989
</dependency>
90+
<dependency>
91+
<groupId>org.awaitility</groupId>
92+
<artifactId>awaitility</artifactId>
93+
<scope>test</scope>
94+
</dependency>
9095
<!-- {x-generated-grpc-dependencies-start} -->
9196
<dependency>
9297
<groupId>com.google.api.grpc</groupId>

java-dialogflow/google-cloud-dialogflow/src/test/java/com/google/cloud/dialogflow/v2/it/ITSystemTest.java

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
*/
1616
package com.google.cloud.dialogflow.v2.it;
1717

18+
import static com.google.common.collect.Streams.stream;
19+
import static org.awaitility.Awaitility.await;
1820
import static org.junit.Assert.assertEquals;
21+
import static org.junit.Assert.assertTrue;
1922

2023
import com.google.cloud.ServiceOptions;
2124
import com.google.cloud.dialogflow.v2.Agent;
@@ -54,10 +57,10 @@
5457
import com.google.protobuf.Struct;
5558
import com.google.protobuf.Value;
5659
import java.io.IOException;
60+
import java.time.Duration;
5761
import java.util.UUID;
5862
import org.junit.AfterClass;
5963
import org.junit.BeforeClass;
60-
import org.junit.Ignore;
6164
import org.junit.Test;
6265

6366
public class ITSystemTest {
@@ -259,7 +262,6 @@ public void getIntentTest() {
259262
}
260263

261264
@Test
262-
@Ignore("b/423958346")
263265
public void detectIntentTest() {
264266
QueryInput queryInput =
265267
QueryInput.newBuilder()
@@ -279,22 +281,28 @@ public void detectIntentTest() {
279281
.setSession(SESSION_NAME.toString())
280282
.setQueryInput(queryInput)
281283
.build();
282-
DetectIntentResponse response = sessionsClient.detectIntent(request);
283-
QueryResult result = response.getQueryResult();
284-
assertEquals(EVENT_NAME, result.getQueryText());
285-
assertEquals(ACTION_NAME, result.getAction());
286-
assertEquals(DEFAULT_LANGUAGE_CODE, result.getLanguageCode());
287-
assertEquals(intent.getDisplayName(), result.getIntent().getDisplayName());
284+
await()
285+
.atMost(Duration.ofSeconds(30))
286+
.pollInterval(Duration.ofSeconds(2))
287+
.untilAsserted(
288+
() -> {
289+
DetectIntentResponse response = sessionsClient.detectIntent(request);
290+
QueryResult result = response.getQueryResult();
291+
assertEquals(EVENT_NAME, result.getQueryText());
292+
assertEquals(ACTION_NAME, result.getAction());
293+
assertEquals(DEFAULT_LANGUAGE_CODE, result.getLanguageCode());
294+
assertEquals(intent.getDisplayName(), result.getIntent().getDisplayName());
295+
});
288296
}
289297

290298
@Test
291-
@Ignore("b/423958346")
292299
public void listContextsTest() {
293300
ListContextsRequest request =
294301
ListContextsRequest.newBuilder().setParent(SESSION_NAME.toString()).build();
295-
for (Context actualContext : contextsClient.listContexts(request).iterateAll()) {
296-
assertEquals(context.getName(), actualContext.getName());
297-
}
302+
boolean contextNameInActualContext =
303+
stream(contextsClient.listContexts(request).iterateAll())
304+
.anyMatch(actualContext -> context.getName().equals(actualContext.getName()));
305+
assertTrue(contextNameInActualContext);
298306
}
299307

300308
@Test

0 commit comments

Comments
 (0)