Skip to content

Commit

Permalink
Patch regression in ExternalEvent History-search (#857) (#861)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmrdavid authored Sep 8, 2022
1 parent 833f55b commit bd4aaa4
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/DurableSDK/Tasks/ExternalEventTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal override HistoryEvent GetCompletedHistoryEvent(OrchestrationContext con
return context.History.FirstOrDefault(
e => e.EventType == HistoryEventType.EventRaised &&
e.Name == ExternalEventName &&
e.IsPlayed == processed);
e.IsProcessed == processed);
}

internal override OrchestrationAction CreateOrchestrationAction()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,67 @@ public async Task OrchestratationContextHasAllExpectedProperties()
}
}


[Fact]
public async Task ComplexExternalEventReturnsData()
{
var initialResponse = await Utilities.GetHttpTriggerResponse("DurableClient", queryString: "?FunctionName=DurableOrchestratorComplexRaiseEvent");
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.Contains("helloWorld!", statusResponseBody.output.ToString());
return;
}

default:
Assert.True(false, $"Unexpected orchestration status code: {statusResponse.StatusCode}");
break;
}
}
}
}

[Fact]
public async Task ExternalEventReturnsData()
{
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,10 @@
param($Context)

$output = @()

Invoke-DurableActivity -FunctionName "DurableActivity" -Input "Tokyo"
Invoke-DurableActivity -FunctionName "DurableActivity" -Input "Seattle"
$output += Start-DurableExternalEventListener -EventName "TESTEVENTNAME"
Invoke-DurableActivity -FunctionName "DurableActivity" -Input "London"

$output

0 comments on commit bd4aaa4

Please sign in to comment.