-
Notifications
You must be signed in to change notification settings - Fork 272
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
Implement CreateHttpManagementPayload API in Durable Worker Extension #2929
Conversation
/// A minimal implementation of FunctionContext for testing purposes. | ||
/// It's used to create a TestHttpRequestData instance, which requires a FunctionContext. | ||
/// </summary> | ||
public class TestFunctionContext : FunctionContext |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’ve added these classes to simulate HttpResponseData
for testing the CreateHttpManagementPayload
method with a HttpResponseData
instance, specifically for the CreateHttpManagementPayload_WithHttpRequestData() test. Let me know if you think this approach is overly complex or if there’s a more efficient way to handle this testing. I’m open to removing these classes if needed.:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the manual way to do it, which is fine. A way to do it with less code would be to use Moq
(which can generate these kinds of fakes dynamically), but no need to change what you've already done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! A few small suggestions.
test/Worker.Extensions.DurableTask.Tests/FunctionsDurableTaskClientTests.cs
Outdated
Show resolved
Hide resolved
/// A minimal implementation of FunctionContext for testing purposes. | ||
/// It's used to create a TestHttpRequestData instance, which requires a FunctionContext. | ||
/// </summary> | ||
public class TestFunctionContext : FunctionContext |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the manual way to do it, which is fine. A way to do it with less code would be to use Moq
(which can generate these kinds of fakes dynamically), but no need to change what you've already done.
test/Worker.Extensions.DurableTask.Tests/FunctionsDurableTaskClientTests.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few questions, looks great. I appreciate the test!
} | ||
|
||
public string? QueryString { get; } | ||
|
||
public string? HttpBaseUrl { get; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it allowed for this string to ever be null? If not, I'd recommend removing the ?
from the string
type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the DurableTaskClient
isn’t an instance of FunctionsDurableTaskClient
, then HttpBaseUrl could be null, as it’s only an attribute of FunctionsDurableTaskClient
. I’m not entirely sure in what scenario the DurableTaskClient wouldn’t be a FunctionsDurableTaskClient—perhaps it could happen if bindings aren’t being used. That’s why I added an exception for cases where the base URL creation fails.
src/Worker.Extensions.DurableTask/DurableTaskClientExtensions.cs
Outdated
Show resolved
Hide resolved
response.Headers.Add("Location", BuildUrl(instanceUrl, commonQueryParameters)); | ||
response.Headers.Add("Content-Type", "application/json"); | ||
|
||
if (response != null) | ||
{ | ||
response.Headers.Add("Location", BuildUrl(instanceUrl, commonQueryParameters)); | ||
response.Headers.Add("Content-Type", "application/json"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is response
possibly null
now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SetHeadersAndGetPayload
is also invoked by the existing method CreateCheckStatusResponse, which provides an HTTP response to SetHeadersAndGetPayload
. In the new API, CreateHttpManagementPayload
, there won’t be an HTTP response parameter. Therefore, when SetHeadersAndGetPayload
is called by CreateHttpManagementPayload
, the response will be null; however, if it’s called by CreateCheckStatusResponse
, the response will not be null.
src/Worker.Extensions.DurableTask/DurableTaskClientExtensions.cs
Outdated
Show resolved
Hide resolved
src/Worker.Extensions.DurableTask/DurableTaskClientExtensions.cs
Outdated
Show resolved
Hide resolved
AssertHttpManagementPayload(payload, "http://localhost:7075/runtime/webhooks/durabletask", instanceId); | ||
} | ||
|
||
private static void AssertHttpManagementPayload(dynamic payload, string BaseUrl, string instanceId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we replace dynamic
with HttpManagementPayload
here, and in the calling functions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just the one suggestion on the test code, but otherwise LGTM!
Issue describing the changes in this PR
Fix issue #2810
This PR adds the implementation of the CreateHttpManagementPayload API in the Durable Worker Extension. The implementation works as follows:
Pull request checklist
pending_docs.md
release_notes.md
/src/Worker.Extensions.DurableTask/AssemblyInfo.cs