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

Support @TestProfile in native mode #12974 #13154

Merged
merged 1 commit into from
Dec 21, 2020
Merged

Conversation

ppalaga
Copy link
Contributor

@ppalaga ppalaga commented Nov 6, 2020

Fix #12974

Edit 2020-12-17:

This has two parts:

  1. ConfigChangeRecorder can now be configured to make the application fail at boot if the build time config changed. (Originally it only warned, which is still the default). The new mode is used by the NativeTestExtension to make sure that native tests are run with the same build time config as was used during the compilation.

  2. @TestProfile support in the NativeTestExtension.

This PR originally included building of multiple native images based on %profile.quarkus.package.output-name. That part was left out based on reviews.

Original description before 2020-12-17

This has several parts:

  1. ConfigChangeRecorder can now be configured to make the application fail at boot if the build time config changed. (Originally it only warned, which is still the default). The new mode is used by the NativeTestExtension to make sure that native tests are run against the right native image.

  2. BuildMojo builds a separate native image for each profile found in application.properties that has quarkus.package.output-name property set.

  3. NativeTestExtension can start the right one of the images built by BuildMojo, passing the configuration from TestProfile to it.

TODO:

  • The TestProfile support in native mode should be documented somewhere (where?)
  • Possible follow up: Figure out whether/how this should be supported in Gradle

@ppalaga
Copy link
Contributor Author

ppalaga commented Nov 6, 2020

cc @lburgazzoli

@ppalaga
Copy link
Contributor Author

ppalaga commented Nov 6, 2020

The CI failure unveils an issue that I need to fix.

@ppalaga
Copy link
Contributor Author

ppalaga commented Nov 6, 2020

Good to review now

@ppalaga
Copy link
Contributor Author

ppalaga commented Nov 9, 2020

Any chance to get a review @geoand or somebody else?

@geoand
Copy link
Contributor

geoand commented Nov 10, 2020

Although I understand this took a fair amount of work (very good work BTW) and I do remember that Camel had a use case where you wanted to be able to build the run the native tests for all profiles, I can't say I'm thrilled about this...
It just feels so unnatural.

I'd like to hear what @stuartwdouglas and @gsmet have to say as well.

@ppalaga
Copy link
Contributor Author

ppalaga commented Nov 12, 2020

I admit this not a feature for common application developers. It is rather something for extension developers like us in Camel Quarkus, where we would like to test various sets of configurations also in native mode.

I guess we are not the only ones in the whole ecosystem who might need this, so Quarkus seems to be most natural place for this feature.

In theory 1. and 2. are easy to workaround on our side, but 3. would mean a lot of duplication.

But maybe the whole approach is wrong and somebody sees some other simple and effective solution?

@geoand
Copy link
Contributor

geoand commented Nov 12, 2020

I don't know... I'm not -1, but I'm definitely not +1 either. In your shoes I would probably just use different Maven profiles and / or failsafe configurations.

Let's see what others think as well.

@geoand
Copy link
Contributor

geoand commented Nov 19, 2020

Pinging @gsmet and @stuartwdouglas again :)

@maxandersen
Copy link
Member

Do I get it right that this basically just enable using @testprofile for the same native images with varied configurations and if a configuration changes build time properties it fails ?

That seems like a good natural first step and matches what is done for java mode does it not ? What is the objection to do that ?

@geoand
Copy link
Contributor

geoand commented Nov 19, 2020

The issue I have is that the PR also looks at the configuration profiles.

It feels very heavy handed

@ppalaga
Copy link
Contributor Author

ppalaga commented Nov 19, 2020

Do I get it right that this basically just enable using @testprofile for the same native images with varied configurations

Yes

and if a configuration changes build time properties it fails ?

Not exactly. This proposal also allows for testing multiple sets of build time configs. This is possible thanks to the change in the native image builder that is now able to build a native image for each application.properties profile that has quarkus.package.output-name property set. The junit extension boots the one of the multiple images that matches the test profile. The boot failure is there only to prevent misconfigurations (such as missing quarkus.package.output-name) in the tests.

@ppalaga
Copy link
Contributor Author

ppalaga commented Nov 24, 2020

Could you guys be more specific about what this PR needs to become mergeable? I am happy to discuss possible changes in this PR, but I'd actually need to know what you want/not want. @lburgazzoli has thoroughly explained the objective in the mailing list, so the background and motivation for this PR should be clear enough.

In his last message Luca even said, he is fine to limit the scope to runtime options only and have some sort of warning/failure if you attempt to change build time only options.

