Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions google-cloud-jar-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<version>4.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
5 changes: 5 additions & 0 deletions java-dialogflow/google-cloud-dialogflow/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@
<artifactId>google-cloud-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<scope>test</scope>
</dependency>
<!-- {x-generated-grpc-dependencies-start} -->
<dependency>
<groupId>com.google.api.grpc</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
*/
package com.google.cloud.dialogflow.v2.it;

import static com.google.common.collect.Streams.stream;
import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import com.google.cloud.ServiceOptions;
import com.google.cloud.dialogflow.v2.Agent;
Expand Down Expand Up @@ -54,10 +57,11 @@
import com.google.protobuf.Struct;
import com.google.protobuf.Value;
import java.io.IOException;
import java.time.Duration;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicReference;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;

public class ITSystemTest {
Expand Down Expand Up @@ -259,7 +263,6 @@ public void getIntentTest() {
}

@Test
@Ignore("b/423958346")
public void detectIntentTest() {
QueryInput queryInput =
QueryInput.newBuilder()
Expand All @@ -279,22 +282,31 @@ public void detectIntentTest() {
.setSession(SESSION_NAME.toString())
.setQueryInput(queryInput)
.build();
DetectIntentResponse response = sessionsClient.detectIntent(request);
QueryResult result = response.getQueryResult();
AtomicReference<DetectIntentResponse> responseRef = new AtomicReference<>();
await()
.atMost(Duration.ofSeconds(30))
.pollInterval(Duration.ofSeconds(2))
.until(
() -> {
DetectIntentResponse response = sessionsClient.detectIntent(request);
responseRef.set(response);
return !response.getQueryResult().getQueryText().isEmpty();
});
QueryResult result = responseRef.get().getQueryResult();
assertEquals(EVENT_NAME, result.getQueryText());
assertEquals(ACTION_NAME, result.getAction());
assertEquals(DEFAULT_LANGUAGE_CODE, result.getLanguageCode());
assertEquals(intent.getDisplayName(), result.getIntent().getDisplayName());
}

@Test
@Ignore("b/423958346")
public void listContextsTest() {
ListContextsRequest request =
ListContextsRequest.newBuilder().setParent(SESSION_NAME.toString()).build();
for (Context actualContext : contextsClient.listContexts(request).iterateAll()) {
assertEquals(context.getName(), actualContext.getName());
}
boolean contextNameInActualContext =
stream(contextsClient.listContexts(request).iterateAll())
.anyMatch(actualContext -> context.getName().equals(actualContext.getName()));
assertTrue(contextNameInActualContext);
Comment on lines +306 to +309

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To ensure listContextsTest is fully deflaked against eventual consistency (replication lag), we should also wrap the assertion in an awaitility block. Otherwise, if the context is not immediately visible in the list, the test will fail.

Suggested change
boolean contextNameInActualContext =
stream(contextsClient.listContexts(request).iterateAll())
.anyMatch(actualContext -> context.getName().equals(actualContext.getName()));
assertTrue(contextNameInActualContext);
await()
.atMost(Duration.ofSeconds(10))
.pollInterval(Duration.ofSeconds(2))
.untilAsserted(
() -> {
boolean contextNameInActualContext =
stream(contextsClient.listContexts(request).iterateAll())
.anyMatch(actualContext -> context.getName().equals(actualContext.getName()));
assertTrue(contextNameInActualContext);
});

}

@Test
Expand Down
Loading