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 a55701fdecae chore: camel-jbang-plugin-tui - fix flaky
MonitorStartupTest and AiCliCommandExecutorTest (#28993)
a55701fdecae is described below
commit a55701fdecae17c6a0de6665391486f87396ca3e
Author: Claus Ibsen <[email protected]>
AuthorDate: Tue Nov 3 08:56:14 2026 +0100
chore: camel-jbang-plugin-tui - fix flaky MonitorStartupTest and
AiCliCommandExecutorTest (#28993)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Claus Ibsen <[email protected]>
---
.../jbang/core/commands/tui/AiCliCommandExecutorTest.java | 4 ++++
.../camel/dsl/jbang/core/commands/tui/BorderRenderTest.java | 3 +++
.../dsl/jbang/core/commands/tui/MonitorStartupTest.java | 12 +++++++-----
.../dsl/jbang/core/commands/tui/ShellPanelLifecycleTest.java | 8 ++++++++
4 files changed, 22 insertions(+), 5 deletions(-)
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/AiCliCommandExecutorTest.java
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/AiCliCommandExecutorTest.java
index c3d95eaee815..0337768e5394 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/AiCliCommandExecutorTest.java
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/AiCliCommandExecutorTest.java
@@ -28,6 +28,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import org.apache.camel.dsl.jbang.core.commands.CamelJBangMain;
import org.apache.camel.dsl.jbang.run.common.Printer;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.parallel.ResourceLock;
import picocli.CommandLine;
import picocli.CommandLine.Command;
@@ -135,6 +136,9 @@ class AiCliCommandExecutorTest {
}
@Test
+ // points the static command line of the Camel CLI at its own main: a
shell panel that another test class starts
+ // meanwhile (the classes run in parallel) would take the printer of this
main
+ @ResourceLock(ShellPanelLifecycleTest.CLI_COMMAND_LINE)
void productionInvokerRestoresPrinterAndDoesNotQuitMain() throws Exception
{
// a command runs on new instances of the commands, so the test
command is added the way plugins add theirs
CamelJBangMain main = new CamelJBangMain() {
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/BorderRenderTest.java
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/BorderRenderTest.java
index c38bd0573d5d..67a3fec2ca54 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/BorderRenderTest.java
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/BorderRenderTest.java
@@ -25,6 +25,7 @@ import dev.tamboui.terminal.Frame;
import dev.tamboui.widgets.block.BorderType;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.parallel.ResourceLock;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -288,6 +289,8 @@ class BorderRenderTest {
// ---- ShellPanel border test ----
@Test
+ // the shell takes the printer of the static command line of the Camel CLI
+ @ResourceLock(ShellPanelLifecycleTest.CLI_COMMAND_LINE)
void shellPanelRendersWithBorder() {
ShellPanel panel = new ShellPanel();
panel.setContext(ctx);
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/MonitorStartupTest.java
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/MonitorStartupTest.java
index 0afa662b10ed..2a0dd3b3e58e 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/MonitorStartupTest.java
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/MonitorStartupTest.java
@@ -83,13 +83,15 @@ class MonitorStartupTest {
});
serving.start();
- await().atMost(10, TimeUnit.SECONDS).untilAsserted(() -> {
- try (Socket socket = new Socket()) {
- socket.connect(new InetSocketAddress("127.0.0.1", port),
500);
- }
- });
+ // the line is printed once the server is bound: a connect before
that is refused, and Awaitility does
+ // not retry on the ConnectException, so wait for the line and
connect once
+ await().atMost(10, TimeUnit.SECONDS).until(() ->
!printer.lines.isEmpty() || !serving.isAlive());
+ assertThat(failure.get()).isNull();
assertThat(printer.lines).containsExactly(
"Camel TUI in the browser at http://127.0.0.1:" + port +
"/ (Ctrl+C to stop)");
+ try (Socket socket = new Socket()) {
+ socket.connect(new InetSocketAddress("127.0.0.1", port), 5000);
+ }
assertThat(serving.isAlive()).as("waits while the server
runs").isTrue();
server.stop();
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/ShellPanelLifecycleTest.java
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/ShellPanelLifecycleTest.java
index 9b537e45836c..b5e3865bb0d4 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/ShellPanelLifecycleTest.java
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/ShellPanelLifecycleTest.java
@@ -27,6 +27,7 @@ import org.apache.camel.dsl.jbang.run.common.Printer;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.parallel.ResourceLock;
import picocli.CommandLine;
import static org.awaitility.Awaitility.await;
@@ -40,8 +41,15 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
* panel, and other code (AiCliCommandExecutorTest) points the static command
line at another main in the meantime,
* whose printer was taken and never given back, which made that test flaky.
*/
+@ResourceLock(ShellPanelLifecycleTest.CLI_COMMAND_LINE)
class ShellPanelLifecycleTest {
+ /**
+ * The lock of the tests that point the static command line of the Camel
CLI at a main of their own, or start a
+ * shell that takes it: the test classes run in parallel.
+ */
+ static final String CLI_COMMAND_LINE = "CamelJBangMain.commandLine";
+
private Field commandLineField;
private Object previous;