Skip to content

Commit

Permalink
add test for external event
Browse files Browse the repository at this point in the history
patch e2e test setup

encode as app/json

remove typo in test-script

patch httpContent's content
  • Loading branch information
davidmrdavid committed Apr 5, 2022
1 parent 76ea57e commit 6f2dbe8
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"bindings": [
{
"name": "Context",
"type": "orchestrationTrigger",
"direction": "in"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
param($Context)

$output = @()

$output += Start-DurableExternalEventListener -EventName "TESTEVENTNAME"

$output

0 comments on commit 6f2dbe8

Please sign in to comment.