gnodet-bot commented on code in PR #27494:
URL: https://github.com/apache/camel/pull/27494#discussion_r4210421311


##########
components/camel-ai/camel-semantic/src/test/java/org/apache/camel/semantic/SemanticInitializationTest.java:
##########
@@ -77,6 +76,39 @@ void concurrentQuestionRegistryCreationReturnsOneInstance() 
throws Exception {
         }
     }
 
+    @Test
+    void cachedRegistryLookupDoesNotWaitForAnotherContext() throws Exception {
+        ExecutorService callers = Executors.newFixedThreadPool(2);
+        CountDownLatch entered = new CountDownLatch(1);
+        CountDownLatch release = new CountDownLatch(1);
+        try (var creating = new DefaultCamelContext(); var cached = new 
DefaultCamelContext()) {
+            var expected = SemanticEvaluations.get(cached);
+            
creating.getCamelContextExtension().lazyAddContextPlugin(SemanticEvaluations.class,
 () -> {
+                entered.countDown();
+                try {
+                    assertThat(release.await(30, TimeUnit.SECONDS)).isTrue();
+                } catch (InterruptedException e) {
+                    Thread.currentThread().interrupt();
+                    throw new IllegalStateException(e);
+                }
+                // Leave the plugin absent so get() creates and registers it 
after this lookup is released.
+                return null;
+            });
+            var creation = callers.submit(() -> 
SemanticEvaluations.get(creating));
+            try {
+                assertThat(entered.await(10, TimeUnit.SECONDS)).isTrue();
+                var lookup = callers.submit(() -> 
SemanticEvaluations.get(cached));
+                assertThat(lookup.get(10, 
TimeUnit.SECONDS)).isSameAs(expected);
+            } finally {
+                release.countDown();
+                assertThat(creation.get(10, TimeUnit.SECONDS)).isNotNull();

Review Comment:
   💡 **Suggestion:** This assertion verifies a non-null result but gives no 
diagnostic context when it fails. Consider adding `.as()` to name the operation 
under test:
   
   ```suggestion
                   assertThat(creation.get(10, TimeUnit.SECONDS)).as("creation 
task must produce the SemanticEvaluations instance").isNotNull();
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to