Skip to content

[FIX] Fix negative duration values in CI test average time calculation#1094

Open
pulk17 wants to merge 1 commit intoCCExtractor:masterfrom
pulk17:fix/negative-duration
Open

[FIX] Fix negative duration values in CI test average time calculation#1094
pulk17 wants to merge 1 commit intoCCExtractor:masterfrom
pulk17:fix/negative-duration

Conversation

@pulk17
Copy link
Copy Markdown

@pulk17 pulk17 commented Apr 7, 2026

Please prefix your pull request with one of the following: [FEATURE] [FIX] [IMPROVEMENT].

In raising this pull request, I confirm the following (please check boxes):

  • I have read and understood the contributors guide.
  • I have checked that another pull request for this purpose does not exist.
  • I have considered, and confirmed that this submission will be valuable to others.
  • I accept that this submission may not be used, and the pull request closed at the will of the maintainer.
  • I give this submission freely, and claim no ownership to its content.

My familiarity with the project is as follows (check one):

  • I have never used the project.
  • I have used the project briefly.
  • I have used the project extensively, but have not contributed previously.
  • I am an active contributor to the project.

Problem
The platform was producing negative duration values for CI test runs, which corrupted the stored average time and caused negative estimated times to be displayed to users.
This stemmed from three separate bugs in update_final_status():

  • Fragile timestamp parsing via group_concat — timestamps were concatenated into a string, split on ,, and manually parsed with a try/except for microsecond format. Since group_concat doesn't guarantee ordering, start/end could be swapped, producing a negative duration.
  • Wrong test count formula — the incremental average used all_results / regression_test_count as a proxy for the number of finished tests per platform. This is completely unrelated to actual test history and produced a wrong weight in the running average.
  • No negative guard on the final stored value — even if the computed duration was negative, it was written directly to the DB and later surfaced as a negative avg_minutes in the UI.

Fix

  • Replaced group_concat + manual string parsing with func.min(timestamp) / func.max(timestamp) directly in SQL — unambiguous, ordering-independent, and format-independent.
  • Replaced the broken test count with a proper COUNT(DISTINCT test_id) query filtered to completed/canceled progress entries for the current platform.
  • Used the correct incremental mean formula: (old_avg × (n−1) + new_duration) / n.
  • Added max(0, ...) guards on duration, last_duration, updated_average, and avg_minutes to prevent any negative value from propagating through to the DB or UI.

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 7, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant