-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Make sure (basic) logging is set up before each test class #22920
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
3 changes: 2 additions & 1 deletion
3
test-framework/junit5-properties/src/main/resources/junit-platform.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
junit.jupiter.testclass.order.default=io.quarkus.test.junit.util.QuarkusTestProfileAwareClassOrderer | ||
junit.jupiter.extensions.autodetection.enabled=true | ||
junit.jupiter.testclass.order.default=io.quarkus.test.junit.util.QuarkusTestProfileAwareClassOrderer |
54 changes: 54 additions & 0 deletions
54
test-framework/junit5/src/main/java/io/quarkus/test/junit/BasicLoggingEnabler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package io.quarkus.test.junit; | ||
|
||
import org.eclipse.microprofile.config.ConfigProvider; | ||
import org.eclipse.microprofile.config.spi.ConfigProviderResolver; | ||
import org.junit.jupiter.api.extension.BeforeAllCallback; | ||
import org.junit.jupiter.api.extension.ExtensionContext; | ||
|
||
import io.quarkus.bootstrap.logging.InitialConfigurator; | ||
|
||
/** | ||
* A (global) JUnit callback that enables/sets up basic logging if logging has not already been set up. | ||
* <p/> | ||
* This is useful for getting log output from non-Quarkus tests (if executed separately or before the first Quarkus test), | ||
* but also for getting instant log output from {@code QuarkusTestResourceLifecycleManagers} etc. | ||
* <p/> | ||
* This callback can be disabled via {@link #CFGKEY_ENABLED} in {@code junit-platform.properties} or via system property. | ||
*/ | ||
public class BasicLoggingEnabler implements BeforeAllCallback { | ||
|
||
private static final String CFGKEY_ENABLED = "junit.quarkus.enable-basic-logging"; | ||
private static Boolean enabled; | ||
|
||
// to speed things up a little, eager async loading of the config that will be looked up in LoggingSetupRecorder | ||
// downside: doesn't obey CFGKEY_ENABLED, but that should be bearable | ||
static { | ||
// e.g. continuous testing has everything set up already (DELAYED_HANDLER is active) | ||
if (!InitialConfigurator.DELAYED_HANDLER.isActivated()) { | ||
new Thread(() -> ConfigProvider.getConfig()).start(); | ||
} | ||
} | ||
|
||
@Override | ||
public void beforeAll(ExtensionContext context) throws Exception { | ||
if (enabled == null) { | ||
enabled = context.getConfigurationParameter(CFGKEY_ENABLED).map(Boolean::valueOf).orElse(Boolean.TRUE); | ||
} | ||
if (!enabled || InitialConfigurator.DELAYED_HANDLER.isActivated()) { | ||
return; | ||
} | ||
try { | ||
IntegrationTestUtil.activateLogging(); | ||
} finally { | ||
// release the config that was retrieved by above call so that tests that try to register their own config | ||
// don't fail with: | ||
// "IllegalStateException: SRCFG00017: Configuration already registered for the given class loader" | ||
// also, a possible recreation of basically the same config for a later test class will consume far less time | ||
var configProviderResolver = ConfigProviderResolver.instance(); | ||
var config = configProviderResolver.getConfig(); | ||
if (config != null) { // probably never null, but be safe | ||
configProviderResolver.releaseConfig(config); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...ork/junit5/src/main/resources/META-INF/services/org.junit.jupiter.api.extension.Extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
io.quarkus.test.junit.BasicLoggingEnabler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Not pretty, but saves up to ~50ms total runtime in my not-so-small project.