Ant 构建关闭 - Ctrl C

发布于 2024-10-05 15:17:07 字数 221 浏览 0 评论 0原文

我有一组 ant 任务,用于运行我的测试套件,偶尔其中一个测试会冻结,并且我的整个测试套件会挂起。我添加了一个关闭处理程序,因此当我点击 Ctrl+C 时,ant 会正常关闭并给我一份报告,其中最终测试标记为未运行。 (这很重要,因为这些是集成测试,可以运行几个小时)这非常有效,除了在 Windows 上,我的关闭钩子没有被调用。有没有办法让 ant 响应任何类型的输入并正常关闭?

I have a set of ant tasks that I use to run my test suite, occasionally one of those tests will freeze and my entire test suite will hang. I added a shutdown handler so when I hit Ctrl+C ant will shutdown gracefully and give me a report with the final test marked as not run. (This is important because these are integration tests and can run for hours) This works great except for on Windows where my shutdown hook is not being called. Is there a way I can get ant to respond to any kind of input and do a graceful shutdown?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

永言不败 2024-10-12 15:17:07

这似乎是一个长期运行的已知问题

问题在于,正如您所观察到的,在 Windows 上,Ant Ctrl+C 不会传播到子虚拟机。您可能会考虑的事项:

  • 将测试分解为更小的部分,并使用超时来终止任何挂起的内容。这将限制挂起的一个测试丢失的数据。
  • 在测试运行中,添加一个等待关闭“信号”(可能存在标志文件)的“侦听器”线程,并安排 Ant 在检测到挂起时根据控制台命令设置该信号。

这看起来很复杂,但可能值得一试。您需要将 Ant parallelinput 任务结合起来,在一个线程中运行测试,并在第二个线程中等待来自控制台的输入。当选择中止时,信号文件被写入,这在测试运行“监听器”中被检测到,导致它终止。任何其他输入都会导致运行干净终止。这样做的问题是,如果测试成功完成,Ant 就会等待用户输入,但您可以为此设置一个整体超时。 (我没有给出测试运行代码如何检测信号文件的示例。)

Psuedo-Ant:

<property name="signal.abort" value="stop.txt" />
<target name="runner">
    <delete file="${signal.abort}" />
    <parallel timeout="86400000">
        <sequential>

            <!-- run tests here -->

        </sequential>
        <sequential>
            <input validargs="y,n"
                   message="Abort the test (y/n)?"
                   addproperty="abort.test" />
            <condition property="do.abort">
                <equals arg1="y" arg2="${abort.test}"/>
            </condition>
            <ant target="terminator" />
        </sequential>
    </parallel>
</target>

<target name="terminator" if="do.abort">
    <echo message="abort" file="${signal.abort}" />
</target>

It seems this is a long-running known issue.

The problem is that on Windows the Ant Ctrl+C is, as you have observed, not propagated to the child VMs. Things you might consider:

  • Break up the test into smaller pieces and use a timeout to kill anything that hangs. This will limit the data lost to the one test that hangs.
  • In your test run, add a 'listener' thread that waits for a shutdown 'signal' (perhaps the presence of a flag file) and arrange for that signal to be set by Ant, on command from the console, if hang is detected.

This appears complex, but might be worth a shot. You'd need to combine the Ant parallel and input tasks to run the tests in one thread, and wait for input from the console in a second thread. When abort is chosen, the signal file is written, this is detected in the test run 'listener', causing it to terminate. Any other input would lead to clean termination of the run. The problem with this is that, if the test completes successfully, you're left with Ant waiting for user input, but you could put an overall timeout in place for that. (I've not given an example of how the test run code might detect the signal file.)

Psuedo-Ant:

<property name="signal.abort" value="stop.txt" />
<target name="runner">
    <delete file="${signal.abort}" />
    <parallel timeout="86400000">
        <sequential>

            <!-- run tests here -->

        </sequential>
        <sequential>
            <input validargs="y,n"
                   message="Abort the test (y/n)?"
                   addproperty="abort.test" />
            <condition property="do.abort">
                <equals arg1="y" arg2="${abort.test}"/>
            </condition>
            <ant target="terminator" />
        </sequential>
    </parallel>
</target>

<target name="terminator" if="do.abort">
    <echo message="abort" file="${signal.abort}" />
</target>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文