gnodet commented on code in PR #1944: URL: https://github.com/apache/maven-mvnd/pull/1944#discussion_r4792851756
########## common/src/test/java/org/mvndaemon/mvnd/common/logging/TerminalInputHandlerTest.java: ########## @@ -0,0 +1,115 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.mvndaemon.mvnd.common.logging; + +import java.io.ByteArrayOutputStream; +import java.io.PipedInputStream; +import java.io.PipedOutputStream; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; + +import org.jline.terminal.Terminal; +import org.jline.terminal.TerminalBuilder; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mvndaemon.mvnd.common.Message; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class TerminalInputHandlerTest { + + private final BlockingQueue<Message> dispatched = new LinkedBlockingQueue<>(); + private final BlockingQueue<Message> received = new LinkedBlockingQueue<>(); + private final ByteArrayOutputStream screen = new ByteArrayOutputStream(); + private PipedOutputStream keys; + private Terminal terminal; + private TerminalInputHandler inputHandler; + + @BeforeEach + void setUp() throws Exception { + keys = new PipedOutputStream(); + terminal = TerminalBuilder.builder() + .system(false) + .type("xterm") + .streams(new PipedInputStream(keys), screen) + .build(); + terminal.enterRawMode(); + inputHandler = new TerminalInputHandler(terminal, false); + inputHandler.setDaemonDispatch(dispatched::add); + } + + @AfterEach + void tearDown() throws Exception { + inputHandler.close(); + terminal.close(); + } + + @Test + void ctrlCBeforeConnectingCancels() throws Exception { + type(TerminalOutput.KEY_CTRL_C); Review Comment: **Good test coverage** The test coverage looks excellent! Using a non-system terminal with pipes is the right approach for testing this functionality. **Minor suggestion:** The 5-second timeout for message polling might be unnecessarily long for most cases, though it provides good margin for slow CI environments. Consider: 1. Using a shorter timeout (e.g., 1 second) for faster test execution in the common case 2. Making the timeout configurable via a system property for CI environments if needed Example: ```java private static final long TIMEOUT_SECONDS = Long.getLong("mvnd.test.timeout.seconds", 1L); @Test void ctrlCBeforeConnectingCancels() throws Exception { type(TerminalOutput.KEY_CTRL_C); assertSame(Message.BareMessage.CANCEL_BUILD_SINGLETON, dispatched.poll(TIMEOUT_SECONDS, TimeUnit.SECONDS)); } ``` This is not a blocker - the current implementation is fine and conservative. _Claude Code on behalf of Guillaume Nodet_ -- 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]
