Skip to content

Commit

Permalink
Use async/await for async operations
Browse files Browse the repository at this point in the history
  • Loading branch information
andystaples committed Jan 31, 2025
1 parent f1b0b25 commit f6a9665
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
14 changes: 7 additions & 7 deletions test/e2e/Tests/Helpers/DurableHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,23 @@ private static string TokenizeAndGetValueFromKeyAsString(string? json, string ke
return statusQueryGetUri ?? string.Empty;
}

internal static string ParseStatusQueryGetUri(HttpResponseMessage invocationStartResponse)
internal static async Task<string> ParseStatusQueryGetUri(HttpResponseMessage invocationStartResponse)
{
string? responseString = invocationStartResponse.Content?.ReadAsStringAsync().Result;
string? responseString = await invocationStartResponse.Content.ReadAsStringAsync();
return TokenizeAndGetValueFromKeyAsString(responseString, "StatusQueryGetUri");
}

internal static string ParseInstanceId(HttpResponseMessage invocationStartResponse)
internal static async Task<string> ParseInstanceId(HttpResponseMessage invocationStartResponse)
{
string? responseString = invocationStartResponse.Content?.ReadAsStringAsync().Result;
string? responseString = await invocationStartResponse.Content.ReadAsStringAsync();
return TokenizeAndGetValueFromKeyAsString(responseString, "Id");
}

internal static OrchestrationStatusDetails GetRunningOrchestrationDetails(string statusQueryGetUri)
internal static async Task<OrchestrationStatusDetails> GetRunningOrchestrationDetails(string statusQueryGetUri)
{
var statusQueryResponse = _httpClient.GetAsync(statusQueryGetUri);
var statusQueryResponse = await _httpClient.GetAsync(statusQueryGetUri);

string? statusQueryResponseString = statusQueryResponse.Result.Content.ReadAsStringAsync().Result;
string? statusQueryResponseString = statusQueryResponse.Content.ReadAsStringAsync().Result;

return new OrchestrationStatusDetails(statusQueryResponseString);
}
Expand Down
10 changes: 5 additions & 5 deletions test/e2e/Tests/Tests/HelloCitiesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,28 +61,28 @@ public async Task ScheduledStartTests(string functionName, int startDelaySeconds
using HttpResponseMessage response = await HttpHelpers.InvokeHttpTrigger(functionName, urlQueryString);
string actualMessage = await response.Content.ReadAsStringAsync();

string statusQueryGetUri = DurableHelpers.ParseStatusQueryGetUri(response);
string statusQueryGetUri = await DurableHelpers.ParseStatusQueryGetUri(response);

Assert.Equal(expectedStatusCode, response.StatusCode);

var orchestrationDetails = DurableHelpers.GetRunningOrchestrationDetails(statusQueryGetUri);
var orchestrationDetails = await DurableHelpers.GetRunningOrchestrationDetails(statusQueryGetUri);
while (DateTime.UtcNow < scheduledStartTime + TimeSpan.FromSeconds(-1))
{
WriteOutput($"Test scheduled for {scheduledStartTime}, current time {DateTime.Now}");
orchestrationDetails = DurableHelpers.GetRunningOrchestrationDetails(statusQueryGetUri);
orchestrationDetails = await DurableHelpers.GetRunningOrchestrationDetails(statusQueryGetUri);
Assert.Equal("Pending", orchestrationDetails.RuntimeStatus);
Thread.Sleep(1000);
}

// Give a small amount of time for the orchestration to complete, even if scheduled to run immediately
Thread.Sleep(3000);
WriteOutput($"Test scheduled for {scheduledStartTime}, current time {DateTime.Now}, looking for completed");
var finalOrchestrationDetails = DurableHelpers.GetRunningOrchestrationDetails(statusQueryGetUri);
var finalOrchestrationDetails = await DurableHelpers.GetRunningOrchestrationDetails(statusQueryGetUri);
int retryAttempts = 0;
while (finalOrchestrationDetails.RuntimeStatus != "Completed" && retryAttempts < 10)
{
Thread.Sleep(1000);
finalOrchestrationDetails = DurableHelpers.GetRunningOrchestrationDetails(statusQueryGetUri);
finalOrchestrationDetails = await DurableHelpers.GetRunningOrchestrationDetails(statusQueryGetUri);
retryAttempts++;
}
Assert.Equal("Completed", finalOrchestrationDetails.RuntimeStatus);
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/Tests/Tests/TerminateOrchestratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public async Task TerminateRunningOrchestration_ShouldSucceed(string functionNam
string actualMessage = await response.Content.ReadAsStringAsync();

Assert.Equal(HttpStatusCode.Accepted, response.StatusCode);
string instanceId = DurableHelpers.ParseInstanceId(response);
string statusQueryGetUri = DurableHelpers.ParseStatusQueryGetUri(response);
string instanceId = await DurableHelpers.ParseInstanceId(response);
string statusQueryGetUri = await DurableHelpers.ParseStatusQueryGetUri(response);

Thread.Sleep(1000);

Expand Down

0 comments on commit f6a9665

Please sign in to comment.