fix: O3-5485 Fix NaN return from computeAverageWaitTimeInMinutes when no entries have endedAt#99
Open
Conversation
|
I have Tested this locally and this looks correct. It fixes the NaN case by returning 0.0 when no matching entries have endedAt, and the added tests cover the expected edge cases. small note : a shorter branch name can make manual fetch/checkouts a bit easier. |
Author
Thanks for testing and the feedback! Good tip on the branch name - I'll keep it shorter next time around. 👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
QueueUtils.computeAverageWaitTimeInMinutes()returnsDouble.NaNwhen all queue entriesin the list have a null
endedAtdate. This causes the/ws/rest/v1/queue-entry-metricand/ws/rest/v1/queue-metricsREST endpoints to returnNaNin JSON responses - which isinvalid per RFC 7159 and breaks frontend metric display.
Root Cause
The method computes
totalWaitTime / numEntrieswithout guarding againstnumEntries == 0.When every entry is skipped (because
endedAtis null), this evaluates to0.0 / 0whichper JLS §15.17.2 produces
Double.NaN— no exception is thrown.Fix
Added a
numEntries > 0guard before the division. When no entries have bothstartedAtand
endedAtpopulated, the method now returns0.0instead ofNaN.Tests Added
computeAverageWaitTime_shouldReturnZeroForNullListcomputeAverageWaitTime_shouldReturnZeroForEmptyListcomputeAverageWaitTime_shouldReturnZeroWhenAllEntriesHaveNullEndedAtcomputeAverageWaitTime_shouldReturnCorrectAverageForEntriesWithEndedAtcomputeAverageWaitTime_shouldSkipEntriesWithNullEndedAt##Related
https://openmrs.atlassian.net/jira/software/c/projects/O3/boards/37?selectedIssue=O3-5485