You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by GitBox <gi...@apache.org> on 2021/07/09 13:03:40 UTC

[GitHub] [dolphinscheduler] shink opened a new issue #5781: [Bug][UT] Some test coverages are always 0% in sonar

shink opened a new issue #5781:
URL: https://github.com/apache/dolphinscheduler/issues/5781


   ## Describe the bug
   
   As we all know, dolphinscheduler uses `PowerMock` for unit testing, and uses `Jacoco` to get code coverage which will be stored and managed by `Sonar`.  But in fact, some test conerages are always 0% in sonar. This seems to be caused by Jacoco not getting the coverage of the class marked by `@PrepareForTest`.
   
   ## To Reproduce
   
   When using the `@PrepareForTest` annotation only causes code coverage to fail in some cases. If you want to write test for `Demo.java`, and you add the `Demo.class` in `@PrepareForTest`, then the `Jacoco` will not count the coverage in `Demo.java`.
   
   ```java
   public class Demo {
   
       public int method() {
           // do something
           return -1;
       }
   
   }
   ```
   
   ```java
   @RunWith(PowerMockRunner.class)
   @PrepareForTest({Demo.class})
   public class DemoTest {
   
       @Mock
       private Demo demo;
   
       @Test
       public void testMethod() {
           when(demo.method()).thenReturn(1);
           Assert.assertEquals(1, demo.method());
       }
   
   }
   ```
   
   If you add other class in `@PrepareForTest`, it will not affect the code coverage in Demo.
   
   ## Cause analysis
   
   > The simplest way to use JaCoCo it is — on-the-fly instrumentation with using JaCoCo Java Agent. In this case a class in modified when it is being loaded. You can just run you application with JaCoCo agent and a code coverage is calculated. This way is used by Eclemma and Intellij Idea. But there is a big issue. PowerMock instruments classes also. Javassist is used to modify classes. The main issue is that Javassist reads classes from disk and all JaCoCo changes are disappeared. As result zero code coverage for classes witch are loaded by PowerMock class loader. ——[Code coverage with JaCoCo](https://github.com/powermock/powermock/wiki/Code-coverage-with-JaCoCo)
   
   JaCoCo tracks execution with so called probes. Probes are additional byte code instructions inserted in the original class file which will note when they are executed and report this to the JaCoCo runtime. This process is called instrumentation. In short, Jacoco will modify the class when it is loaded. 
   
   Jacoco use class ids to unambiguously identify Java classes. At runtime execution data is sampled for every loaded class and typically stored to *.exec files. At analysis time — for example for report generation — the class ids are used to relate analyzed classes with the execution data.
   
   Meanwhile, when performing unit tests, PowerMock will modify the byte code of the tested class according to your mock requirements, which causes the class ids to change. There are different classes are used at runtime and at analysis time, so the data cannot be related to the analyzed classes. As a consequence such classes are reported with 0% coverage.
   
   ## Solution
   
   I think we can make Jacoco running in [offline instrumentation](https://www.eclemma.org/jacoco/trunk/doc/offline.html) to get code converage. This way classes get instrumented by JaCoCo before any runtime modification can take place.
   
   ## Which version of Dolphin Scheduler
   
    - 1.3.6
   


-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [dolphinscheduler] CalvinKirs closed issue #5781: [CI][UT] Some test coverages are always 0% in sonar

Posted by GitBox <gi...@apache.org>.
CalvinKirs closed issue #5781:
URL: https://github.com/apache/dolphinscheduler/issues/5781


   


-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [dolphinscheduler] CalvinKirs commented on issue #5781: [CI][UT] Some test coverages are always 0% in sonar

Posted by GitBox <gi...@apache.org>.
CalvinKirs commented on issue #5781:
URL: https://github.com/apache/dolphinscheduler/issues/5781#issuecomment-915913186


   close by #5837


-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [dolphinscheduler] github-actions[bot] removed a comment on issue #5781: [Bug][UT] Some test coverages are always 0% in sonar

Posted by GitBox <gi...@apache.org>.
github-actions[bot] removed a comment on issue #5781:
URL: https://github.com/apache/dolphinscheduler/issues/5781#issuecomment-877171353


   Hi:
   * Thank you for your feedback, we have received your issue, Please wait patiently for a reply.
   * In order for us to understand your request as soon as possible, please provide detailed information、version or pictures.
   * If you haven't received a reply for a long time, you can subscribe to the developer's email,Mail subscription steps reference https://dolphinscheduler.apache.org/zh-cn/community/development/subscribe.html ,Then write the issue URL in the email content and send question to dev@dolphinscheduler.apache.org.


-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [dolphinscheduler] CalvinKirs commented on issue #5781: [CI][UT] Some test coverages are always 0% in sonar

Posted by GitBox <gi...@apache.org>.
CalvinKirs commented on issue #5781:
URL: https://github.com/apache/dolphinscheduler/issues/5781#issuecomment-877350432


   This problem has always existed, and related emails have also been discussed. The inability of Sonar to monitor the CI coverage rate blocked our CI process. Do you intend to accomplish this?
   Here is some information that may be helpful to you:
   https://github.com/powermock/powermock/wiki/Code-coverage-with-JaCoCo


-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [dolphinscheduler] github-actions[bot] commented on issue #5781: [Bug][UT] Some test coverages are always 0% in sonar

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on issue #5781:
URL: https://github.com/apache/dolphinscheduler/issues/5781#issuecomment-877171353


   Hi:
   * Thank you for your feedback, we have received your issue, Please wait patiently for a reply.
   * In order for us to understand your request as soon as possible, please provide detailed information、version or pictures.
   * If you haven't received a reply for a long time, you can subscribe to the developer's email,Mail subscription steps reference https://dolphinscheduler.apache.org/zh-cn/community/development/subscribe.html ,Then write the issue URL in the email content and send question to dev@dolphinscheduler.apache.org.


-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [dolphinscheduler] shink commented on issue #5781: [CI][UT] Some test coverages are always 0% in sonar

Posted by GitBox <gi...@apache.org>.
shink commented on issue #5781:
URL: https://github.com/apache/dolphinscheduler/issues/5781#issuecomment-877661873


   @CalvinKirs Yes, I am willing to fix it.
   
   Further, how is this problem represented in the Jacoco report?
   
   > The typical symptom of class id mismatch is classes not shown as covered although they have been executed during the test. This situation can be easily detected e.g. in the HTML report: Open the Sessions page with the link on the top-right corner. You see a list of all classes where execution data has been collected for. Find the class in questions and check whether the entry has a link to the corresponding coverage report page. If the entry is not linked this means there is a class id mismatch between the class used at runtime and the class provided to create the report. —— [How can I detect that I have a problem with class ids?](https://www.eclemma.org/jacoco/trunk/doc/classids.html)
   
   ![4](https://user-images.githubusercontent.com/49934421/125169241-db674e00-e1db-11eb-89c4-e7820dead48d.png)
   
   As you can see from the figure below, The `Demo` class is not linked to the corresponding coverage report page. It means there is a class id mismatch between the class used at runtime and the class provided to create the report.
   
   In addition, you can see the name of the `Demo` class has changed. This is due to PowerMock modifying the Demo class at runtime and Jacoco testing it but has been modified.
   


-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org