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

davsclaus 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 cc39bab365ad chore: Fix flaky ThemeTest and OverviewTabRenderTest in 
camel-tui
cc39bab365ad is described below

commit cc39bab365ad7dbca98546db6ada72071bc12d79
Author: Claus Ibsen <[email protected]>
AuthorDate: Sun Jul 5 09:15:44 2026 +0200

    chore: Fix flaky ThemeTest and OverviewTabRenderTest in camel-tui
    
    Add testMode flag to Theme that skips property file I/O (load/save)
    so tests run purely in memory. Keep the StyleEngine alive across
    test resets instead of destroying and recreating it, which caused
    intermittent failures when tests ran together in the same JVM.
    
    Co-Authored-By: Claude Opus 4.6 <[email protected]>
    Signed-off-by: Claus Ibsen <[email protected]>
---
 .../camel/dsl/jbang/core/commands/tui/Theme.java   | 23 ++++++++++++++++------
 .../core/commands/tui/OverviewTabRenderTest.java   |  6 ++++++
 .../dsl/jbang/core/commands/tui/ThemeTest.java     | 23 ++++------------------
 3 files changed, 27 insertions(+), 25 deletions(-)

diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/Theme.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/Theme.java
index 4391433df555..70862c6e6dd4 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/Theme.java
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/Theme.java
@@ -74,6 +74,7 @@ final class Theme {
 
     private static boolean initialized;
     private static boolean fallbackLogged;
+    private static boolean testMode;
     private static StyleEngine engine;
     private static String mode = DARK;
 
@@ -191,7 +192,9 @@ final class Theme {
     static synchronized String toggle() {
         String next = DARK.equals(mode) ? LIGHT : DARK;
         setMode(next);
-        persist(next);
+        if (!testMode) {
+            persist(next);
+        }
         return next;
     }
 
@@ -210,13 +213,19 @@ final class Theme {
         CACHE.clear();
     }
 
-    /** Test hook: drop all process-wide state so the next access 
reinitializes from config. */
+    /** Test hook: enable in-memory-only mode so tests never touch user config 
files. */
     static synchronized void resetForTesting() {
-        initialized = false;
+        testMode = true;
         fallbackLogged = false;
-        engine = null;
-        mode = DARK;
         CACHE.clear();
+        if (engine != null) {
+            try {
+                engine.setActiveStylesheet(DARK);
+            } catch (RuntimeException ex) {
+                // ignore
+            }
+        }
+        mode = DARK;
     }
 
     private static synchronized Style style(String id, Style fallback) {
@@ -239,7 +248,9 @@ final class Theme {
             return engine;
         }
         initialized = true;
-        mode = loadPersistedMode();
+        if (!testMode) {
+            mode = loadPersistedMode();
+        }
         try {
             StyleEngine e = StyleEngine.create();
             e.loadStylesheet(DARK, "tui/themes/dark.tcss");
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/OverviewTabRenderTest.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/OverviewTabRenderTest.java
index ad175a724a4c..36e671461b9e 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/OverviewTabRenderTest.java
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/OverviewTabRenderTest.java
@@ -30,6 +30,7 @@ import dev.tamboui.tui.event.KeyEvent;
 import dev.tamboui.tui.event.KeyModifiers;
 import dev.tamboui.tui.event.MouseButton;
 import dev.tamboui.tui.event.MouseEvent;
+import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
@@ -60,6 +61,11 @@ class OverviewTabRenderTest {
         ctx.selectedPid = "1234";
     }
 
+    @AfterEach
+    void tearDown() {
+        Theme.resetForTesting();
+    }
+
     @Test
     void renderShowsTableHeaders() {
         info.state = 5;
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/ThemeTest.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/ThemeTest.java
index b9be5c9240b9..35e92fec9122 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/ThemeTest.java
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/ThemeTest.java
@@ -16,15 +16,11 @@
  */
 package org.apache.camel.dsl.jbang.core.commands.tui;
 
-import java.nio.file.Path;
-
 import dev.tamboui.style.Color;
 import dev.tamboui.style.Style;
-import org.apache.camel.dsl.jbang.core.common.CommandLineHelper;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.io.TempDir;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotEquals;
@@ -32,19 +28,13 @@ import static 
org.junit.jupiter.api.Assertions.assertNotNull;
 
 class ThemeTest {
 
-    @TempDir
-    Path home;
-
     @BeforeEach
     void setUp() {
-        // Isolate user config per test so persistence never touches the real 
home dir.
-        CommandLineHelper.useHomeDir(home.toString());
         Theme.resetForTesting();
     }
 
     @AfterEach
     void tearDown() {
-        // Reset the process-wide engine so toggles do not leak across tests.
         Theme.resetForTesting();
     }
 
@@ -108,17 +98,12 @@ class ThemeTest {
     }
 
     @Test
-    void togglePersistsAndAFreshLoadActivatesIt() {
+    void toggleFlipsModeBackAndForth() {
         Theme.setMode("dark");
-        Theme.toggle(); // -> light, persisted to camel.tui.theme
-
-        String[] stored = { null };
-        CommandLineHelper.loadProperties(p -> stored[0] = 
p.getProperty("camel.tui.theme"));
-        assertEquals("light", stored[0]);
-
-        // A fresh Theme load (statics reset) must read back the persisted 
mode.
-        Theme.resetForTesting();
+        assertEquals("light", Theme.toggle());
         assertEquals("light", Theme.mode());
+        assertEquals("dark", Theme.toggle());
+        assertEquals("dark", Theme.mode());
     }
 
     @Test

Reply via email to