apupier commented on code in PR #31326: URL: https://github.com/apache/camel/pull/31326#discussion_r4787993483
########## components/camel-robotframework/src/test/java/org/apache/camel/component/robotframework/RobotFrameworkInterruptedRunTest.java: ########## @@ -0,0 +1,71 @@ +/* + * 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.apache.camel.component.robotframework; + +import java.util.Arrays; +import java.util.concurrent.TimeUnit; + +import org.apache.camel.Exchange; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.test.junit6.CamelTestSupport; +import org.junit.jupiter.api.Test; + +import static org.awaitility.Awaitility.await; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + +/** + * A Robot Framework run that is interrupted must not break the later runs in the same JVM: the console stream of Robot + * Framework is shared by the JVM and, with the console enabled, it stays closed after the interrupt. + */ +class RobotFrameworkInterruptedRunTest extends CamelTestSupport { + + @Test + void testRunAfterInterruptedRunSucceeds() throws Exception { + template.send("direct:robot", e -> e.getIn().setBody("warmup")); + + // a thread that is interrupted while Robot Framework starts closes the console stream of Robot Framework + for (int i = 0; i < 5; i++) { + Thread interrupted = new Thread(() -> template.send("direct:robot", e -> e.getIn().setBody("interrupted"))); + interrupted.start(); + await().atMost(30, TimeUnit.SECONDS) + .until(() -> !interrupted.isAlive() || Arrays.stream(interrupted.getStackTrace()) + .anyMatch(frame -> frame.getClassName().startsWith("org.python."))); + interrupted.interrupt(); Review Comment: Good point, thanks. I ran the module with `-Dcamel.surefire.forkCount=8 -Dcamel.surefire.parallel=true -Dcamel.surefire.parallel.factor=4` several times. The new test was not the cause of the flakiness, but the module was flaky anyway: the forks shared `target/output.xml` (`ParseError: Premature end of file`, `rc=252`), also on the base code. I pushed a commit that gives each Robot test class its own output directory; after it 6 of 6 runs passed with no flakes. The new test already wrote to its own directory. It waits with Awaitility (30 s) until the thread is inside `org.python.*` or finished, then interrupts it. _Bob (IBM AI assistant) on behalf of @apupier_ -- 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]
