Skip to content
This repository has been archived by the owner on Dec 4, 2023. It is now read-only.

Some Waterfall tests were missing some joins, causing some random failures #961

Merged
merged 2 commits into from
Feb 9, 2021
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ private String determineCulture(Activity activity) {
}

String culture = PromptCultureModels.mapToNearestLanguage(locale);
if (StringUtils.isBlank(culture) || !choiceDefaults.containsKey(culture)) {
if (StringUtils.isEmpty(culture) || !choiceDefaults.containsKey(culture)) {
culture = PromptCultureModels.ENGLISH_CULTURE;
}
return culture;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,17 @@ public void CallDialogInParentComponent() {

class Step1 implements WaterfallStep {
public CompletableFuture<DialogTurnResult> waterfallStep(WaterfallStepContext stepContext) {
stepContext.getContext().sendActivity("Child started.").join();
return stepContext.beginDialog("parentDialog", "test");
return stepContext.getContext()
.sendActivity("Child started.")
.thenCompose(resourceResponse -> stepContext.beginDialog("parentDialog", "test"));
}
}

class Step2 implements WaterfallStep {
public CompletableFuture<DialogTurnResult> waterfallStep(WaterfallStepContext stepContext) {
stepContext.getContext()
.sendActivity(String.format("Child finished. Value: %s", stepContext.getResult()));
return stepContext.endDialog();
return stepContext.getContext()
.sendActivity(String.format("Child finished. Value: %s", stepContext.getResult()))
.thenCompose(resourceResponse -> stepContext.endDialog());
}
}

Expand All @@ -73,8 +74,9 @@ public CompletableFuture<DialogTurnResult> waterfallStep(WaterfallStepContext st

class ParentStep implements WaterfallStep {
public CompletableFuture<DialogTurnResult> waterfallStep(WaterfallStepContext stepContext) {
stepContext.getContext().sendActivity(String.format("Parent called.", stepContext.getResult()));
return stepContext.endDialog(stepContext.getOptions());
return stepContext.getContext()
.sendActivity(String.format("Parent called.", stepContext.getResult()))
.thenCompose(resourceResponse -> stepContext.endDialog(stepContext.getOptions()));
}
}
WaterfallStep[] parentStep = new WaterfallStep[] {new ParentStep() };
Expand All @@ -90,7 +92,7 @@ public CompletableFuture<DialogTurnResult> waterfallStep(WaterfallStepContext st
dc.beginDialog("parentComponent", null).join();
} else if (results.getStatus() == DialogTurnStatus.COMPLETE) {
int value = (int) results.getResult();
turnContext.sendActivity(MessageFactory.text(String.format("Bot received the number '%d'.", value)));
turnContext.sendActivity(MessageFactory.text(String.format("Bot received the number '%d'.", value))).join();
}

return CompletableFuture.completedFuture(null);
Expand Down Expand Up @@ -122,10 +124,10 @@ public void BasicWaterfallTest() throws UnsupportedDataTypeException {

DialogTurnResult results = dc.continueDialog().join();
if (results.getStatus() == DialogTurnStatus.EMPTY) {
dc.beginDialog("test-waterfall", null);
dc.beginDialog("test-waterfall", null).join();
} else if (results.getStatus() == DialogTurnStatus.COMPLETE) {
int value = (int) results.getResult();
turnContext.sendActivity(MessageFactory.text(String.format("Bot received the number '%d'.", value)));
turnContext.sendActivity(MessageFactory.text(String.format("Bot received the number '%d'.", value))).join();
}
return CompletableFuture.completedFuture(null);
})
Expand Down Expand Up @@ -238,10 +240,10 @@ public void BasicComponentDialogTest() throws UnsupportedDataTypeException {

DialogTurnResult results = dc.continueDialog().join();
if (results.getStatus() == DialogTurnStatus.EMPTY) {
dc.beginDialog("TestComponentDialog", null);
dc.beginDialog("TestComponentDialog", null).join();
} else if (results.getStatus() == DialogTurnStatus.COMPLETE) {
int value = (int) results.getResult();
turnContext.sendActivity(MessageFactory.text(String.format("Bot received the number '%d'.", value)));
turnContext.sendActivity(MessageFactory.text(String.format("Bot received the number '%d'.", value))).join();
}
return CompletableFuture.completedFuture(null);
})
Expand Down Expand Up @@ -280,10 +282,10 @@ public void NestedComponentDialogTest() {

DialogTurnResult results = dc.continueDialog().join();
if (results.getStatus() == DialogTurnStatus.EMPTY) {
dc.beginDialog("TestNestedComponentDialog", null);
dc.beginDialog("TestNestedComponentDialog", null).join();
} else if (results.getStatus() == DialogTurnStatus.COMPLETE) {
int value = (int) results.getResult();
turnContext.sendActivity(MessageFactory.text(String.format("Bot received the number '%d'.", value)));
turnContext.sendActivity(MessageFactory.text(String.format("Bot received the number '%d'.", value))).join();
}
return CompletableFuture.completedFuture(null);
})
Expand Down Expand Up @@ -328,16 +330,16 @@ public void CallDialogDefinedInParentComponent() {

class Step1 implements WaterfallStep {
public CompletableFuture<DialogTurnResult> waterfallStep(WaterfallStepContext stepContext) {
stepContext.getContext().sendActivity("Child started.");
return stepContext.beginDialog("parentDialog", options);
return stepContext.getContext().sendActivity("Child started.")
.thenCompose(resourceResponse -> stepContext.beginDialog("parentDialog", options));
}
}

class Step2 implements WaterfallStep {
public CompletableFuture<DialogTurnResult> waterfallStep(WaterfallStepContext stepContext) {
Assert.assertEquals("test", (String) stepContext.getResult());
stepContext.getContext().sendActivity("Child finished.");
return stepContext.endDialog();
return stepContext.getContext().sendActivity("Child finished.")
.thenCompose(resourceResponse -> stepContext.endDialog());
}
}

Expand All @@ -353,9 +355,9 @@ public CompletableFuture<DialogTurnResult> waterfallStep(WaterfallStepContext st
Map<String, String> stepOptions = (Map<String, String>) stepContext.getOptions();
Assert.assertNotNull(stepOptions);
Assert.assertTrue(stepOptions.containsKey("value"));
stepContext.getContext().sendActivity(
String.format("Parent called with: {%s}", stepOptions.get("value")));
return stepContext.endDialog(stepOptions.get("value"));
return stepContext.getContext()
.sendActivity(String.format("Parent called with: %s", stepOptions.get("value")))
.thenCompose(resourceResponse -> stepContext.endDialog(stepOptions.get("value")));
}
}

