-
Notifications
You must be signed in to change notification settings - Fork 281
Add RestartAsync at Durable Functions Isolated #3147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
fb50ef3
initial commit
nytian 23cb325
add blnk line
nytian a1cbbf1
sort usings
nytian fb0ce5d
Merge branch 'dev' into nytian/restart
nytian 6e1a1fd
udpate implementatio
nytian 2a5d01d
merge latest from dev
nytian 5254623
remove unnecessary usings
nytian 1fab39b
don't restart instace with same instanceid if not completed
nytian ea56573
update protobuf
nytian d379922
inc ver and update tests
nytian ef5976c
Merge branch 'dev' into nytian/restart
nytian 4c2fdbb
inc ver and update test
nytian 382dc4e
merge from latest
nytian dcddb6e
undo unnecessary change
nytian e91868d
skip non dotnet language for test
nytian 8199677
updates test
nytian d3888de
remove unnecessary local added doc
nytian 3c35c9a
update bycomments
nytian 43c83aa
remove using
nytian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
| // Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
|
||
| using Microsoft.Azure.Functions.Worker; | ||
| using Microsoft.Azure.Functions.Worker.Http; | ||
| using Microsoft.DurableTask; | ||
| using Microsoft.DurableTask.Client; | ||
| using Microsoft.Extensions.Logging; | ||
| using System.Net; | ||
|
|
||
| namespace Microsoft.Azure.Durable.Tests.E2E; | ||
|
|
||
| public static class RestartOrchestration | ||
| { | ||
| [Function(nameof(RestartOrchestrator))] | ||
| public static string RestartOrchestrator( | ||
| [OrchestrationTrigger] TaskOrchestrationContext context) | ||
| { | ||
| string? input = context.GetInput<string>(); | ||
| return "Hello " + input; | ||
| } | ||
|
|
||
| [Function("RestartOrchestration_HttpStart")] | ||
| public static async Task<HttpResponseData> HttpStartRestartOrchestration( | ||
| [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req, | ||
| [DurableClient] DurableTaskClient client, | ||
| FunctionContext executionContext) | ||
| { | ||
| string instanceId = await client.ScheduleNewOrchestrationInstanceAsync(nameof(RestartOrchestrator), input: "World"); | ||
| return await client.CreateCheckStatusResponseAsync(req, instanceId); | ||
| } | ||
|
|
||
| public class RestartRequest | ||
| { | ||
| public string InstanceId { get; set; } = string.Empty; | ||
| public bool RestartWithNewInstanceId { get; set; } | ||
| } | ||
|
|
||
| [Function("RestartOrchestration_HttpRestart")] | ||
| public static async Task<HttpResponseData> HttpRestartOrchestration( | ||
| [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req, | ||
| [DurableClient] DurableTaskClient client, | ||
| FunctionContext executionContext) | ||
| { | ||
| var data = await req.ReadFromJsonAsync<RestartRequest>(); | ||
| if (data == null) | ||
| { | ||
| return req.CreateResponse(HttpStatusCode.BadRequest); | ||
| } | ||
| string newInstanceId = await client.RestartAsync(data.InstanceId,data.RestartWithNewInstanceId); | ||
|
|
||
| return await client.CreateCheckStatusResponseAsync(req, newInstanceId); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
| // Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
|
||
| using System.Net; | ||
| using System.Text.Json; | ||
| using Xunit; | ||
| using Xunit.Abstractions; | ||
|
|
||
| namespace Microsoft.Azure.Durable.Tests.DotnetIsolatedE2E; | ||
|
|
||
| [Collection(Constants.FunctionAppCollectionName)] | ||
| public class RestartOrchestrationTests | ||
| { | ||
| private readonly FunctionAppFixture fixture; | ||
| private readonly ITestOutputHelper output; | ||
|
|
||
| public RestartOrchestrationTests(FunctionAppFixture fixture, ITestOutputHelper testOutputHelper) | ||
| { | ||
| this.fixture = fixture; | ||
| this.fixture.TestLogs.UseTestLogger(testOutputHelper); | ||
| this.output = testOutputHelper; | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData(false)] | ||
| [InlineData(true)] | ||
| // Test behavior of restartasync of durabletaskclient. | ||
| // when restart with a instanceid and startwithnewinstanceid is false, the orchestration should be restarted with the same instance id. | ||
| // and the output should be the same as the original orchestration. | ||
| // when restart with a instanceid and startwithnewinstanceid is true, the orchestration should be restarted with a new instance id. | ||
| // and the output should be same as the original orchestration. | ||
| public async Task RestartOrchestration_CreatedTimeAndOutputChange(bool restartWithNewInstanceId) | ||
| { | ||
| // Start the orchestration | ||
| using HttpResponseMessage response = await HttpHelpers.InvokeHttpTrigger("RestartOrchestration_HttpStart", ""); | ||
| Assert.Equal(HttpStatusCode.Accepted, response.StatusCode); | ||
| string statusQueryGetUri = await DurableHelpers.ParseStatusQueryGetUriAsync(response); | ||
| string instanceId = await DurableHelpers.ParseInstanceIdAsync(response); | ||
|
|
||
| await DurableHelpers.WaitForOrchestrationStateAsync(statusQueryGetUri, "Completed", 10); | ||
| var orchestrationDetails = await DurableHelpers.GetRunningOrchestrationDetailsAsync(statusQueryGetUri); | ||
| string output1 = orchestrationDetails.Output; | ||
| DateTime createdTime1 = orchestrationDetails.CreatedTime; | ||
|
|
||
| // best practice to wait for 1 seconds before restarting orchestration to avoid race condition. | ||
| await Task.Delay(1000); | ||
|
|
||
| var restartPayload = new { | ||
| InstanceId = instanceId, | ||
| RestartWithNewInstanceId = restartWithNewInstanceId | ||
| }; | ||
|
|
||
| string jsonBody = JsonSerializer.Serialize(restartPayload); | ||
|
|
||
| // Restart the orchestrator with the same instance id) | ||
| using HttpResponseMessage restartResponse = await HttpHelpers.InvokeHttpTriggerWithBody( | ||
| "RestartOrchestration_HttpRestart", jsonBody, "application/json"); | ||
| Assert.Equal(HttpStatusCode.Accepted, restartResponse.StatusCode); | ||
| string restartStatusQueryGetUri = await DurableHelpers.ParseStatusQueryGetUriAsync(restartResponse); | ||
| string restartInstanceId = await DurableHelpers.ParseInstanceIdAsync(restartResponse); | ||
|
|
||
| await DurableHelpers.WaitForOrchestrationStateAsync(restartStatusQueryGetUri, "Completed", 10); | ||
| var restartOrchestrationDetails = await DurableHelpers.GetRunningOrchestrationDetailsAsync(restartStatusQueryGetUri); | ||
| string output2 = restartOrchestrationDetails.Output; | ||
| DateTime createdTime2 = restartOrchestrationDetails.CreatedTime; | ||
|
|
||
| // The outputs and created times should be different | ||
| Assert.Equal(output1, output2); | ||
| Assert.NotEqual(createdTime1, createdTime2); | ||
|
|
||
| if (restartWithNewInstanceId) | ||
| { | ||
| // If restartWithNewInstanceId is True, the two instanceId should be different. | ||
| Assert.NotEqual(instanceId, restartInstanceId); | ||
| } | ||
| else | ||
| { | ||
| Assert.Equal(instanceId, restartInstanceId); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.