diff --git a/src/DurableTask.AzureServiceFabric/DurableTask.AzureServiceFabric.csproj b/src/DurableTask.AzureServiceFabric/DurableTask.AzureServiceFabric.csproj
index f283ca42d..63c71e52c 100644
--- a/src/DurableTask.AzureServiceFabric/DurableTask.AzureServiceFabric.csproj
+++ b/src/DurableTask.AzureServiceFabric/DurableTask.AzureServiceFabric.csproj
@@ -6,7 +6,7 @@
true
Microsoft.Azure.DurableTask.AzureServiceFabric
true
- 2.3.11
+ 2.3.12
$(Version)
$(Version)
Azure Service Fabric provider extension for the Durable Task Framework.
diff --git a/src/DurableTask.AzureServiceFabric/Remote/RemoteOrchestrationServiceClient.cs b/src/DurableTask.AzureServiceFabric/Remote/RemoteOrchestrationServiceClient.cs
index 51db1edda..2143dd414 100644
--- a/src/DurableTask.AzureServiceFabric/Remote/RemoteOrchestrationServiceClient.cs
+++ b/src/DurableTask.AzureServiceFabric/Remote/RemoteOrchestrationServiceClient.cs
@@ -317,12 +317,12 @@ private async Task PutJsonAsync(string instanceId, string fragment, object @obje
// TODO: Improve exception handling
if (result.StatusCode == HttpStatusCode.Conflict)
{
- throw await result.Content?.ReadAsAsync();
+ throw await (result.Content?.ReadAsAsync() ?? Task.FromResult(new OrchestrationAlreadyExistsException()));
}
if (!result.IsSuccessStatusCode)
{
- var content = await result.Content?.ReadAsStringAsync();
+ var content = await (result.Content?.ReadAsStringAsync() ?? Task.FromResult(null));
throw new RemoteServiceException($"CreateTaskOrchestrationAsync failed with status code {result.StatusCode}: {content}", result.StatusCode);
}
}
diff --git a/src/DurableTask.AzureServiceFabric/Service/FabricOrchestrationServiceController.cs b/src/DurableTask.AzureServiceFabric/Service/FabricOrchestrationServiceController.cs
index 12f7f1cef..dd3778dd9 100644
--- a/src/DurableTask.AzureServiceFabric/Service/FabricOrchestrationServiceController.cs
+++ b/src/DurableTask.AzureServiceFabric/Service/FabricOrchestrationServiceController.cs
@@ -69,13 +69,13 @@ public async Task CreateTaskOrchestration([FromUri] string or
return new OkResult(this);
}
- catch (OrchestrationAlreadyExistsException ex)
+ catch (OrchestrationAlreadyExistsException orchestrationAlreadyExistsException)
{
- return Content(System.Net.HttpStatusCode.Conflict, ex);
+ return Content(System.Net.HttpStatusCode.Conflict, orchestrationAlreadyExistsException);
}
- catch (NotSupportedException ex)
+ catch (NotSupportedException notSupportedException)
{
- return Content(System.Net.HttpStatusCode.BadRequest, ex);
+ return Content(System.Net.HttpStatusCode.BadRequest, notSupportedException);
}
}
diff --git a/test/DurableTask.AzureServiceFabric.Integration.Tests/DurableTask.AzureServiceFabric.Integration.Tests.csproj b/test/DurableTask.AzureServiceFabric.Integration.Tests/DurableTask.AzureServiceFabric.Integration.Tests.csproj
index f23978e45..39c5670e3 100644
--- a/test/DurableTask.AzureServiceFabric.Integration.Tests/DurableTask.AzureServiceFabric.Integration.Tests.csproj
+++ b/test/DurableTask.AzureServiceFabric.Integration.Tests/DurableTask.AzureServiceFabric.Integration.Tests.csproj
@@ -14,6 +14,7 @@
+
diff --git a/test/DurableTask.AzureServiceFabric.Integration.Tests/FunctionalTests.cs b/test/DurableTask.AzureServiceFabric.Integration.Tests/FunctionalTests.cs
index e2353a5b7..448568d8a 100644
--- a/test/DurableTask.AzureServiceFabric.Integration.Tests/FunctionalTests.cs
+++ b/test/DurableTask.AzureServiceFabric.Integration.Tests/FunctionalTests.cs
@@ -15,14 +15,15 @@ namespace DurableTask.AzureServiceFabric.Integration.Tests
{
using System;
using System.Collections.Generic;
+ using System.Net.Http;
+ using System.Threading;
using System.Threading.Tasks;
using DurableTask.AzureServiceFabric.Exceptions;
using DurableTask.Core;
using DurableTask.Core.Exceptions;
using DurableTask.Test.Orchestrations.Performance;
-
using Microsoft.VisualStudio.TestTools.UnitTesting;
-
+ using Moq;
using TestApplication.Common.Orchestrations;
[TestClass]
@@ -586,5 +587,42 @@ public async Task ScheduledStartTest_NotSupported()
var expectedStartTime = DateTime.UtcNow.AddSeconds(30);
await Assert.ThrowsExceptionAsync(() => this.taskHubClient.CreateScheduledOrchestrationInstanceAsync(typeof(SimpleOrchestrationWithTasks), null, expectedStartTime));
}
+
+ [TestMethod]
+ public async Task CreateTaskOrchestration_HandlesConflictResponse_When_HttpClientReturnsNullContent()
+ {
+ var httpClientMock = new Mock();
+ var response = new HttpResponseMessage(System.Net.HttpStatusCode.Conflict) { Content = null };
+ SetupHttpClientMockForPut(httpClientMock, response);
+
+ var taskHubClient = Utilities.CreateTaskHubClient((serviceClient) =>
+ {
+ serviceClient.HttpClient = httpClientMock.Object;
+ });
+
+ await Assert.ThrowsExceptionAsync(async () =>
+ {
+ await taskHubClient.CreateOrchestrationInstanceAsync(typeof(TestOrchestration), new TestOrchestrationData());
+ });
+ }
+
+ private static void SetupHttpClientMockForPut(Mock httpClientMock, HttpResponseMessage response)
+ {
+ httpClientMock
+ .Setup(x => x.PutAsync(It.IsAny(), It.IsAny()))
+ .ReturnsAsync(response);
+
+ httpClientMock
+ .Setup(x => x.PutAsync(It.IsAny(), It.IsAny()))
+ .ReturnsAsync(response);
+
+ httpClientMock
+ .Setup(x => x.PutAsync(It.IsAny(), It.IsAny(), It.IsAny()))
+ .ReturnsAsync(response);
+
+ httpClientMock
+ .Setup(x => x.PutAsync(It.IsAny(), It.IsAny(), It.IsAny()))
+ .ReturnsAsync(response);
+ }
}
}
diff --git a/test/DurableTask.AzureServiceFabric.Integration.Tests/Utilities.cs b/test/DurableTask.AzureServiceFabric.Integration.Tests/Utilities.cs
index a33b53b13..cca8a4989 100644
--- a/test/DurableTask.AzureServiceFabric.Integration.Tests/Utilities.cs
+++ b/test/DurableTask.AzureServiceFabric.Integration.Tests/Utilities.cs
@@ -17,22 +17,27 @@ namespace DurableTask.AzureServiceFabric.Integration.Tests
using System.Diagnostics;
using System.Net.Http;
using System.Threading.Tasks;
- using DurableTask.Core;
using DurableTask.AzureServiceFabric.Remote;
- using DurableTask.AzureServiceFabric.Service;
-
+ using DurableTask.Core;
using Microsoft.VisualStudio.TestTools.UnitTesting;
public static class Utilities
{
public static TaskHubClient CreateTaskHubClient()
+ {
+ return CreateTaskHubClient(_ => { });
+ }
+
+ public static TaskHubClient CreateTaskHubClient(Action setupServiceClient)
{
var partitionProvider = new FabricPartitionEndpointResolver(new Uri(Constants.TestFabricApplicationAddress), new DefaultStringPartitionHashing());
var httpClientHandler = new HttpClientHandler()
{
ServerCertificateCustomValidationCallback = (message, certificate, chain, errors) => true
};
- return new TaskHubClient(new RemoteOrchestrationServiceClient(partitionProvider, httpClientHandler));
+ var serviceClient = new RemoteOrchestrationServiceClient(partitionProvider, httpClientHandler);
+ setupServiceClient(serviceClient);
+ return new TaskHubClient(serviceClient);
}
public static async Task ThrowsException(Func action, string expectedMessage) where TException : Exception