Expand All @@ -374,15 +376,16 @@ public CompletableFuture<DialogTurnResult> waterfallStep(WaterfallStepContext st
if (results.getStatus() == DialogTurnStatus.EMPTY) {
dc.beginDialog("parentComponent", null).join();
} else if (results.getStatus() == DialogTurnStatus.COMPLETE) {
turnContext.sendActivity(MessageFactory.text("Done"));
turnContext.sendActivity(MessageFactory.text("Done")).join();
}
return CompletableFuture.completedFuture(null);
})
.send("Hi")
.assertReply("Child started.")
.assertReply("Parent called with: test")
.assertReply("Child finished.")
.startTest();
.startTest()
.join();
}

// private static TestFlow CreateTestFlow(WaterfallDialog waterfallDialog) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public TestFlow CreateDialogContext(DialogTestFunction handler) {
.useBotState(new ConversationState(new MemoryStorage()));
DialogManager dm = new DialogManager(new LamdbaDialog(testName.getMethodName(), handler), null);
return new TestFlow(adapter, (turnContext) -> {
return dm.onTurn(turnContext).thenAccept(null);
return dm.onTurn(turnContext).thenApply(dialogManagerResult -> null);
}).sendConverationUpdate();
}

Expand Down Expand Up @@ -77,7 +77,7 @@ public void SimpleMemoryScopesTest() {
}
return CompletableFuture.completedFuture(null);
};
CreateDialogContext(testFunction).startTest();
CreateDialogContext(testFunction).startTest().join();
}

