Repository navigation
Fix Durable client current-app detection #3528
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
Open
wangbill (YunchuWang)
wants to merge
10
commits into
dev
Choose a base branch
from
yunchuwang-fix-durable-client-current-app-detection
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
917a5e6
Fix durable client current-app detection
YunchuWang 7214b93
Merge branch 'dev' into yunchuwang-fix-durable-client-current-app-det…
YunchuWang f6bc0cf
Add Azure Storage current-app E2E coverage
YunchuWang 7ca55a1
Configure secondary Azurite in public E2E CI
YunchuWang 463fb96
Merge latest dev into current-app fix
YunchuWang c6d5767
Dispose Azure Storage service in E2E cleanup
YunchuWang 6af50cb
Use provider hub semantics for client selection
YunchuWang 8b7b18b
Preserve provider identity in durable client caches
YunchuWang b31f039
test: cover hosted durable client cache modes
YunchuWang 107e606
Merge branch 'dev' into yunchuwang-fix-durable-client-current-app-det…
YunchuWang 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
Some comments aren't visible on the classic Files Changed page.
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
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
14 changes: 14 additions & 0 deletions
14
test/FunctionsV2/FunctionApp/CurrentAppDetectionFunctions.cs
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,14 @@ | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
| // Licensed under the MIT License. See LICENSE in the project root for license information. | ||
|
|
||
| namespace Microsoft.Azure.WebJobs.Extensions.DurableTask.Tests | ||
| { | ||
| internal static class CurrentAppDetectionFunctions | ||
| { | ||
| public static string TargetOnlyOrchestrator( | ||
| [OrchestrationTrigger] IDurableOrchestrationContext context) | ||
| { | ||
| return $"target:{context.GetInput<string>()}"; | ||
| } | ||
| } | ||
| } |
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,235 @@ | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
| // Licensed under the MIT License. See LICENSE in the project root for license information. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Diagnostics; | ||
| using System.Threading.Tasks; | ||
| using DurableTask.AzureStorage; | ||
| using Microsoft.Azure.WebJobs.Host; | ||
| using Microsoft.Azure.WebJobs.Host.TestCommon; | ||
| using Xunit; | ||
| using Xunit.Abstractions; | ||
|
|
||
| namespace Microsoft.Azure.WebJobs.Extensions.DurableTask.Tests | ||
| { | ||
| [Trait("TestType", "E2E")] | ||
| public class CurrentAppDetectionTests | ||
| { | ||
| private const string SecondaryStorageSettingName = "SecondaryStorage"; | ||
|
|
||
| private readonly ITestOutputHelper output; | ||
| private readonly TestLoggerProvider loggerProvider; | ||
|
|
||
| public CurrentAppDetectionTests(ITestOutputHelper output) | ||
| { | ||
| this.output = output; | ||
| this.loggerProvider = new TestLoggerProvider(output); | ||
| } | ||
|
|
||
| [Fact] | ||
| [Trait("Category", PlatformSpecificHelpers.TestCategory)] | ||
| public async Task AzureStorage_CaseVariantTaskHub_DisabledOrchestratorIsRejected() | ||
| { | ||
| string taskHubName = TestHelpers.GetTaskHubNameFromTestName( | ||
| nameof(this.AzureStorage_CaseVariantTaskHub_DisabledOrchestratorIsRejected), | ||
| enableExtendedSessions: false); | ||
| string caseVariantTaskHub = taskHubName.ToUpperInvariant(); | ||
| string instanceId = $"case-disabled-{Guid.NewGuid():N}"; | ||
| var nameResolver = new SimpleNameResolver( | ||
| new Dictionary<string, string> | ||
| { | ||
| { "TestTaskHub", caseVariantTaskHub }, | ||
| }); | ||
|
|
||
| try | ||
| { | ||
| using ITestHost host = TestHelpers.GetJobHost( | ||
| this.loggerProvider, | ||
| nameof(this.AzureStorage_CaseVariantTaskHub_DisabledOrchestratorIsRejected), | ||
| enableExtendedSessions: false, | ||
| nameResolver: nameResolver, | ||
| storageProviderType: TestHelpers.AzureStorageProviderType, | ||
| exactTaskHubName: taskHubName); | ||
| await host.StartAsync(); | ||
|
|
||
| Exception exception = await Record.ExceptionAsync( | ||
| () => host.StartOrchestratorAsync( | ||
| nameof(TestOrchestrations.DisabledOrchestrator), | ||
| input: null, | ||
| this.output, | ||
| instanceId, | ||
| useTaskHubFromAppSettings: true)); | ||
|
|
||
| IDurableOrchestrationClient defaultClient = | ||
| await host.GetOrchestrationClientBindingTest(this.output); | ||
| if (exception == null) | ||
| { | ||
| DurableOrchestrationStatus persistedStatus = | ||
| await WaitForInstanceAsync(defaultClient, instanceId); | ||
| Assert.Fail( | ||
| $"The case-variant client accepted and persisted the disabled orchestration " + | ||
| $"with status {persistedStatus.RuntimeStatus}."); | ||
| } | ||
|
|
||
| FunctionInvocationException invocationException = | ||
| Assert.IsType<FunctionInvocationException>(exception); | ||
| Assert.Contains( | ||
| "doesn't exist, is disabled, or is not an orchestrator function", | ||
| invocationException.InnerException?.ToString()); | ||
| await AssertInstanceRemainsAbsentAsync(defaultClient, instanceId); | ||
|
|
||
| await host.StopAsync(); | ||
| } | ||
| finally | ||
| { | ||
| await DeleteTaskHubAsync(taskHubName, TestHelpers.GetStorageConnectionString()); | ||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| [Trait("Category", PlatformSpecificHelpers.TestCategory)] | ||
| public async Task AzureStorage_DifferentConnection_SameTaskHub_ReachesTargetBackend() | ||
| { | ||
| string taskHubName = TestHelpers.GetTaskHubNameFromTestName( | ||
| nameof(this.AzureStorage_DifferentConnection_SameTaskHub_ReachesTargetBackend), | ||
| enableExtendedSessions: false); | ||
| string instanceId = $"cross-account-{Guid.NewGuid():N}"; | ||
| string secondaryConnection = GetSecondaryStorageConnectionString(); | ||
| var nameResolver = new SimpleNameResolver( | ||
| new Dictionary<string, string> | ||
| { | ||
| { "TestTaskHub", taskHubName }, | ||
| { SecondaryStorageSettingName, secondaryConnection }, | ||
| }); | ||
| var targetOptions = new DurableTaskOptions | ||
| { | ||
| HubName = taskHubName, | ||
| }; | ||
| targetOptions.StorageProvider["ConnectionName"] = SecondaryStorageSettingName; | ||
|
|
||
| try | ||
| { | ||
| using ITestHost sourceHost = TestHelpers.GetJobHost( | ||
| this.loggerProvider, | ||
| nameof(this.AzureStorage_DifferentConnection_SameTaskHub_ReachesTargetBackend), | ||
| enableExtendedSessions: false, | ||
| nameResolver: nameResolver, | ||
| storageProviderType: TestHelpers.AzureStorageProviderType, | ||
| exactTaskHubName: taskHubName, | ||
| types: new[] { typeof(ClientFunctions) }); | ||
| using ITestHost targetHost = TestHelpers.GetJobHostWithOptions( | ||
| this.loggerProvider, | ||
| targetOptions, | ||
| nameResolver: nameResolver, | ||
| types: new[] { typeof(CurrentAppDetectionFunctions) }); | ||
|
|
||
| await targetHost.StartAsync(); | ||
| await sourceHost.StartAsync(); | ||
|
|
||
| TestDurableClient targetClient = await this.StartOnSecondaryStorageAsync( | ||
| sourceHost, | ||
| nameof(CurrentAppDetectionFunctions.TargetOnlyOrchestrator), | ||
| input: "completed", | ||
| instanceId); | ||
| DurableOrchestrationStatus targetStatus = | ||
| await targetClient.WaitForCompletionAsync(this.output); | ||
|
|
||
| Assert.Equal(OrchestrationRuntimeStatus.Completed, targetStatus.RuntimeStatus); | ||
| Assert.Equal("target:completed", targetStatus.Output); | ||
|
|
||
| IDurableOrchestrationClient sourceClient = | ||
| await sourceHost.GetOrchestrationClientBindingTest(this.output); | ||
| await AssertInstanceRemainsAbsentAsync(sourceClient, instanceId); | ||
|
|
||
| await sourceHost.StopAsync(); | ||
| await targetHost.StopAsync(); | ||
| } | ||
| finally | ||
| { | ||
| await Task.WhenAll( | ||
| DeleteTaskHubAsync(taskHubName, TestHelpers.GetStorageConnectionString()), | ||
| DeleteTaskHubAsync(taskHubName, secondaryConnection)); | ||
| } | ||
| } | ||
|
|
||
| private static async Task AssertInstanceRemainsAbsentAsync( | ||
| IDurableOrchestrationClient client, | ||
| string instanceId) | ||
| { | ||
| int observations = 0; | ||
| Stopwatch stopwatch = Stopwatch.StartNew(); | ||
| do | ||
| { | ||
| Assert.Null(await client.GetStatusAsync(instanceId)); | ||
| observations++; | ||
| await Task.Delay(TimeSpan.FromMilliseconds(200)); | ||
| } | ||
| while (stopwatch.Elapsed < TimeSpan.FromSeconds(2)); | ||
|
|
||
| Assert.True(observations >= 3); | ||
| } | ||
|
|
||
| private async Task<TestDurableClient> StartOnSecondaryStorageAsync( | ||
| ITestHost host, | ||
| string functionName, | ||
| object input, | ||
| string instanceId) | ||
| { | ||
| var clientRef = new TestDurableClient[1]; | ||
| var arguments = new Dictionary<string, object> | ||
| { | ||
| { "functionName", functionName }, | ||
| { "instanceId", instanceId }, | ||
| { "input", input }, | ||
| { "clientRef", clientRef }, | ||
| }; | ||
|
|
||
| await host.CallAsync( | ||
| typeof(ClientFunctions).GetMethod(nameof(ClientFunctions.StartFunctionWithConnection)), | ||
| arguments); | ||
| this.output.WriteLine($"Started {functionName}, Instance ID = {clientRef[0].InstanceId}"); | ||
| return clientRef[0]; | ||
| } | ||
|
|
||
| private static async Task<DurableOrchestrationStatus> WaitForInstanceAsync( | ||
| IDurableOrchestrationClient client, | ||
| string instanceId) | ||
| { | ||
| Stopwatch stopwatch = Stopwatch.StartNew(); | ||
| do | ||
| { | ||
| DurableOrchestrationStatus status = await client.GetStatusAsync(instanceId); | ||
| if (status != null) | ||
| { | ||
| return status; | ||
| } | ||
|
|
||
| await Task.Delay(TimeSpan.FromMilliseconds(200)); | ||
| } | ||
| while (stopwatch.Elapsed < TimeSpan.FromSeconds(30)); | ||
|
|
||
| throw new TimeoutException($"Instance '{instanceId}' was accepted but did not persist."); | ||
| } | ||
|
|
||
| private static async Task DeleteTaskHubAsync(string taskHubName, string connectionString) | ||
| { | ||
| var settings = new AzureStorageOrchestrationServiceSettings | ||
| { | ||
| TaskHubName = taskHubName, | ||
| StorageAccountClientProvider = new StorageAccountClientProvider(connectionString), | ||
| }; | ||
| using var service = new AzureStorageOrchestrationService(settings); | ||
| await service.DeleteAsync(); | ||
| } | ||
|
|
||
| private static string GetSecondaryStorageConnectionString() | ||
| { | ||
| string connectionString = Environment.GetEnvironmentVariable(SecondaryStorageSettingName); | ||
| return !string.IsNullOrWhiteSpace(connectionString) | ||
| ? connectionString | ||
| : throw new InvalidOperationException( | ||
| $"The {SecondaryStorageSettingName} environment variable must point to the secondary Azurite instance."); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
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.