This would mean that the new ability of the native image builder to build multiple executables with distinct build time configs is not necessary. I can remove that part, but I'd like to hear some authoritative voice saying that you want me to do that (plus any other changes you wish).

@geoand
Copy link
Contributor

geoand commented Nov 24, 2020

I need to take another look.
I'll do that tomorrow and let you know.

@geoand
Copy link
Contributor

geoand commented Nov 25, 2020

After looking at this again, I think my main objection is that the PR is coupling config profiles with test profiles.
I understand why this has been done (and I indeed don't see another way you could know which native images to build), but these are two different things and this change just doesn't make intuitive sense to me - and I assume it will be very hard to make users understand it as well.

I won't block this (as I understand it fills a need for Camel), but I just can't get behind it either. I would for sure like to hear what others think as well.

@ppalaga
Copy link
Contributor Author

ppalaga commented Nov 25, 2020

Thanks for the statement @geoand. Let me try to remove the multi-native-image capability from the image builder and from the test extension - that's basically what Luca proposed on the ML. I guess it could eliminate your objection wholly or partly.

@geoand
Copy link
Contributor

geoand commented Nov 25, 2020

That does sounds much better to me :)

@ghost ghost added area/config area/core area/infra-automation anything related to CI, bots, etc. that are used to automated our infrastructure area/testing labels Nov 25, 2020
@ppalaga
Copy link
Contributor Author

ppalaga commented Nov 25, 2020

Let me try to remove the multi-native-image capability from the image builder and from the test extension

Done in 9aa9f86. Please re-review.

Questions/tasks still open:

  • The TestProfile support in native mode should be documented somewhere (where?)
  • Possible follow up: Figure out whether/how this should be supported in Gradle - I cannot do this, I'd just file a new issue.

@maxandersen
Copy link
Member

We should always try and keep maven and gradle experience equal capable wherever possible.

@ppalaga
Copy link
Contributor Author

ppalaga commented Nov 25, 2020

Actually, I think after the last iteration nothing needs to be done for Gradle because all changes are done in non-Maven code that should be the same for Gradle.

