Skip to content
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

Override new "base" Terminate API #2829

Merged
merged 7 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions WebJobs.Extensions.DurableTask.sln
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "PerfTests", "PerfTests", "{
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DFPerfScenariosV4", "test\DFPerfScenarios\DFPerfScenariosV4.csproj", "{FC8AD123-F949-4D21-B817-E5A4BBF7F69B}"
EndProject
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}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -178,6 +180,10 @@ Global
{FC8AD123-F949-4D21-B817-E5A4BBF7F69B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FC8AD123-F949-4D21-B817-E5A4BBF7F69B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FC8AD123-F949-4D21-B817-E5A4BBF7F69B}.Release|Any CPU.Build.0 = Release|Any CPU
{76DEC17C-BF6A-498A-8E8A-7D6CB2E03284}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{76DEC17C-BF6A-498A-8E8A-7D6CB2E03284}.Debug|Any CPU.Build.0 = Debug|Any CPU
{76DEC17C-BF6A-498A-8E8A-7D6CB2E03284}.Release|Any CPU.ActiveCfg = Release|Any CPU
{76DEC17C-BF6A-498A-8E8A-7D6CB2E03284}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -211,6 +217,7 @@ Global
{65F904AA-0F6F-48CB-BE19-593B7D68152A} = {7387E723-E153-4B7A-B105-8C67BFBD48CF}
{7387E723-E153-4B7A-B105-8C67BFBD48CF} = {78BCF152-C22C-408F-9FB1-0F8C99B154B5}
{FC8AD123-F949-4D21-B817-E5A4BBF7F69B} = {7387E723-E153-4B7A-B105-8C67BFBD48CF}
{76DEC17C-BF6A-498A-8E8A-7D6CB2E03284} = {78BCF152-C22C-408F-9FB1-0F8C99B154B5}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5E9AC327-DE18-41A5-A55D-E44CB4281943}
Expand Down
5 changes: 2 additions & 3 deletions release_notes.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# Release Notes

## Microsoft.Azure.Functions.Worker.Extensions.DurableTask 1.2.0
## Microsoft.Azure.Functions.Worker.Extensions.DurableTask 1.2.1

### New Features

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

### Bug Fixes

Expand Down
2 changes: 2 additions & 0 deletions src/Worker.Extensions.DurableTask/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System.Runtime.CompilerServices;
using Microsoft.Azure.Functions.Worker.Extensions.Abstractions;

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So that internal classes can be tested in the tests project. This is a standard pattern, and we use it for the DF WebJobs Extension tests afaik.

Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ public override Task SuspendInstanceAsync(
}

public override Task TerminateInstanceAsync(
string instanceId, object? output = null, CancellationToken cancellation = default)
string instanceId, TerminateInstanceOptions? options = null, CancellationToken cancellation = default)
{
return this.inner.TerminateInstanceAsync(instanceId, output, cancellation);
return this.inner.TerminateInstanceAsync(instanceId, options, cancellation);
}

public override Task<OrchestrationMetadata> WaitForInstanceCompletionAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public override HttpMethod Read(
Type objectType,
JsonSerializerOptions options)
{
return new HttpMethod(reader.GetString());
string readerString = reader.GetString() ?? string.Empty;
return new HttpMethod(readerString);
Comment on lines +23 to +24
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a small warning that reader.GetString() might return null. So I added this to make sure the method was well typed.

}

public override void Write(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using Microsoft.DurableTask.Client;
using Microsoft.DurableTask.Client.Grpc;
using Moq;

namespace Microsoft.Azure.Functions.Worker.Tests
{
/// <summary>
/// Unit tests for <see cref="FunctionsDurableTaskClient />.
/// </summary>
public class FunctionsDurableTaskClientTests
{
private FunctionsDurableTaskClient GetTestFunctionsDurableTaskClient()
{
// construct mock client

// The DurableTaskClient demands a string parameter in it's constructor, so we pass it in
string clientName = string.Empty;
Mock<DurableTaskClient> durableClientMock = new(clientName);

Task completedTask = Task.CompletedTask;
durableClientMock.Setup(x => x.TerminateInstanceAsync(
It.IsAny<string>(), It.IsAny<TerminateInstanceOptions>(), It.IsAny<CancellationToken>())).Returns(completedTask);

DurableTaskClient durableClient = durableClientMock.Object;
FunctionsDurableTaskClient client = new FunctionsDurableTaskClient(durableClient, queryString: null);
return client;
}

/// <summary>
/// Test that the `TerminateInstnaceAsync` can be invoked without exceptions.
/// Exceptions are a risk since we inherit from an abstract class where default implementations are not provided.
/// </summary>
[Fact]
public async void TerminateDoesNotThrow()
{
FunctionsDurableTaskClient client = GetTestFunctionsDurableTaskClient();

string instanceId = string.Empty;
object output = string.Empty;
TerminateInstanceOptions options = new TerminateInstanceOptions();
CancellationToken token = CancellationToken.None;

// call terminate API with every possible parameter combination
// if we don't encounter any unimplemented exceptions from the abstract class,
// then the test passes

await client.TerminateInstanceAsync(instanceId, token);

await client.TerminateInstanceAsync(instanceId, output);
await client.TerminateInstanceAsync(instanceId, output, token);

await client.TerminateInstanceAsync(instanceId);
await client.TerminateInstanceAsync(instanceId, options);
await client.TerminateInstanceAsync(instanceId, options, token);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>

<!-- Sign assembly so it can reference internal components of the Worker Extension package -->
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\sign.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.5.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
<PackageReference Include="Moq" Version="4.7.145" />
<ProjectReference Include="..\..\src\Worker.Extensions.DurableTask\Worker.Extensions.DurableTask.csproj" />
</ItemGroup>

<ItemGroup>
<Using Include="Xunit" />
</ItemGroup>

</Project>
Loading