@@ -92,10 +92,15 @@ static QuarkusTestProfile getQuarkusTestProfile(Class<? extends QuarkusTestProfi
92
92
return profile == null ? null : new ClassCoercingTestProfile (profile .getConstructor ().newInstance ());
93
93
}
94
94
95
- static Runnable setExtraProperties (Class <?> profileClass , QuarkusTestProfile profileInstance ) {
95
+ /**
96
+ * Reads properties from a profile, sets them as system properties, and returns a Runnable which can be invoked to remove
97
+ * them back off of
98
+ * system properties.
99
+ */
100
+ static Runnable setExtraPropertiesRestorably (Class <?> profileClass , QuarkusTestProfile profileInstance ) {
96
101
final Map <String , String > additional = new HashMap <>();
97
- // TODO we make this twice, also in abstractjvmextension can we streamline that?
98
- // TODO We can't get rid of the one here because config needs to be set before augmentation, but maybe we can get rid of it on the test side?
102
+ // We apply the profile config twice, once before augmentation, and once before app start
103
+ // That's a bit awkward, but both augmentation and app start need to have the right config for their profile
99
104
additional .putAll (profileInstance .getConfigOverrides ());
100
105
if (!profileInstance .getEnabledAlternatives ().isEmpty ()) {
101
106
additional .put ("quarkus.arc.selected-alternatives" , profileInstance .getEnabledAlternatives ()
@@ -124,7 +129,9 @@ static Runnable setExtraProperties(Class<?> profileClass, QuarkusTestProfile pro
124
129
//we just use system properties for now
125
130
//it's a lot simpler
126
131
// TODO this is really ugly, set proper config on the app
127
- // Sadly, I don't think #42715 helps, because it kicks in after this code
132
+ // TODO investigate whether we can use the config from https://github.com/quarkusio/quarkus/pull/42715 to avoid system properties
133
+ // ... but be aware that this is called twice, and on the first pass through, the classloader might be an all-purpose runtime classloader, and would not be the actual test classloader
134
+ // Setting config on the wrong classloader is worse than useless, so we'd need solid test coverage
128
135
return RestorableSystemProperties .setProperties (additional )::close ;
129
136
}
130
137
@@ -233,29 +240,25 @@ public static CuratedApplication makeCuratedApplication(Class<?> requiredTestCla
233
240
// should have been freshly created
234
241
// TODO maybe don't even accept one? is that comment right?
235
242
public static StartupAction getStartupAction (Class <?> testClass , CuratedApplication curatedApplication , Class profile )
236
- throws AppModelResolverException , BootstrapException , IOException ,
237
- InvocationTargetException , NoSuchMethodException , InstantiationException , IllegalAccessException {
243
+ throws InvocationTargetException , NoSuchMethodException , InstantiationException , IllegalAccessException {
238
244
239
- PrepareResult prepareResult = prepare (testClass ,
240
- curatedApplication ,
241
- profile );
245
+ PrepareResult prepareResult = prepare (testClass , curatedApplication , profile );
242
246
247
+ // Before doing the augmentation, apply any extra config from the profile
243
248
final Runnable configCleanup = prepareResult .profileInstance () == null ? null
244
- : setExtraProperties (profile , prepareResult .profileInstance ());
249
+ : setExtraPropertiesRestorably (profile , prepareResult .profileInstance ());
245
250
246
251
try {
247
-
248
252
// To check changes here run integration-tests/elytron-resteasy-reactive and SharedProfileTestCase in integration-tests/main
249
-
250
253
return prepareResult .augmentAction ().createInitialRuntimeApplication ();
251
- } catch (Throwable e ) {
254
+ } catch (Exception e ) {
252
255
// Errors at this point just get reported as org.junit.platform.commons.JUnitException: TestEngine with ID 'junit-jupiter' failed to discover tests
253
- // Give a little help to debuggers
254
- // TODO how best to handle?
256
+ // Even though a stack trace isn't ideal handling, we want to make sure people have something to try and debug if problems happen
255
257
e .printStackTrace ();
256
258
throw e ;
257
259
258
260
} finally {
261
+ // We may by doing augmentations for other profiles now, so unset the config
259
262
if (configCleanup != null ) {
260
263
configCleanup .run ();
261
264
}
0 commit comments