additional.putAll(profileInstance.getConfigOverrides());
final Set<Class<?>> enabledAlternatives = profileInstance.getEnabledAlternatives();
if (!enabledAlternatives.isEmpty()) {
additional.put("quarkus.arc.selected-alternatives", enabledAlternatives.stream()
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this can be supported as it is a build time property only

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, but I think the current solution is not that bad: If enabledAlternatives is a non-empty set containing anything different than what the test app was compiled with, the test app will fail at boot. I think that's better than ignoring silently or warning. The user should do a conscious decision what to do in such a case. If he wants to test with the alternatives in JVM mode and ignore them in the native mode, he can create subclass of his QuarkusTestProfile for the native mode in which he returns an empty set of alternatives.

Do you think warn+ignore would be better?

Copy link
Contributor

Choose a reason for hiding this comment

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

You are probably right, Let's keep it for now and see.

@geoand
Copy link
Contributor

geoand commented Nov 26, 2020

I added a small comment. Other than that, I'm fine with this

@ppalaga
Copy link
Contributor Author

ppalaga commented Nov 27, 2020

Is there still anything missing here @geoand ?

@geoand
Copy link
Contributor

geoand commented Nov 27, 2020

Is there still anything missing here @geoand ?

Other people's feedback :)

@ppalaga
Copy link
Contributor Author

ppalaga commented Nov 27, 2020

Could you please be more specific, so that we move forward?

@geoand
Copy link
Contributor

geoand commented Nov 27, 2020

Like I said above, I want @stuartwdouglas and or @gsmet to OK this as well

@ppalaga
Copy link
Contributor Author

ppalaga commented Dec 2, 2020

@stuartwdouglas or @gsmet would you be so kind and review this so that we can move forward?

@geoand
Copy link
Contributor

geoand commented Dec 18, 2020

@ppalaga can you please rebase onto master?

I want to make sure nothing broke in the meantime (although it's very unlikely)

@ppalaga
Copy link
Contributor Author

ppalaga commented Dec 18, 2020

2478d22: rebased. Thanks!

@geoand geoand merged commit 3818ee1 into quarkusio:master Dec 21, 2020
@ghost ghost added this to the 1.11 - master milestone Dec 21, 2020
Sgitario added a commit to Sgitario/quarkus that referenced this pull request Jun 22, 2021
## Description
In quarkusio#13154, the annotation `@TestProfile` was supported also in Native tests. However, the native extension was not processing the test resources in the test profile like:

```
public class ConfluentTestProfile implements QuarkusTestProfile {

    @OverRide
    public String getConfigProfile() {
        return "confluent";
    }

    @OverRide
    public List<TestResourceEntry> testResources() {
        return Collections.singletonList(new TestResourceEntry(ConfluentKafkaResource.class));
    }
}
```

This PR makes the above to be supported.
The solution behaves the same as done in the Quarkus Test extension.
Sgitario added a commit to Sgitario/quarkus that referenced this pull request Jun 22, 2021
## Description
In quarkusio#13154, the annotation `@TestProfile` was supported also in Native tests. However, the native extension was not processing the test resources in the test profile like:

```
public class ConfluentTestProfile implements QuarkusTestProfile {

    @OverRide
    public String getConfigProfile() {
        return "confluent";
    }

    @OverRide
    public List<TestResourceEntry> testResources() {
        return Collections.singletonList(new TestResourceEntry(ConfluentKafkaResource.class));
    }
}
```

This PR makes the above to be supported.
The solution behaves the same as done in the Quarkus Test extension.
Sgitario added a commit to Sgitario/quarkus that referenced this pull request Jun 22, 2021
## Description
In quarkusio#13154, the annotation `@TestProfile` was supported also in Native tests. However, the native extension was not processing the test resources in the test profile like:

```
public class ConfluentTestProfile implements QuarkusTestProfile {

    @OverRide
    public String getConfigProfile() {
        return "confluent";
    }

    @OverRide
    public List<TestResourceEntry> testResources() {
        return Collections.singletonList(new TestResourceEntry(ConfluentKafkaResource.class));
    }
}
```

This PR makes the above to be supported.
The solution behaves the same as done in the Quarkus Test extension.
Sgitario added a commit to Sgitario/beefy-scenarios that referenced this pull request Jun 23, 2021
From quarkusio/quarkus#13154, the `@TestProfile` annotation supports Native tests, therefore the modules 001, 301 and 303 can be extended for Native test coverage.
As part of this work, we have supported also the test resources for Native: quarkusio/quarkus#18077

And also, I've removed the workaround for quarkusio/quarkus#16810 that had been fixed a while ago.

Moreover, for 301:
- We've fixed the native failures and got rid of the application.properties file in the test resources. This can be closed now: quarkusio/quarkus#17829.
- Reduce the number of traces to ease the troubleshot of failures.

And for 303:
- Refactored the test resources to not rely on system properties to load/unload application properties.
patrox pushed a commit to patrox/quarkus that referenced this pull request Jun 23, 2021
## Description
In quarkusio#13154, the annotation `@TestProfile` was supported also in Native tests. However, the native extension was not processing the test resources in the test profile like:

```
public class ConfluentTestProfile implements QuarkusTestProfile {

    @OverRide
    public String getConfigProfile() {
        return "confluent";
    }

    @OverRide
    public List<TestResourceEntry> testResources() {
        return Collections.singletonList(new TestResourceEntry(ConfluentKafkaResource.class));
    }
}
```

This PR makes the above to be supported.
The solution behaves the same as done in the Quarkus Test extension.
pjgg pushed a commit to quarkus-qe/beefy-scenarios that referenced this pull request Jul 14, 2021
From quarkusio/quarkus#13154, the `@TestProfile` annotation supports Native tests, therefore the modules 001, 301 and 303 can be extended for Native test coverage.
As part of this work, we have supported also the test resources for Native: quarkusio/quarkus#18077

And also, I've removed the workaround for quarkusio/quarkus#16810 that had been fixed a while ago.

Moreover, for 301:
- We've fixed the native failures and got rid of the application.properties file in the test resources. This can be closed now: quarkusio/quarkus#17829.
- Reduce the number of traces to ease the troubleshot of failures.

And for 303:
- Refactored the test resources to not rely on system properties to load/unload application properties.
luca-digrazia pushed a commit to luca-digrazia/DatasetCommitsDiffSearch that referenced this pull request Sep 4, 2022
    ## Description
    In quarkusio/quarkus#13154, the annotation `@TestProfile` was supported also in Native tests. However, the native extension was not processing the test resources in the test profile like:

    ```
    public class ConfluentTestProfile implements QuarkusTestProfile {

        @OverRide
        public String getConfigProfile() {
            return "confluent";
        }

        @OverRide
        public List<TestResourceEntry> testResources() {
            return Collections.singletonList(new TestResourceEntry(ConfluentKafkaResource.class));
        }
    }
    ```

    This PR makes the above to be supported.
    The solution behaves the same as done in the Quarkus Test extension.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/config area/core area/infra-automation anything related to CI, bots, etc. that are used to automated our infrastructure area/testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support @TestProfile in native mode
4 participants