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

Handle primitive HTTP client responses with MessageBodyReader #10699

Merged
merged 4 commits into from
Apr 17, 2024

Conversation

kevin-wise
Copy link
Contributor

Fixes issue #10698

@CLAassistant
Copy link

CLAassistant commented Apr 9, 2024

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@sdelamo sdelamo left a comment

Choose a reason for hiding this comment

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

it misses a test

@sdelamo sdelamo requested a review from yawkat April 10, 2024 08:51
@sdelamo sdelamo changed the base branch from 4.4.x to 4.5.x April 10, 2024 08:52
@kevin-wise
Copy link
Contributor Author

@sdelamo I'm happy to add a test. Any guidance on the best place to put the test? Should I add a test to HttpGetSpec? Or maybe that's too high level

@kevin-wise
Copy link
Contributor Author

kevin-wise commented Apr 10, 2024

So as I was writing the tests, I was initially unable to reproduce the problem. It turns out it was being masked in the tests because NettyConverters has a TypeConverter from BytBuf to Object. So when http-server-netty is loaded, the tests pass without my modifications. The tests fail when http-server-netty is not loaded though.

I do think this should be fixed though, because that TypeConverter simply uses .toString() to convert, which is a bit naive even if it might be functional for boxed primitives. Also there is no guarantee that the Netty server lib will be loaded along with the HttpClient, so we shouldn't rely on that.

I was going to put the test right next to io.micronaut.http.body.ConversionTextPlainHandlerSpec, but that Gradle module includes project(":http-server-netty") as a dependency, so it always loads NettyConverters. Is there a pattern for this kind of test, which requires a specific set of dependencies? Is that what the test-suite-* modules are for?

@kevin-wise kevin-wise force-pushed the issue-10698-fix branch 2 times, most recently from 2bdbbba to fc48c46 Compare April 10, 2024 23:40
@kevin-wise
Copy link
Contributor Author

@sdelamo I pushed up some tests which fail on 4.3.x and pass on my branch. As I mentioned above, I had to block NettyConverters to get it to fail. Is there a better way to block NettyConverters?

I also noticed some tests which were leaking controllers into other tests, so I cleaned those up while I was at it.

@dstepanov The approach I took of creating a mock NettyConverters meant I had to make it non-final. I see you were the one that made it final. Are you ok with that change?

@kevin-wise kevin-wise force-pushed the issue-10698-fix branch 5 times, most recently from c487d0f to 038437a Compare April 11, 2024 00:09
@kevin-wise kevin-wise requested a review from sdelamo April 11, 2024 00:09
@kevin-wise kevin-wise changed the title Handle primitive HTTP client responses Handle primitive HTTP client responses with MessageBodyReader Apr 11, 2024
…loaded

Fixes issue micronaut-projects#10698
Also fixed some tests which had controllers leaking into other tests.
@kevin-wise
Copy link
Contributor Author

Also, any chance this can make it into 4.4?
When will the 4.4 platform bom get released?

@dstepanov
Copy link
Contributor

@kevin-wise Maybe you can just use @Replaces?

@kevin-wise
Copy link
Contributor Author

kevin-wise commented Apr 11, 2024

Looks like @Replaces along with GroovyMock worked with NettyConverter still final. Will post shortly.

Update: it seemed to have worked, but the input/output tests don't actually fail without the bug fix, so somehow the converters are still getting registered. I'll keep looking for some combination that works.

The error with @MockBean is

Cannot apply AOP advice to final class. Class must be made non-final to support proxying: io.micronaut.http.server.netty.converters.NettyConverters

@kevin-wise
Copy link
Contributor Author

kevin-wise commented Apr 11, 2024

Ok, found a combination that worked. The solution was to mock the interface instead of the class. The interface is what we care about anyway.

    @MockBean(bean = TypeConverterRegistrar, named = "NettyConverters")
    TypeConverterRegistrar nettyConverters() {
        Mock(TypeConverterRegistrar.class)
    }

Without fix:
image

With fix:
image

@kevin-wise
Copy link
Contributor Author

@sdelamo I noticed you changed the base branch to 4.5. Any chance this could make it in 4.4.x?

@yawkat
Copy link
Member

yawkat commented Apr 15, 2024

imo this is sufficiently bug-fixy to make it into a patch release of core

@yawkat
Copy link
Member

yawkat commented Apr 15, 2024

@sdelamo WDYT, 4.4.x?

@sdelamo sdelamo changed the base branch from 4.5.x to 4.4.x April 17, 2024 07:29
@sdelamo sdelamo changed the base branch from 4.4.x to 4.5.x April 17, 2024 07:30
@sdelamo
Copy link
Contributor

sdelamo commented Apr 17, 2024

I will cherry picked it and port it to 4.4.x

@sdelamo sdelamo merged commit 2642018 into micronaut-projects:4.5.x Apr 17, 2024
4 checks passed
sdelamo pushed a commit that referenced this pull request Apr 17, 2024
Fixes issue #10698
Also fixed some tests which had controllers leaking into other tests.
* Mock TypeConverterRegistrar so NettyConverters can stay final
@kevin-wise
Copy link
Contributor Author

Thanks!

@kevin-wise kevin-wise deleted the issue-10698-fix branch April 17, 2024 18:35
@yawkat
Copy link
Member

yawkat commented Apr 18, 2024

Thank you for the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

7 participants