Feature branch and Develop branch reporting different code coverage numbers

Versions Used:
Sonarqube: 8.9.1.44547
SonarScanner: 4.6.2.2472
Error observed:
Develop and feature branch reporting different code coverage. Upon looking at scans, develop appears to be reporting lines of cold that have not been modified as new code that does not have code coverage. This causes the feature branch to pass sonarqube gates, but upon merging to develop, develop will treat unmodified code lines as new code and fail the build due to insufficient coverage. In all cases, scans were run with the feature branches that were caught up with develop. Issue has been observed when scanning NPM code.
Steps to reproduce: This has been occurring intermittently and we have not isolated the cause.

Hi,

Welcome to the community!

When you say the lines havenā€™t been modifiedā€¦ do they show up in SonarQube with a yellow highlight? If you click the left margin to get ā€˜blameā€™ information, do you see a date thatā€™s old or within the New Code Period?

Off-hand my guess would be that a ā€œhelpfulā€ process is modifying whitespace and so invisibly ā€œchangingā€ the lines.

Ā 
Ann

Hi Ann,

The housekeeping feature purged the log from the most recent time this happened, but for the last time this happened that I observed:

The code shows up with a yellow highlight with a blame information that is outside the New Code Period. This happened with an older version of Sonarqube, but appears to be happening after updating to the latest 8.9 version as well.

Thanks

Hi,

The next time this happens, it will be interesting to know:

  • Is there a yellow (new code) highlight on the line?
  • When you click in the margin next to the line to see the blame data, what is the date on the line?
  • When does your project homepage say the New Code Period started?

Ā 
Ann

Hi,

Sorry, it took awhile before this popped up again!

  1. The scan on the feature branch showed that there were no new lines of code and marked the branch as passing
  2. On merging the code into develop, the new lines of code are now recognized by sonarqube as lines that need coverage. The lines are then marked as having insufficient coverage and our develop build fails.
  3. The code is a typescript package scanned using sonarscanner version 4.6.2.2472 and sent to a sonarqube instance running Version 9.0.1 (build 46107)

Hi,

I donā€™t supposed you still have access to screenshotting this?

 
Ann

Iā€™m not sure I can get screenshots of this easily without security approval, but this issue did pop up again and I noticed something interesting: the ā€œnew code periodā€ between develop and the PR branch did not match up. Develop (the baseline branch) stated the new code coverage period started on June 22, but the PR thought that the new code period started on August 19 (the day the branch was created and scanned). From my understanding, the new code period should be compared against baseline, should it not? Is there a setting that needs to be set that is missing?

Hi,

It sounds like itā€™s working as expected. From the docs:

Reference Branch ā€“ Choose a specific branch to define your New Code. Any changes made from your reference branch are considered New Code.

So itā€™s not about matching the reference branchā€™s dates, but about comparing the code against that branch. And in your case, the New Code Period canā€™t start on 22 June since the PR/branch didnā€™t exist then.

 
Ann

From those docs:
" * Previous Version ā€“ Define New Code as any changes made in your projectā€™s current version. This works well for projects with regular versions or releases.Available at the global, project, and branch level."
Is that the configuration I would need to use in my use case instead?
Thanks

Hi,

Iā€™ll be honest and say that without screenshots to orient myself, Iā€™m having a little bit of trouble keeping up.

The Previous Version setting is best used within a main or release branch where the version number increments on a (semi)regular basis. In that case, youā€™re looking at everything that changed since the last release as ā€˜New Codeā€™.

For feature branches (and Iā€™m not sure at this point whether you were talking earlier about feature branches earlier or not) itā€™s probably best to use a reference branch. And unless your feature branch starts at the same time your reference branch does, youā€™re still going to see that date mismatch you observed in your 24 Aug post. And thatā€™s perfectly normal and to be expected.

Does that help?

Ā 
Ann

Hi,

Yes, that does help. We currently use a mainline branch that increments a version when feature branches are merged in. It sounds like previous version is closer to what we need, settings wise. Iā€™ll test with the settings and documentation you provided.

Thanks

1 Like