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

Small refactoring on dapr client and invocation handler. Add improvements on test structure. #1379

Closed

Conversation

RafaelJCamara
Copy link
Contributor

Description

  • Small refactor to improve code readability (both on dapr client and the invocation handler)
  • Improve test structure by removing the test definition from the test class itself to a test data class, therefore doing a small separation of concerns between test data definition and test data usage.

Issue reference

No issues to be referenced.

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

  • Code compiles correctly
  • Created/updated tests
  • Extended the documentation

…ents on test structure.

Signed-off-by: Rafael Camara <rafaelcamarac@gmail.com>
@RafaelJCamara RafaelJCamara requested review from a team as code owners October 24, 2024 17:08
Signed-off-by: Rafael Camara <rafaelcamarac@gmail.com>
Copy link
Contributor

@WhitWaldo WhitWaldo left a comment

Choose a reason for hiding this comment

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

Thank you for your pull request. I appreciate the effort you’ve put into it. However, I noticed several changes that seem unnecessary, particularly the renaming of arguments without a clear reason. As mentioned in my comments, we prefer to avoid such changes unless they are essential, as our XML documentation already provides clarity.

If a new feature requires renaming for better functionality or readability, that’s understandable. However, changes should not be made solely for the sake of change. Please revert these specific changes, and in future pull requests, ensure that any renaming is justified by a significant need.

@@ -79,47 +83,10 @@ public void TryRewriteUri_FailsForRelativeUris()
}

[Theory]
[InlineData(null, "http://bank", "https://some.host:3499/v1.0/invoke/bank/method/")]
Copy link
Contributor

Choose a reason for hiding this comment

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

I disagree with removing all these tests - again, they're each verifying a unique and separate variation of the inputs that is worth knowing is covered.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not removing them, I just placed them in the class data TryRewriteUriWithNoAppIdRewritesUriToDaprInvokeTestData and all of them are being called here.

The reason why I've done this was to make this testing class a bit more cleaner.

If you don't agree with moving the test data to that class, I can revert this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Which I've now seen you want to revert back to the attributes.

@@ -0,0 +1,56 @@
using Xunit;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please put these back with the inline data attributes. When building unit tests, I don't expect to have to look in a separate file to add additional variations, I expect to see them inline using the convenience attributes provided by the framework. This might make sense in an actual library, but not in a unit test class.

@@ -98,63 +96,68 @@ internal string? DaprApiToken
/// <inheritdoc />
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
var original = request.RequestUri;
if (!this.TryRewriteUri(request.RequestUri, out var rewritten))
var originalUri = request.RequestUri;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm disinclined to accept this change which only changes the inline variable. If you're rewriting the method to do something and you need to change the variable so it's more meaningful, by all means, but to change it for the sake of changing it isn't necessary.

request.Headers.Remove("dapr-api-token");
}
}

// Internal for testing
internal bool TryRewriteUri(Uri? uri, [NotNullWhen(true)] out Uri? rewritten)
internal bool TryRewriteUri(Uri? uri, [NotNullWhen(true)] out Uri? rewrittenUri)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same thing - I'm disinclined to accept this change that renames the argument just because you can. Again, if you're changing the method itself and need to change the name so it's useful in your rewrite, that's one thing, but changing it just for the sake of doing so here, especially for something that's strictly internal for testing purposes, doesn't make sense.

@@ -29,11 +29,7 @@ public void CreateInvokeHttpClient_WithAppId()
[Fact]
public void CreateInvokeHttpClient_InvalidAppId()
{
var ex = Assert.Throws<ArgumentException>(() =>
{
// The appId needs to be something that can be used as hostname in a URI.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's useful to retain this comment in the test as it provides more context to the test name and what it's covering

@RafaelJCamara
Copy link
Contributor Author

@WhitWaldo I was looking at the codebase to understand how somethings worked and I thought it was a good idea to suggest some improvements.

I see that most of my suggested changes are proposed for revert. Do you think it still makes sense to have the rest of the changes up or shall we have put this PR to sleep?

@WhitWaldo
Copy link
Contributor

@WhitWaldo I was looking at the codebase to understand how somethings worked and I thought it was a good idea to suggest some improvements.

I see that most of my suggested changes are proposed for revert. Do you think it still makes sense to have the rest of the changes up or shall we have put this PR to sleep?

Thank you for your follow-up. I appreciate your understanding regarding the previous points. Several of the remaining changes in this PR appear to be formatting-based (e.g., tab inserts) or minor syntax updates (like converting a get body to a lambda expression). Generally, I would prefer not to accept these types of changes unless they are part of a larger feature addition.

I do see value in the following change in this PR:

var ex = Assert.Throws<ArgumentException>(() => 
{ 
    _ = DaprClient.CreateInvokeHttpClient(daprEndpoint: "ftp://localhost:3500");
});

to

var ex = Assert.Throws<ArgumentException>(() => DaprClient.CreateInvokeHttpClient(daprEndpoint: "ftp://localhost:3500"));

...and the others like it. If you could revert the other changes and keep this one, I'd be happy to accept this PR.

For future reference however, I'd prefer that PRs include more substantial feature additions or changes rather than consisting solely of small formatting and refactoring changes.

@RafaelJCamara
Copy link
Contributor Author

I'll close this one and perhaps open another one with such improvements.

Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants