Fix millisecond zero-padding in epoch_to_log_line_timestamp - #1028
Draft
rootkiller6788 wants to merge 1 commit into
Draft
Fix millisecond zero-padding in epoch_to_log_line_timestamp#1028rootkiller6788 wants to merge 1 commit into
rootkiller6788 wants to merge 1 commit into
Conversation
epoch_to_log_line_timestamp concatenated the milliseconds field with str(), which drops leading zeros for values below 100. The resulting timestamp (e.g. '07-21 20:51:02.5') does not match the canonical log line timestamp format, which always uses three millisecond digits, and fails is_valid_logline_timestamp. Zero-pad the milliseconds to three digits and add a regression test.
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.
Problem
mobly.logger.epoch_to_log_line_timestampproduced a non-zero-padded millisecond component:For epoch values whose millisecond remainder is below 100,
str(ms)drops the leading zeros. For exampleepoch_to_log_line_timestamp(1469134262005, time_zone=datetime.timezone.utc)returned'07-21 20:51:02.5'instead of'07-21 20:51:02.005'.This is inconsistent with the canonical log line timestamp format used everywhere else in the module:
get_log_line_timestampreturns exactly three millisecond digits,logline_timestamp_rematches\d\d\dafter the dot, andis_valid_logline_timestamprejects anything else. Such malformed timestamps also compare incorrectly withlogline_timestamp_comparator, which relies on fixed-width fields.Fix
Zero-pad the millisecond component to three digits:
Test
Added
test_epoch_to_log_line_timestamp_pads_millisecondscovering millisecond remainders of 0, 5, 50 and 99, asserting both the exact output and thatis_valid_logline_timestampaccepts it.python -m pytest tests/mobly/logger_test.pypasses (27 passed).