From 6f2dbe8ebc03ef8feccfa1d234656aa9c673c361 Mon Sep 17 00:00:00 2001 From: David Justo Date: Mon, 4 Apr 2022 18:26:13 -0700 Subject: [PATCH] add test for external event patch e2e test setup encode as app/json remove typo in test-script patch httpContent's content --- .../DurableEndToEndTests.cs | 61 +++++++++++++++++++ .../function.json | 9 +++ .../DurableOrchestratorRaiseEvent/run.ps1 | 7 +++ 3 files changed, 77 insertions(+) create mode 100644 test/E2E/TestFunctionApp/DurableOrchestratorRaiseEvent/function.json create mode 100644 test/E2E/TestFunctionApp/DurableOrchestratorRaiseEvent/run.ps1 diff --git a/test/E2E/Azure.Functions.PowerShellWorker.E2E/Azure.Functions.PowerShellWorker.E2E/DurableEndToEndTests.cs b/test/E2E/Azure.Functions.PowerShellWorker.E2E/Azure.Functions.PowerShellWorker.E2E/DurableEndToEndTests.cs index 6d1243b8..181d294e 100644 --- a/test/E2E/Azure.Functions.PowerShellWorker.E2E/Azure.Functions.PowerShellWorker.E2E/DurableEndToEndTests.cs +++ b/test/E2E/Azure.Functions.PowerShellWorker.E2E/Azure.Functions.PowerShellWorker.E2E/DurableEndToEndTests.cs @@ -12,6 +12,7 @@ namespace Azure.Functions.PowerShell.Tests.E2E using System.Net.Http; using Newtonsoft.Json; + using System.Text; [Collection(Constants.FunctionAppCollectionName)] public class DurableEndToEndTests @@ -201,6 +202,66 @@ public async Task OrchestratationContextHasAllExpectedProperties() } } + [Fact] + public async Task ExternalEventReturnsData() + { + var initialResponse = await Utilities.GetHttpTriggerResponse("DurableClient", queryString: "?FunctionName=DurableOrchestratorRaiseEvent"); + Assert.Equal(HttpStatusCode.Accepted, initialResponse.StatusCode); + + var initialResponseBody = await initialResponse.Content.ReadAsStringAsync(); + dynamic initialResponseBodyObject = JsonConvert.DeserializeObject(initialResponseBody); + var statusQueryGetUri = (string)initialResponseBodyObject.statusQueryGetUri; + var raiseEventUri = (string)initialResponseBodyObject.sendEventPostUri; + + raiseEventUri = raiseEventUri.Replace("{eventName}", "TESTEVENTNAME"); + + var startTime = DateTime.UtcNow; + + using (var httpClient = new HttpClient()) + { + while (true) + { + // Send external event payload + var json = JsonConvert.SerializeObject("helloWorld!"); + var httpContent = new StringContent(json, Encoding.UTF8, "application/json"); + await httpClient.PostAsync(raiseEventUri, httpContent); + + var statusResponse = await httpClient.GetAsync(statusQueryGetUri); + switch (statusResponse.StatusCode) + { + case HttpStatusCode.Accepted: + { + var statusResponseBody = await GetResponseBodyAsync(statusResponse); + var runtimeStatus = (string)statusResponseBody.runtimeStatus; + Assert.True( + runtimeStatus == "Running" || runtimeStatus == "Pending", + $"Unexpected runtime status: {runtimeStatus}"); + + if (DateTime.UtcNow > startTime + _orchestrationCompletionTimeout) + { + Assert.True(false, $"The orchestration has not completed after {_orchestrationCompletionTimeout}"); + } + + await Task.Delay(TimeSpan.FromSeconds(2)); + break; + } + + case HttpStatusCode.OK: + { + var statusResponseBody = await GetResponseBodyAsync(statusResponse); + Assert.Equal("Completed", (string)statusResponseBody.runtimeStatus); + Assert.Equal("helloWorld!", statusResponseBody.output.ToString()); + return; + } + + default: + Assert.True(false, $"Unexpected orchestration status code: {statusResponse.StatusCode}"); + break; + } + } + } + } + [Fact] public async Task ActivityCanHaveQueueBinding() { diff --git a/test/E2E/TestFunctionApp/DurableOrchestratorRaiseEvent/function.json b/test/E2E/TestFunctionApp/DurableOrchestratorRaiseEvent/function.json new file mode 100644 index 00000000..336f5a18 --- /dev/null +++ b/test/E2E/TestFunctionApp/DurableOrchestratorRaiseEvent/function.json @@ -0,0 +1,9 @@ +{ + "bindings": [ + { + "name": "Context", + "type": "orchestrationTrigger", + "direction": "in" + } + ] +} \ No newline at end of file diff --git a/test/E2E/TestFunctionApp/DurableOrchestratorRaiseEvent/run.ps1 b/test/E2E/TestFunctionApp/DurableOrchestratorRaiseEvent/run.ps1 new file mode 100644 index 00000000..f7b9360b --- /dev/null +++ b/test/E2E/TestFunctionApp/DurableOrchestratorRaiseEvent/run.ps1 @@ -0,0 +1,7 @@ +param($Context) + +$output = @() + +$output += Start-DurableExternalEventListener -EventName "TESTEVENTNAME" + +$output