Skip to content

Make the test less flaky #1245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 30, 2018
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
import com.google.cloud.dialogflow.v2beta1.KnowledgeBasesClient;
import com.google.cloud.dialogflow.v2beta1.ProjectName;

import com.google.common.collect.ImmutableList;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.Collections;
import java.util.List;
import java.util.Map;

Expand All @@ -53,7 +53,9 @@ public class KnowledgeBaseManagementIT {
private static String KNOWLEDGE_BASE_NAME = "fake_knowledge_base_name";
private static String DOCUMENT_BASE_NAME = "fake_document_name";

private static List<String> TEXTS = Collections.singletonList("How do I sign up?");
private static List<String> TEXTS = ImmutableList
.of("How do I sign up?", "Is my data redundant?", "Where can I find pricing information?",
"Where is my data stored?", "What are my support options?");

@Before
public void setUp() {
Expand Down Expand Up @@ -160,14 +162,19 @@ public void testDetectIntentKnowledge() throws Exception {

Map<String, KnowledgeAnswers> allAnswers = DetectIntentKnowledge
.detectIntentKnowledge(PROJECT_ID, knowledgeBaseName, SESSION_ID, LANGUAGE_CODE, TEXTS);
assertEquals(1, allAnswers.size());
KnowledgeAnswers knowledgeAnswers = allAnswers.get(TEXTS.get(0));
assertEquals(TEXTS.size(), allAnswers.size());
int answersFound = 0;
for (String text : TEXTS) {
assertEquals(1, knowledgeAnswers.getAnswersCount());
Answer answer = knowledgeAnswers.getAnswers(0);
assertEquals(text, answer.getFaqQuestion());
assertEquals(document.getName(), answer.getSource());
assertThat(answer.getAnswer()).contains("Cloud Storage");
KnowledgeAnswers knowledgeAnswers = allAnswers.get(text);
if (knowledgeAnswers.getAnswersCount() > 0) {
answersFound++;
Answer answer = knowledgeAnswers.getAnswers(0);
assertEquals(text, answer.getFaqQuestion());
assertEquals(document.getName(), answer.getSource());
assertThat(answer.getAnswer()).contains("Cloud Storage");
}
}
// To make the test less flaky, check that half of the texts got a result.
assertThat(answersFound).isGreaterThan(TEXTS.size() / 2);

Choose a reason for hiding this comment

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

Smart 👌

}
}