discard defaulted, old timestamps when validating#1027
Conversation
|
😎 Merged successfully - details. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1027 +/- ##
==========================================
+ Coverage 81.40% 81.72% +0.32%
==========================================
Files 69 69
Lines 14527 14537 +10
==========================================
+ Hits 11825 11880 +55
+ Misses 2702 2657 -45 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| let two_days_ago = Utc::now() | ||
| .checked_sub_days(Days::new(2)) | ||
| .unwrap() | ||
| .timestamp(); | ||
| let test_started_at = Timestamp { | ||
| seconds: 1000, | ||
| seconds: two_days_ago, | ||
| nanos: 0, | ||
| }; | ||
| let test_finished_at = Timestamp { | ||
| seconds: 2000, | ||
| seconds: two_days_ago + 1000, | ||
| nanos: 0, |
There was a problem hiding this comment.
These were basically set to 1970-01-01, so I've updated them to be old, but not invalid and discarded
| /// Don't even consider timestamps older than this reference date time delta when validating | ||
| /// timestamps. These timestamps are considered to be defaulted by the test runner, test reporter, | ||
| /// or test suite, so they are unactionable and should be ignored. | ||
| pub const DISCARD_DEFAULTED_TIMESTAMP_OLDER_THAN_REFERENCE_TIMESTAMP: TimeDelta = | ||
| TimeDelta::days(30); |
There was a problem hiding this comment.
Anything older than 30 days is probably a mistake, not just something that's being uploaded a bit late
| let mut issues: Vec<JunitTestCaseValidationIssueSubOptimal> = Vec::new(); | ||
| let timestamp_with_fallbacks = [test_case_timestamp, test_suite_timestamp, report_timestamp] | ||
| .iter() | ||
| .find_map(|ts| ts.discard_defaulted_timestamp(reference_timestamp)); |
There was a problem hiding this comment.
I updated this function to be a little simpler utilizing some language features in Rust edition 2024.
calling discard_defaulted_timestamp is the only material change
| trait DiscardDefaultedTimestamp<T: Into<DateTime<FixedOffset>>> { | ||
| fn discard_defaulted_timestamp(self, reference_timestamp: T) -> Self | ||
| where | ||
| Self: marker::Sized; | ||
| } | ||
|
|
||
| impl DiscardDefaultedTimestamp<DateTime<FixedOffset>> for Option<DateTime<FixedOffset>> { | ||
| fn discard_defaulted_timestamp(self, reference_timestamp: DateTime<FixedOffset>) -> Self { | ||
| self.filter(|timestamp| { | ||
| *timestamp | ||
| > reference_timestamp | ||
| .checked_sub_signed(DISCARD_DEFAULTED_TIMESTAMP_OLDER_THAN_REFERENCE_TIMESTAMP) | ||
| .unwrap_or_default() | ||
| }) | ||
| } | ||
| } |
There was a problem hiding this comment.
Here's what helps do the check for whether the timestamp should be discarded
| @@ -344,10 +362,24 @@ fn validate_timestamps() { | |||
| JunitValidationIssueType::Report(JunitReportValidationIssue::SubOptimal( | |||
| JunitReportValidationIssueSubOptimal::FutureTimestamps, | |||
| )), | |||
| ], | |||
| "failed to validate with seed `{}`", | |||
| seed, | |||
| ); | |||
| ]; | |||
| // discarded timestamps have fallbacks, so timestamps are only reported missing if there's | |||
| // other non-discarded timestamps present | |||
| if generated_report_index > 1 { | |||
| expected_issues.push(JunitValidationIssueType::Report( | |||
| JunitReportValidationIssue::SubOptimal( | |||
| JunitReportValidationIssueSubOptimal::MissingTimestamps, | |||
| ), | |||
| )); | |||
| } | |||
|
|
|||
| pretty_assertions::assert_eq!( | |||
| report_validation.all_issues(), | |||
| expected_issues, | |||
| "failed to validate with seed `{}`", | |||
| seed, | |||
| ); | |||
There was a problem hiding this comment.
This checks that the old behavior is preserved and that invalid test case timestamps are only reported when all timestamps are either missing or invalid.
See Slack thread for details:
https://trunk-io.slack.com/archives/C09GP4PFWTD/p1770178649384319?thread_ts=1770172846.666909&cid=C09GP4PFWTD