@@ -153,14 +153,40 @@ public void testMatchingAppNamesDropinsTest() throws Exception {
153153 log ("testMatchingAppNamesDropinsTest" , "Deploying the ConfigAdmin App into the dropins directory." );
154154 loadServerAndApplication (server1 , APP_NAME , "io.openliberty.microprofile.health31.config.admin.dropins.checks.app" , false );
155155
156- //Hitting health endpoint to trigger configAdmin app registration.
156+ // Wait for the health bundle's setConfigAdmin() to be invoked
157+ // This ensures ConfigAdmin binding has occurred before we check for app detection
158+ log ("testMatchingAppNamesDropinsTest" , "Waiting for ConfigAdmin binding to health bundle." );
159+ String setConfigAdminLine = server1 .waitForStringInTrace ("invoking bind: setConfigAdmin" , 10000 );
160+ assertNotNull ("ConfigAdmin was not bound to health bundle." , setConfigAdminLine );
161+
162+ log ("testMatchingAppNamesDropinsTest" , "ConfigAdmin binding detected, now checking app detection." );
163+
164+ // Now hit the health endpoint to trigger the check
157165 HttpURLConnection conReady = HttpUtils .getHttpConnectionWithAnyResponseCode (server1 , READY_ENDPOINT );
158166 getJSONPayload (conReady );
159167
160- String configAdminLine = server1 .waitForStringInTrace (" configAdminAppName = ConfigAdminDropinsCheckApp" , 10000 );
161- String stateMapLine = server1 .waitForStringInTrace (": appName = ConfigAdminDropinsCheckApp" );
168+ // Check if the app was detected by ConfigAdmin
169+ String configAdminLine = server1 .waitForStringInTrace (" configAdminAppName = ConfigAdminDropinsCheckApp" , 5000 );
170+
171+ // If not found, it might be the race condition - check for the "could not find" message
172+ if (configAdminLine == null ) {
173+ String notFoundLine = server1 .waitForStringInTrace ("configAdmin could not find any configured apps" , 1000 );
174+ if (notFoundLine != null ) {
175+ // Race condition detected - ConfigAdmin was queried before app registered
176+ // Hit the endpoint again to trigger a re-check
177+ log ("testMatchingAppNamesDropinsTest" , "Race condition detected, retrying health endpoint." );
178+ conReady = HttpUtils .getHttpConnectionWithAnyResponseCode (server1 , READY_ENDPOINT );
179+ getJSONPayload (conReady );
180+
181+ // Wait for the app detection after retry
182+ configAdminLine = server1 .waitForStringInTrace (" configAdminAppName = ConfigAdminDropinsCheckApp" , 5000 );
183+ }
184+ }
162185
163186 assertNotNull ("App was not detected by ConfigAdmin." , configAdminLine );
187+
188+ // Check appTracker detection
189+ String stateMapLine = server1 .waitForStringInTrace (": appName = ConfigAdminDropinsCheckApp" );
164190 assertNotNull ("App was not detected by appTracker." , stateMapLine );
165191
166192 }
@@ -299,16 +325,40 @@ public void testMultiWarDetectionDropinsTest() throws Exception {
299325 assertTrue ("Failure to start server. " , server1 .isStarted ());
300326 }
301327
302- log ("testReadinessEndpointOnServerStart " , "Waiting for Application to start." );
328+ log ("testMultiWarDetectionDropinsTest " , "Waiting for Application to start." );
303329 String line = server1 .waitForStringInLog ("Application MultiWarApps started" , 30000 );
304- log ("testReadinessEndpointOnServerStart " , "Application started. Line Found : " + line );
330+ log ("testMultiWarDetectionDropinsTest " , "Application started. Line Found : " + line );
305331 assertNotNull ("The CWWKZ0001I Application started message did not appear in messages.log" , line );
306332
307- //Hitting health endpoint to trigger configAdmin app registration.
333+ // Wait for the health bundle's setConfigAdmin() to be invoked
334+ // This ensures ConfigAdmin binding has occurred before we check for app detection
335+ log ("testMultiWarDetectionDropinsTest" , "Waiting for ConfigAdmin binding to health bundle." );
336+ String setConfigAdminLine = server1 .waitForStringInTrace ("invoking bind: setConfigAdmin" , 10000 );
337+ assertNotNull ("ConfigAdmin was not bound to health bundle." , setConfigAdminLine );
338+
339+ log ("testMultiWarDetectionDropinsTest" , "ConfigAdmin binding detected, now checking app detection." );
340+
341+ // Now hit the health endpoint to trigger the check
308342 HttpURLConnection conReady = HttpUtils .getHttpConnectionWithAnyResponseCode (server1 , READY_ENDPOINT );
309343 getJSONPayload (conReady );
310344
311- String configAdminLine = server1 .waitForStringInTrace ("configAdminAppName = MultiWarApps" );
345+ // Check if the app was detected by ConfigAdmin
346+ String configAdminLine = server1 .waitForStringInTrace ("configAdminAppName = MultiWarApps" , 5000 );
347+
348+ // If not found, it might be the race condition - check for the "could not find" message
349+ if (configAdminLine == null ) {
350+ String notFoundLine = server1 .waitForStringInTrace ("configAdmin could not find any configured apps" , 1000 );
351+ if (notFoundLine != null ) {
352+ // Race condition detected - ConfigAdmin was queried before app registered
353+ // Hit the endpoint again to trigger a re-check
354+ log ("testMultiWarDetectionDropinsTest" , "Race condition detected, retrying health endpoint." );
355+ conReady = HttpUtils .getHttpConnectionWithAnyResponseCode (server1 , READY_ENDPOINT );
356+ getJSONPayload (conReady );
357+
358+ // Wait for the app detection after retry
359+ configAdminLine = server1 .waitForStringInTrace ("configAdminAppName = MultiWarApps" , 5000 );
360+ }
361+ }
312362
313363 assertNotNull ("App was not detected by ConfigAdmin." , configAdminLine );
314364
0 commit comments