This is an automated email from the ASF dual-hosted git repository.

apupier pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 6e5987949794   CAMEL-24647: Fix flaky JBang IT tests caused by missing 
cleanup between tests
6e5987949794 is described below

commit 6e59879497945faa4432ae497144da55038725b0
Author: Torsten Mielke <[email protected]>
AuthorDate: Tue Sep 8 16:01:30 2026 +0200

      CAMEL-24647: Fix flaky JBang IT tests caused by missing cleanup between 
tests
    
      The JBang IT tests share a singleton container, but afterEach() never
      stopped background integrations or cleaned up test files. This caused
      two independent failures:
    
      1. BindException (Address already in use): background routes from one
         test were still bound to port 8080 when the next test tried to start.
         Fixed by calling "camel stop" and waiting (via Awaitility) until
         "camel ps" reports no running processes before proceeding.
    
      2. Wrong OpenAPI spec loaded (HTTP 404): tests that call downloadFile()
         or generateProperties() leave files in /home/jbang/ which persist
         across tests. A stale application.properties with camel.jbang.open-api
         pointing to petstore-v3.json caused a subsequent test to load the
         wrong spec. Fixed by removing all non-hidden files from /home/jbang/
         after each test. The JBang installation baseline is entirely hidden
         files (.jbang/, .bashrc, .camel-jbang/), so this is safe.
    
      Also wraps assertNoErrors() in try/finally so cleanup always runs even
      when log assertions fail.
    
    Co-Authored-By: Claude Opus 4.6 <[email protected]>
---
 .../dsl/jbang/it/support/JBangTestSupport.java     | 31 +++++++++++++++++++---
 1 file changed, 27 insertions(+), 4 deletions(-)

diff --git 
a/dsl/camel-jbang/camel-jbang-it/src/test/java/org/apache/camel/dsl/jbang/it/support/JBangTestSupport.java
 
b/dsl/camel-jbang/camel-jbang-it/src/test/java/org/apache/camel/dsl/jbang/it/support/JBangTestSupport.java
index 7e8052a11996..7b174e6a335e 100644
--- 
a/dsl/camel-jbang/camel-jbang-it/src/test/java/org/apache/camel/dsl/jbang/it/support/JBangTestSupport.java
+++ 
b/dsl/camel-jbang/camel-jbang-it/src/test/java/org/apache/camel/dsl/jbang/it/support/JBangTestSupport.java
@@ -87,10 +87,33 @@ public abstract class JBangTestSupport {
     @AfterEach
     protected void afterEach(TestInfo testInfo) {
         logger.debug("ending {}#{} using data folder {}", 
getClass().getName(), testInfo.getDisplayName(), getDataFolder());
-        assertNoErrors();
-        logger.debug("clean up data folder");
-        if (containerDataFolder != null) {
-            FileUtil.removeDir(new File(containerDataFolder));
+        try {
+            assertNoErrors();
+        } finally {
+            try {
+                execute("stop");
+            } catch (Exception | AssertionError e) {
+                logger.debug("failed to stop running integrations: {}", 
e.getMessage());
+            }
+            try {
+                Awaitility.await()
+                        .atMost(30, TimeUnit.SECONDS)
+                        .pollInterval(500, TimeUnit.MILLISECONDS)
+                        .until(() -> execute("ps").trim().isEmpty());
+            } catch (Exception | AssertionError e) {
+                logger.warn("integrations did not stop within timeout: {}", 
e.getMessage());
+            }
+            // Remove non-hidden files/dirs from /home/jbang to prevent 
cross-test contamination.
+            // The JBang installation baseline is entirely hidden (.jbang/, 
.bashrc, .camel-jbang/).
+            try {
+                execInContainer("find /home/jbang -maxdepth 1 -mindepth 1 -not 
-name '.*' -exec rm -rf {} +");
+            } catch (Exception e) {
+                logger.debug("failed to clean up test files from /home/jbang: 
{}", e.getMessage());
+            }
+            logger.debug("clean up data folder");
+            if (containerDataFolder != null) {
+                FileUtil.removeDir(new File(containerDataFolder));
+            }
         }
     }
 

Reply via email to