在docker中运行时,在SIGTERM之后做出jacoco报告

具有一个集成测试方案,在该方案上有一个HTTP服务器,我希望能够将SIGTERM发送到我的程序并获取jacoco报告。

考虑一个外部程序会碰到多个端点,到最后我将看到它实际触及了我的代码多少。

我具有以下pom.xml构建和属性,如果我只是mvn clean verify并正常完成(退出测试),它将很好地工作

  <properties>
        <integration.test.target>${project.build.directory}/coverage-reports/jacoco-it.exec</integration.test.target>

    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>8</source>
                    <target>8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.3</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>properties</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.15</version>
            </plugin>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.5</version>
                <executions>
                    <execution>
                        <id>report-aggregate</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>report-aggregate</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>default-prepare-agent</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                        <configuration>
                            <destFile>${integration.test.target}</destFile>
                        </configuration>
                    </execution>
                    <execution>
                        <goals>
                            <goal>report-integration</goal>
                        </goals>
                        <configuration>
                            <dataFile>${integration.test.target}</dataFile>
                            <outputDirectory>target/reports/jacoco-it</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

jacoco-maven-plugin处理代理程序的创建和报告生成,maven-failsafe-plugin通过其默认argline接收报告数据,并手动执行任何操作。

我的测试正在逐步展开,一个无限循环可以将标志设置为停止,标志设置为命中HTTP端点,但我希望它在SIGTERM上进行设置。

import org.junit.Test;

public class IntegrationTest {

    @Test()
    public void RunNormally() {
        String[] args = new String[0];
        Hello.main(args);
        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
            System.out.println("Killing it ");
            Hello.killed = true;
        }));
        while (!Hello.killed) {
            try {
                 Thread.sleep(500);

            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

在本地运行maven验证,并且执行不是SIGTERM的操作,将成功生成报告。 运行执行maven验证然后停止的docker不会生成也在本地运行的报告,并且将sigterm发送到maven不会生成报告。

我很确定我缺少实现此操作的细节,但是我不确定是什么。

谢谢。

编辑: 我的代码为is here

的仓库
xuelei4460 回答:在docker中运行时,在SIGTERM之后做出jacoco报告

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2913204.html

大家都在问