@Test
Expand All @@ -100,15 +100,15 @@ public void BotStateMemoryScopeTest() {
for (Pair<BotState, MemoryScope> stateScope : stateScopes) {
final String name = "test-name";
final String value = "test-value";
stateScope.getValue0().createProperty(name).set(dc.getContext(), value);
stateScope.getValue0().createProperty(name).set(dc.getContext(), value).join();

Object memory = stateScope.getValue1().getMemory(dc);

Assert.assertEquals(value, ObjectPath.getPathValue(memory, name, String.class));
}
return CompletableFuture.completedFuture(null);
};
CreateDialogContext(testFunction).startTest();
CreateDialogContext(testFunction).startTest().join();
}

public class CustomState extends BotState {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,14 @@ public void PromptValidatorNumberOfAttempts() {
PromptValidator<String> validator = (promptContext) -> {
String result = promptContext.getRecognized().getValue();
if (result.length() > 3) {
Activity succeededMessage = MessageFactory.text(String.format("You got it at the %nth try!",
Activity succeededMessage = MessageFactory.text(String.format("You got it at the %dth try!",
promptContext.getAttemptCount()));
promptContext.getContext().sendActivity(succeededMessage);
return CompletableFuture.completedFuture(true);
return promptContext.getContext().sendActivity(succeededMessage).thenApply(resourceResponse -> true);
} else {
promptContext.getContext().sendActivity(
MessageFactory.text("Please send a name that is longer than 3 characters."));
return promptContext.getContext()
.sendActivity(MessageFactory.text(String.format("Please send a name that is longer than 3 characters. %d", promptContext.getAttemptCount())))
.thenApply(resourceResponse -> false);
}

return CompletableFuture.completedFuture(false);
};

dialogs.add(new TextPrompt("namePrompt", validator));
Expand Down Expand Up @@ -197,7 +195,8 @@ public void PromptValidatorNumberOfAttempts() {
.send("John")
.assertReply("You got it at the 4th try!")
.assertReply("John is a great name!")
.startTest();
.startTest()
.join();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ public void ReplaceDialogTelemetryClientNotNull() {
return CompletableFuture.completedFuture(null);
})
.send("hello")
.startTest();
.startTest()
.join();
}

private class FirstDialog extends ComponentDialog {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ public void WaterfallWithClass() {

new TestFlow(adapter, (turnContext) -> {
DialogContext dc = dialogs.createContext(turnContext).join();
dc.continueDialog();
dc.continueDialog().join();
if (!turnContext.getResponded()) {
dc.beginDialog("test", null);
dc.beginDialog("test", null).join();
}
return CompletableFuture.completedFuture(null);
})
Expand Down Expand Up @@ -287,7 +287,8 @@ public void WaterfallNested() {
.assertReply("step2.1")
.send("hello")
.assertReply("step2.2")
.startTest();
.startTest()
.join();
}

@Test
Expand All @@ -302,8 +303,7 @@ public void WaterfallDateTimePromptFirstInvalidThenValidInput() {
WaterfallStep[] steps = new WaterfallStep[] {
(stepContext) -> {
PromptOptions options = new PromptOptions();
Activity activity = new Activity(ActivityTypes.MESSAGE);
activity.setText("Provide a date");
options.setPrompt(MessageFactory.text("Provide a date"));
return stepContext.prompt("dateTimePrompt", options);
},
(stepContext) -> {
Expand All @@ -325,7 +325,7 @@ public void WaterfallDateTimePromptFirstInvalidThenValidInput() {
dc.continueDialog().join();

if (!turnContext.getResponded()) {
dc.beginDialog("test-dateTimePrompt", null);
dc.beginDialog("test-dateTimePrompt", null).join();
}
return CompletableFuture.completedFuture(null);
})
Expand All @@ -334,7 +334,8 @@ public void WaterfallDateTimePromptFirstInvalidThenValidInput() {
.send("hello again")
.assertReply("Provide a date")
.send("Wednesday 4 oclock")
.startTest();
.startTest()
.join();
}

@Test
Expand All @@ -356,7 +357,7 @@ public void WaterfallCancel() {
dialog.endDialog(
new TurnContextImpl(new TestAdapter(), new Activity(ActivityTypes.MESSAGE)),
dialogInstance,
DialogReason.CANCEL_CALLED);
DialogReason.CANCEL_CALLED).join();

Assert.assertTrue(telemetryClient.trackEventCallCount > 0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,14 @@ public void ActivityPromptShouldSendRetryPromptIfValidationFailed() {
DialogTurnResult results = dc.continueDialog().join();
if (results.getStatus() == DialogTurnStatus.EMPTY) {
PromptOptions options = new PromptOptions();
Activity activity = new Activity(ActivityTypes.MESSAGE);
activity.setText("please send an event.");
Activity retryActivity = new Activity(ActivityTypes.MESSAGE);
retryActivity.setText("Retrying - please send an event.");
options.setPrompt(activity);
options.setRetryPrompt(retryActivity);
options.setPrompt(MessageFactory.text("please send an event."));
options.setRetryPrompt(MessageFactory.text("Retrying - please send an event."));
dc.prompt("EventActivityPrompt", options).join();
} else if (results.getStatus() == DialogTurnStatus.COMPLETE) {
Activity content = (Activity) results.getResult();
turnContext.sendActivity(content).join();
} else if (results.getStatus() == DialogTurnStatus.WAITING) {
turnContext.sendActivity("Test complete.");
turnContext.sendActivity("Test complete.").join();
}
return CompletableFuture.completedFuture(null);
});
Expand All @@ -134,7 +130,8 @@ public void ActivityPromptShouldSendRetryPromptIfValidationFailed() {
.assertReply("please send an event.")
.send("test")
.assertReply("Retrying - please send an event.")
.startTest();
.startTest()
.join();
}

@Test
Expand All @@ -156,12 +153,8 @@ public void ActivityPromptResumeDialogShouldPromptNotRetry()
switch (turnContext.getActivity().getText()) {
case "begin":
PromptOptions options = new PromptOptions();
Activity activity = new Activity(ActivityTypes.MESSAGE);
activity.setText("please send an event.");
Activity retryActivity = new Activity(ActivityTypes.MESSAGE);
retryActivity.setText("Retrying - please send an event.");
options.setPrompt(activity);
options.setRetryPrompt(retryActivity);
options.setPrompt(MessageFactory.text("please send an event."));
options.setRetryPrompt(MessageFactory.text("Retrying - please send an event."));
dc.prompt("EventActivityPrompt", options).join();
break;
case "continue":
Expand All @@ -183,7 +176,8 @@ public void ActivityPromptResumeDialogShouldPromptNotRetry()
.send("resume")
// 'ResumeDialogAsync' of ActivityPrompt does NOT cause a Retry
.assertReply("please send an event.")
.startTest();
.startTest()
.join();
}

@Test
Expand All @@ -208,9 +202,7 @@ public void OnPromptOverloadWithoutIsRetryParamReturnsBasicActivityPrompt() {
DialogTurnResult results = dc.continueDialog().join();
if (results.getStatus() == DialogTurnStatus.EMPTY) {
PromptOptions options = new PromptOptions();
Activity activity = new Activity(ActivityTypes.MESSAGE);
activity.setText("please send an event.");
options.setPrompt(activity);
options.setPrompt(MessageFactory.text("please send an event."));
dc.prompt("EventActivityWithoutRetryPrompt", options).join();
} else if (results.getStatus() == DialogTurnStatus.COMPLETE) {
Activity content = (Activity) results.getResult();
Expand All @@ -223,7 +215,8 @@ public void OnPromptOverloadWithoutIsRetryParamReturnsBasicActivityPrompt() {
.assertReply("please send an event.")
.send(eventActivity)
.assertReply("2")
.startTest();
.startTest()
.join();
}

@Test
Expand Down
Loading