the coverage rate in jacoco report page doesnt match the green colored lines count in source file page.

32 views
Skip to first unread message

Lipeng Guo

unread,
Sep 1, 2024, 11:49:32 PM9/1/24
to JaCoCo and EclEmma Users
hi,
i add jacoco to a scala project(apache spark), and run `mvn verify`,then jacoco successfully generate execution data file and report.
but the coverage rate in jacoco report page doesnt match the green colored lines count in source file page.
for example, after test, the method `org$apache$spark$HeartbeatReceiver$$expireDeadHosts()` has many missed instruction which is highligted red in source file page, but jacoco report page show that the method coverage rate is 100%.
i assumed that the highlight color in source file is depend on jacoco.exec.(is it right?)
i test jacoco for the scala's `for loop` syntax in a helloworld scala project and it works fine.

i search thorough the jacoco faq but doesnt solve it, could you please help me find whats wrong?

problem reproduce:
($ java -version
java version "1.8.0_261"
Java(TM) SE Runtime Environment (build 1.8.0_261-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.261-b12, mixed mode)
)
git clone g...@github.com:apache/spark.git
cd spark
git checkout v3.5.0
git apply testjacoco.patch
./build/mvn -Dtest=none -DwildcardSuites="org.apache.spark.HeartbeatReceiverSuite" -pl org.apache.spark:spark-core_2.12 clean verify


report.png
sourcefile.png

Lipeng Guo

unread,
Sep 2, 2024, 1:05:17 AM9/2/24
to JaCoCo and EclEmma Users
testjacoco.patch uploads as an attachment.



diff --git a/core/src/test/scala/org/apache/spark/HeartbeatReceiverSuite.scala b/core/src/test/scala/org/apache/spark/HeartbeatReceiverSuite.scala
index ee0a577..c74eccd 100644
--- a/core/src/test/scala/org/apache/spark/HeartbeatReceiverSuite.scala
+++ b/core/src/test/scala/org/apache/spark/HeartbeatReceiverSuite.scala
@@ -112,7 +112,7 @@ class HeartbeatReceiverSuite
assert(trackedExecutors.contains(executorId1))
assert(trackedExecutors.contains(executorId2))
}
-
+/***
test("reregister if scheduler is not ready yet") {
addExecutorAndVerify(executorId1)
// Task scheduler is not set yet in HeartbeatReceiver, so executors should reregister
@@ -236,7 +236,7 @@ class HeartbeatReceiverSuite
sc.stopped.set(false)
}
}
-
+*/
/** Manually send a heartbeat and return the response. */
private def triggerHeartbeat(
executorId: String,
diff --git a/pom.xml b/pom.xml
index 93d696d..ffe3b37 100644
--- a/pom.xml
+++ b/pom.xml
@@ -2918,7 +2918,7 @@
<arg>-feature</arg>
<arg>-explaintypes</arg>
<arg>-target:jvm-1.8</arg>
- <arg>-Xfatal-warnings</arg>
+ <!-- <arg>-Xfatal-warnings</arg> -->
<arg>-Ywarn-unused:imports</arg>
<arg>-P:silencer:globalFilters=.*deprecated.*</arg>
</args>
@@ -2975,7 +2975,7 @@
<include>**/*Suite.java</include>
</includes>
<reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
- <argLine>-ea -Xmx4g -Xss4m -XX:MaxMetaspaceSize=2g -XX:ReservedCodeCacheSize=${CodeCacheSize} ${extraJavaTestArgs} -Dio.netty.tryReflectionSetAccessible=true</argLine>
+ <argLine>${argLine} -ea -Xmx4g -Xss4m -XX:MaxMetaspaceSize=2g -XX:ReservedCodeCacheSize=${CodeCacheSize} ${extraJavaTestArgs} -Dio.netty.tryReflectionSetAccessible=true</argLine>
<environmentVariables>
<!--
Setting SPARK_DIST_CLASSPATH is a simple way to make sure any child processes
@@ -3029,7 +3029,7 @@
<reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
<junitxml>.</junitxml>
<filereports>SparkTestSuite.txt</filereports>
- <argLine>-ea -Xmx4g -Xss4m -XX:MaxMetaspaceSize=2g -XX:ReservedCodeCacheSize=${CodeCacheSize} ${extraJavaTestArgs} -Dio.netty.tryReflectionSetAccessible=true</argLine>
+ <argLine>${argLine} -ea -Xmx4g -Xss4m -XX:MaxMetaspaceSize=2g -XX:ReservedCodeCacheSize=${CodeCacheSize} ${extraJavaTestArgs} -Dio.netty.tryReflectionSetAccessible=true</argLine>
<stderr/>
<environmentVariables>
<!--
@@ -3480,6 +3480,25 @@
</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ <version>0.8.12</version>
+ <executions>
+ <execution>
+ <id>default-prepare-agent</id>
+ <goals>
+ <goal>prepare-agent</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>default-report</id>
+ <goals>
+ <goal>report</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
diff --git a/sql/core/pom.xml b/sql/core/pom.xml
index 7313ee5..8340308 100644
--- a/sql/core/pom.xml
+++ b/sql/core/pom.xml
@@ -248,7 +248,7 @@
<groupId>org.scalatest</groupId>
<artifactId>scalatest-maven-plugin</artifactId>
<configuration>
- <argLine>-ea -Xmx4g -Xss4m -XX:ReservedCodeCacheSize=${CodeCacheSize} ${extraJavaTestArgs} -Dio.netty.tryReflectionSetAccessible=true</argLine>
+ <argLine>${argLine} -ea -Xmx4g -Xss4m -XX:ReservedCodeCacheSize=${CodeCacheSize} ${extraJavaTestArgs} -Dio.netty.tryReflectionSetAccessible=true</argLine>
</configuration>
</plugin>
<plugin>


testjacoco.patch

Lipeng Guo

unread,
Sep 2, 2024, 4:40:49 AM9/2/24
to JaCoCo and EclEmma Users
another example is after test, the method `compressSize(long)` hits all instruction which is highligted green in source file page, but jacoco report page show that the method coverage rate is 0%.
reproduce:
./build/mvn -Dtest=none  -pl org.apache.spark:spark-core_2.12 clean verify

report1.png
source1.png

Reply all
Reply to author
Forward
0 new messages