diff --git a/src/WebJobs.Extensions.DurableTask/DurableTaskJobHostConfigurationExtensions.cs b/src/WebJobs.Extensions.DurableTask/DurableTaskJobHostConfigurationExtensions.cs index 1a7df3454..25ebcb92c 100644 --- a/src/WebJobs.Extensions.DurableTask/DurableTaskJobHostConfigurationExtensions.cs +++ b/src/WebJobs.Extensions.DurableTask/DurableTaskJobHostConfigurationExtensions.cs @@ -45,6 +45,9 @@ public static IServiceCollection AddDurableClientFactory(this IServiceCollection serviceCollection.TryAddSingleton(); serviceCollection.TryAddSingleton(); serviceCollection.TryAddSingleton(); +#pragma warning disable CS0612 // Type or member is obsolete + serviceCollection.TryAddSingleton(); +#pragma warning restore CS0612 // Type or member is obsolete return serviceCollection; } diff --git a/test/Common/DurableClientBaseTests.cs b/test/Common/DurableClientBaseTests.cs index f204dd475..308592252 100644 --- a/test/Common/DurableClientBaseTests.cs +++ b/test/Common/DurableClientBaseTests.cs @@ -7,7 +7,6 @@ using System.Net.Http; using System.Threading.Tasks; using DurableTask.Core; -using FluentAssertions; #if !FUNCTIONS_V1 using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; @@ -20,6 +19,7 @@ using Moq; using Newtonsoft.Json; using Xunit; +using Xunit.Abstractions; using static Microsoft.Azure.WebJobs.Extensions.DurableTask.Tests.HttpApiHandlerTests; namespace Microsoft.Azure.WebJobs.Extensions.DurableTask.Tests diff --git a/test/Common/DurableTaskEndToEndTests.cs b/test/Common/DurableTaskEndToEndTests.cs index 30fbdf3dc..ece0f92ff 100644 --- a/test/Common/DurableTaskEndToEndTests.cs +++ b/test/Common/DurableTaskEndToEndTests.cs @@ -194,6 +194,30 @@ public async Task HelloWorld_OrchestrationClientTaskHub(string storageProviderTy } } + /// + /// End to end test that ensures that DurableClientFactory is set up correctly + /// (i.e. the correct services are injected through dependency injection + /// and AzureStorageDurabilityProvider is created). + /// + [Fact] + [Trait("Category", PlatformSpecificHelpers.TestCategory)] + public async Task DurableClient_AzureStorage_SuccessfulSetup() + { + string orchestratorName = nameof(TestOrchestrations.SayHelloInline); + using (ITestHost host = TestHelpers.GetJobHost( + loggerProvider: this.loggerProvider, + testName: nameof(this.DurableClient_AzureStorage_SuccessfulSetup), + enableExtendedSessions: false, + storageProviderType: "azure_storage", + addDurableClientFactory: true)) + { + await host.StartAsync(); + var client = await host.StartOrchestratorAsync(orchestratorName, input: "World", this.output); + var status = await client.WaitForCompletionAsync(this.output); + await host.StopAsync(); + } + } + /// /// End-to-end test which validates a simple orchestrator function does not have assigned value for . /// diff --git a/test/Common/TestHelpers.cs b/test/Common/TestHelpers.cs index 25a06b269..646db5cfa 100644 --- a/test/Common/TestHelpers.cs +++ b/test/Common/TestHelpers.cs @@ -63,7 +63,8 @@ public static ITestHost GetJobHost( Action onSend = null, bool rollbackEntityOperationsOnExceptions = true, int entityMessageReorderWindowInMinutes = 30, - string exactTaskHubName = null) + string exactTaskHubName = null, + bool addDurableClientFactory = false) { switch (storageProviderType) { @@ -145,15 +146,18 @@ public static ITestHost GetJobHost( } return GetJobHostWithOptions( - loggerProvider, - options, - storageProviderType, - nameResolver, - durableHttpMessageHandler, - lifeCycleNotificationHelper, - serializerSettings, - onSend, - durabilityProviderFactoryType); + loggerProvider: loggerProvider, + durableTaskOptions: options, + storageProviderType: storageProviderType, + nameResolver: nameResolver, + durableHttpMessageHandler: durableHttpMessageHandler, + lifeCycleNotificationHelper: lifeCycleNotificationHelper, + serializerSettings: serializerSettings, + onSend: onSend, +#if !FUNCTIONS_V1 + addDurableClientFactory: addDurableClientFactory, +#endif + durabilityProviderFactoryType: durabilityProviderFactoryType); } public static ITestHost GetJobHostWithOptions( @@ -165,7 +169,8 @@ public static ITestHost GetJobHostWithOptions( ILifeCycleNotificationHelper lifeCycleNotificationHelper = null, IMessageSerializerSettingsFactory serializerSettings = null, Action onSend = null, - Type durabilityProviderFactoryType = null) + Type durabilityProviderFactoryType = null, + bool addDurableClientFactory = false) { if (serializerSettings == null) { @@ -184,6 +189,7 @@ public static ITestHost GetJobHostWithOptions( storageProvider: storageProviderType, #if !FUNCTIONS_V1 durabilityProviderFactoryType: durabilityProviderFactoryType, + addDurableClientFactory: addDurableClientFactory, #endif loggerProvider: loggerProvider, nameResolver: testNameResolver, diff --git a/test/FunctionsV2/PlatformSpecificHelpers.FunctionsV2.cs b/test/FunctionsV2/PlatformSpecificHelpers.FunctionsV2.cs index 50ab2fee8..a6d5db68a 100644 --- a/test/FunctionsV2/PlatformSpecificHelpers.FunctionsV2.cs +++ b/test/FunctionsV2/PlatformSpecificHelpers.FunctionsV2.cs @@ -34,7 +34,8 @@ public static ITestHost CreateJobHost( IDurableHttpMessageHandlerFactory durableHttpMessageHandler, ILifeCycleNotificationHelper lifeCycleNotificationHelper, IMessageSerializerSettingsFactory serializerSettingsFactory, - Action onSend) + Action onSend, + bool addDurableClientFactory) { // Unless otherwise specified, use legacy partition management for tests as it makes the task hubs start up faster. // These tests run on a single task hub workers, so they don't test partition management anyways, and that is tested @@ -53,7 +54,15 @@ public static ITestHost CreateJobHost( .ConfigureWebJobs( webJobsBuilder => { - webJobsBuilder.AddDurableTask(options, storageProvider, durabilityProviderFactoryType); + if (addDurableClientFactory) + { + webJobsBuilder.AddDurableClientFactoryDurableTask(options); + } + else + { + webJobsBuilder.AddDurableTask(options, storageProvider, durabilityProviderFactoryType); + } + webJobsBuilder.AddAzureStorage(); }) .ConfigureServices( @@ -157,6 +166,25 @@ private static IWebJobsBuilder AddMultipleDurabilityProvidersDurableTask(this IW return builder; } + /// + /// Registers the services needed for DurableClientFactory and calls AddDurableClientFactory() + /// which adds the Durable Task extension that uses Azure Storage. + /// + private static IWebJobsBuilder AddDurableClientFactoryDurableTask(this IWebJobsBuilder builder, IOptions options) + { + builder.Services.AddDurableClientFactory(); + + builder.Services.AddSingleton(options); + + var serviceCollection = builder.AddExtension() + .BindOptions() + .Services.AddSingleton(); + + serviceCollection.TryAddSingleton(); + + return builder; + } + private static IWebJobsBuilder AddRedisDurableTask(this IWebJobsBuilder builder) { builder.Services.AddSingleton();