Skip to content

Commit 9583bb0

Browse files
authored
Override new "base" Terminate API (#2829)
1 parent f4aed61 commit 9583bb0

File tree

7 files changed

+101
-6
lines changed

7 files changed

+101
-6
lines changed

WebJobs.Extensions.DurableTask.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "PerfTests", "PerfTests", "{
9494
EndProject
9595
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DFPerfScenariosV4", "test\DFPerfScenarios\DFPerfScenariosV4.csproj", "{FC8AD123-F949-4D21-B817-E5A4BBF7F69B}"
9696
EndProject
97+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Worker.Extensions.DurableTask.Tests", "test\Worker.Extensions.DurableTask.Tests\Worker.Extensions.DurableTask.Tests.csproj", "{76DEC17C-BF6A-498A-8E8A-7D6CB2E03284}"
98+
EndProject
9799
Global
98100
GlobalSection(SolutionConfigurationPlatforms) = preSolution
99101
Debug|Any CPU = Debug|Any CPU
@@ -178,6 +180,10 @@ Global
178180
{FC8AD123-F949-4D21-B817-E5A4BBF7F69B}.Debug|Any CPU.Build.0 = Debug|Any CPU
179181
{FC8AD123-F949-4D21-B817-E5A4BBF7F69B}.Release|Any CPU.ActiveCfg = Release|Any CPU
180182
{FC8AD123-F949-4D21-B817-E5A4BBF7F69B}.Release|Any CPU.Build.0 = Release|Any CPU
183+
{76DEC17C-BF6A-498A-8E8A-7D6CB2E03284}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
184+
{76DEC17C-BF6A-498A-8E8A-7D6CB2E03284}.Debug|Any CPU.Build.0 = Debug|Any CPU
185+
{76DEC17C-BF6A-498A-8E8A-7D6CB2E03284}.Release|Any CPU.ActiveCfg = Release|Any CPU
186+
{76DEC17C-BF6A-498A-8E8A-7D6CB2E03284}.Release|Any CPU.Build.0 = Release|Any CPU
181187
EndGlobalSection
182188
GlobalSection(SolutionProperties) = preSolution
183189
HideSolutionNode = FALSE
@@ -211,6 +217,7 @@ Global
211217
{65F904AA-0F6F-48CB-BE19-593B7D68152A} = {7387E723-E153-4B7A-B105-8C67BFBD48CF}
212218
{7387E723-E153-4B7A-B105-8C67BFBD48CF} = {78BCF152-C22C-408F-9FB1-0F8C99B154B5}
213219
{FC8AD123-F949-4D21-B817-E5A4BBF7F69B} = {7387E723-E153-4B7A-B105-8C67BFBD48CF}
220+
{76DEC17C-BF6A-498A-8E8A-7D6CB2E03284} = {78BCF152-C22C-408F-9FB1-0F8C99B154B5}
214221
EndGlobalSection
215222
GlobalSection(ExtensibilityGlobals) = postSolution
216223
SolutionGuid = {5E9AC327-DE18-41A5-A55D-E44CB4281943}

release_notes.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
# Release Notes
22

3-
## Microsoft.Azure.Functions.Worker.Extensions.DurableTask 1.2.0
3+
## Microsoft.Azure.Functions.Worker.Extensions.DurableTask 1.2.1
44

55
### New Features
66

7-
- Add `suspendPostUri` and `resumePostUri` to the list of returned URIs in `CreateCheckStatusResponseAsync`. (https://github.com/Azure/azure-functions-durable-extension/pull/2785)
8-
- Fix `NotSupportedException` when calling `PurgeAllInstancesAsync` and `PurgeInstanceAsync`
7+
- Fix regression on `TerminateInstanceAsync` API causing invocations to fail with "unimplemented" exceptions (https://github.com/Azure/azure-functions-durable-extension/pull/2829).
98

109
### Bug Fixes
1110

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

4+
using System.Runtime.CompilerServices;
45
using Microsoft.Azure.Functions.Worker.Extensions.Abstractions;
56

67
// TODO: Find a way to generate this dynamically at build-time
78
[assembly: ExtensionInformation("Microsoft.Azure.WebJobs.Extensions.DurableTask", "2.13.3")]
9+
[assembly: InternalsVisibleTo("Worker.Extensions.DurableTask.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100cd1dabd5a893b40e75dc901fe7293db4a3caf9cd4d3e3ed6178d49cd476969abe74a9e0b7f4a0bb15edca48758155d35a4f05e6e852fff1b319d103b39ba04acbadd278c2753627c95e1f6f6582425374b92f51cca3deb0d2aab9de3ecda7753900a31f70a236f163006beefffe282888f85e3c76d1205ec7dfef7fa472a17b1")]

src/Worker.Extensions.DurableTask/FunctionsDurableTaskClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ public override Task SuspendInstanceAsync(
8585
}
8686

8787
public override Task TerminateInstanceAsync(
88-
string instanceId, object? output = null, CancellationToken cancellation = default)
88+
string instanceId, TerminateInstanceOptions? options = null, CancellationToken cancellation = default)
8989
{
90-
return this.inner.TerminateInstanceAsync(instanceId, output, cancellation);
90+
return this.inner.TerminateInstanceAsync(instanceId, options, cancellation);
9191
}
9292

9393
public override Task<OrchestrationMetadata> WaitForInstanceCompletionAsync(

src/Worker.Extensions.DurableTask/HTTP/HttpMethodConverter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ public override HttpMethod Read(
2020
Type objectType,
2121
JsonSerializerOptions options)
2222
{
23-
return new HttpMethod(reader.GetString());
23+
string readerString = reader.GetString() ?? string.Empty;
24+
return new HttpMethod(readerString);
2425
}
2526

2627
public override void Write(
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using Microsoft.DurableTask.Client;
2+
using Microsoft.DurableTask.Client.Grpc;
3+
using Moq;
4+
5+
namespace Microsoft.Azure.Functions.Worker.Tests
6+
{
7+
/// <summary>
8+
/// Unit tests for <see cref="FunctionsDurableTaskClient />.
9+
/// </summary>
10+
public class FunctionsDurableTaskClientTests
11+
{
12+
private FunctionsDurableTaskClient GetTestFunctionsDurableTaskClient()
13+
{
14+
// construct mock client
15+
16+
// The DurableTaskClient demands a string parameter in it's constructor, so we pass it in
17+
string clientName = string.Empty;
18+
Mock<DurableTaskClient> durableClientMock = new(clientName);
19+
20+
Task completedTask = Task.CompletedTask;
21+
durableClientMock.Setup(x => x.TerminateInstanceAsync(
22+
It.IsAny<string>(), It.IsAny<TerminateInstanceOptions>(), It.IsAny<CancellationToken>())).Returns(completedTask);
23+
24+
DurableTaskClient durableClient = durableClientMock.Object;
25+
FunctionsDurableTaskClient client = new FunctionsDurableTaskClient(durableClient, queryString: null);
26+
return client;
27+
}
28+
29+
/// <summary>
30+
/// Test that the `TerminateInstnaceAsync` can be invoked without exceptions.
31+
/// Exceptions are a risk since we inherit from an abstract class where default implementations are not provided.
32+
/// </summary>
33+
[Fact]
34+
public async void TerminateDoesNotThrow()
35+
{
36+
FunctionsDurableTaskClient client = GetTestFunctionsDurableTaskClient();
37+
38+
string instanceId = string.Empty;
39+
object output = string.Empty;
40+
TerminateInstanceOptions options = new TerminateInstanceOptions();
41+
CancellationToken token = CancellationToken.None;
42+
43+
// call terminate API with every possible parameter combination
44+
// if we don't encounter any unimplemented exceptions from the abstract class,
45+
// then the test passes
46+
47+
await client.TerminateInstanceAsync(instanceId, token);
48+
49+
await client.TerminateInstanceAsync(instanceId, output);
50+
await client.TerminateInstanceAsync(instanceId, output, token);
51+
52+
await client.TerminateInstanceAsync(instanceId);
53+
await client.TerminateInstanceAsync(instanceId, options);
54+
await client.TerminateInstanceAsync(instanceId, options, token);
55+
}
56+
}
57+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
8+
<IsPackable>false</IsPackable>
9+
<IsTestProject>true</IsTestProject>
10+
11+
<!-- Sign assembly so it can reference internal components of the Worker Extension package -->
12+
<SignAssembly>true</SignAssembly>
13+
<AssemblyOriginatorKeyFile>..\..\sign.snk</AssemblyOriginatorKeyFile>
14+
</PropertyGroup>
15+
16+
<ItemGroup>
17+
<PackageReference Include="coverlet.collector" Version="6.0.0" />
18+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
19+
<PackageReference Include="xunit" Version="2.5.3" />
20+
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
21+
<PackageReference Include="Moq" Version="4.7.145" />
22+
<ProjectReference Include="..\..\src\Worker.Extensions.DurableTask\Worker.Extensions.DurableTask.csproj" />
23+
</ItemGroup>
24+
25+
<ItemGroup>
26+
<Using Include="Xunit" />
27+
</ItemGroup>
28+
29+
</Project>

0 commit comments

Comments
 (0)