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

Honor the environment variable for verifying the host at which the server is listening #8240

Merged
merged 1 commit into from
Mar 30, 2020

Conversation

roguexz
Copy link
Contributor

@roguexz roguexz commented Mar 28, 2020

Sometimes, when running on a VPN, 0.0.0.0 is inaccessible and it forces me to set the QUARKUS_HTTP_HOST environment variable to localhost. There is one test case that does not honor the explicit environment variable setting. This PR fixes that problem.

I don't know if there is a better way of doing it, but I'm open to suggestions.

@gastaldi
Copy link
Contributor

You can inject the config property in the test instead:

    @ConfigProperty(name="quarkus.http.host", defaultValue="0.0.0.0")
    String host;

Copy link
Contributor

@gastaldi gastaldi left a comment

Choose a reason for hiding this comment

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

LGTM

@gastaldi gastaldi added this to the 1.4.0 milestone Mar 29, 2020
@gastaldi gastaldi added the triage/waiting-for-ci Ready to merge when CI successfully finishes label Mar 29, 2020
Copy link
Contributor

@gastaldi gastaldi left a comment

Choose a reason for hiding this comment

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

Hum, sorry, looks like it doesn't work with native 😞

[ERROR] Failures: 
[ERROR]   JaxRSITCase>JaxRSTestCase.testConfigInjectionOfPort:40 1 expectation failed.
Response body doesn't match expectation.
Expected: is null
  Actual: 0.0.0.0

@gastaldi gastaldi removed the triage/waiting-for-ci Ready to merge when CI successfully finishes label Mar 29, 2020
@gastaldi
Copy link
Contributor

What happens if you change to Instance<String> host and call host.get() in the test instead of String host?

@machi1990
Copy link
Member

Injection is not yet supported in Native tests - https://quarkus.io/guides/getting-started-testing#native-executable-testing

@roguexz
Copy link
Contributor Author

roguexz commented Mar 29, 2020

so, would you recommend that I move it back to checking for environment variables? That is what I started with originally.

@gastaldi
Copy link
Contributor

@roguexz yeah maybe that would be the best in this case, WDYT @dmlloyd ?

@roguexz
Copy link
Contributor Author

roguexz commented Mar 29, 2020

For a reference, my original commit had the following change,

RestAssured.when().get("/test/config/host").then()
            .body(is(System.getenv().getOrDefault("QUARKUS_HTTP_HOST", "0.0.0.0")));

If you are ok with it, I can update the commit.

@gastaldi
Copy link
Contributor

Isn't easier to just check if the body response is not empty or null?

@roguexz
Copy link
Contributor Author

roguexz commented Mar 29, 2020

@gastaldi The original test was checking for 0.0.0.0. As part of debugging another issue, I noticed this scenario.

@gastaldi
Copy link
Contributor

I know, I mean that the possible values for this test are localhost or 0.0.0.0, so I wonder if isn't easier to just check if the result matches one of those values

@gastaldi
Copy link
Contributor

Just another shot: try getting the quarkus.http.host from ConfigProvider.getConfig().

@gastaldi
Copy link
Contributor

The reason is that we should avoid reading from System.getenv() or System.getProperties() and use MP Config where possible

@roguexz
Copy link
Contributor Author

roguexz commented Mar 29, 2020

Agreed. Wouldn't the suggested fix do the same, giving the additional possibility of honoring a system environment value? I am good either ways. What would you recommend?

@gastaldi
Copy link
Contributor

I'm fine with either TBH ;)

@roguexz
Copy link
Contributor Author

roguexz commented Mar 29, 2020

@gastaldi Done. I have switched to using MP config instead.

Copy link
Contributor

@geoand geoand left a comment

Choose a reason for hiding this comment

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

Thanks for this!

@geoand geoand requested a review from gastaldi March 30, 2020 08:45
@gastaldi gastaldi merged commit 1562e07 into quarkusio:master Mar 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants