Skip to content

Commit a95787c

Browse files
committed
test(dialogflow): deflake and re-enable test cases in ITSystemTest
1 parent 2d9d01c commit a95787c

3 files changed

Lines changed: 32 additions & 8 deletions

File tree

google-cloud-jar-parent/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@
7171
</dependency>
7272

7373
<!-- Test dependencies -->
74+
<dependency>
75+
<groupId>org.awaitility</groupId>
76+
<artifactId>awaitility</artifactId>
77+
<version>4.3.0</version>
78+
<scope>test</scope>
79+
</dependency>
7480
<dependency>
7581
<groupId>junit</groupId>
7682
<artifactId>junit</artifactId>

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: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,14 @@
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;
24+
import java.time.Duration;
25+
import java.util.concurrent.atomic.AtomicReference;
2126
import com.google.cloud.dialogflow.v2.Agent;
2227
import com.google.cloud.dialogflow.v2.AgentsClient;
2328
import com.google.cloud.dialogflow.v2.Context;
@@ -57,7 +62,6 @@
5762
import java.util.UUID;
5863
import org.junit.AfterClass;
5964
import org.junit.BeforeClass;
60-
import org.junit.Ignore;
6165
import org.junit.Test;
6266

6367
public class ITSystemTest {
@@ -259,7 +263,6 @@ public void getIntentTest() {
259263
}
260264

261265
@Test
262-
@Ignore("b/423958346")
263266
public void detectIntentTest() {
264267
QueryInput queryInput =
265268
QueryInput.newBuilder()
@@ -279,22 +282,32 @@ public void detectIntentTest() {
279282
.setSession(SESSION_NAME.toString())
280283
.setQueryInput(queryInput)
281284
.build();
282-
DetectIntentResponse response = sessionsClient.detectIntent(request);
283-
QueryResult result = response.getQueryResult();
285+
AtomicReference<DetectIntentResponse> responseRef =
286+
new AtomicReference<>();
287+
await()
288+
.atMost(Duration.ofSeconds(10))
289+
.pollInterval(Duration.ofSeconds(2))
290+
.until(
291+
() -> {
292+
DetectIntentResponse response = sessionsClient.detectIntent(request);
293+
responseRef.set(response);
294+
return !response.getQueryResult().getQueryText().isEmpty();
295+
});
296+
QueryResult result = responseRef.get().getQueryResult();
284297
assertEquals(EVENT_NAME, result.getQueryText());
285298
assertEquals(ACTION_NAME, result.getAction());
286299
assertEquals(DEFAULT_LANGUAGE_CODE, result.getLanguageCode());
287300
assertEquals(intent.getDisplayName(), result.getIntent().getDisplayName());
288301
}
289302

290303
@Test
291-
@Ignore("b/423958346")
292304
public void listContextsTest() {
293305
ListContextsRequest request =
294306
ListContextsRequest.newBuilder().setParent(SESSION_NAME.toString()).build();
295-
for (Context actualContext : contextsClient.listContexts(request).iterateAll()) {
296-
assertEquals(context.getName(), actualContext.getName());
297-
}
307+
boolean contextNameInActualContext =
308+
stream(contextsClient.listContexts(request).iterateAll())
309+
.anyMatch(actualContext -> context.getName().equals(actualContext.getName()));
310+
assertTrue(contextNameInActualContext);
298311
}
299312

300313
@Test

0 commit comments

Comments
 (0)