-
Notifications
You must be signed in to change notification settings - Fork 7
(Chore): Better telemetry for quarantine query #1100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
TylerJang27
wants to merge
2
commits into
tyler/reorganize-report-tests
Choose a base branch
from
tyler/better-telemetry-quarantining
base: tyler/reorganize-report-tests
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,7 @@ use lazy_static::lazy_static; | |
| use predicates::prelude::*; | ||
| use pretty_assertions::assert_eq; | ||
| use prost::Message; | ||
| use proto::upload_metrics::trunk::QuarantineQueryResult; | ||
| use tempfile::tempdir; | ||
| #[cfg(target_os = "macos")] | ||
| use test_utils::inputs::unpack_archive_to_dir; | ||
|
|
@@ -1277,6 +1278,10 @@ async fn telemetry_upload_metrics_on_upload_failure() { | |
| assert_eq!(telemetry_request_repo.owner, "trunk-io"); | ||
| assert_eq!(telemetry_request_repo.name, "analytics-cli"); | ||
| assert_eq!(telemetry_request.failure_reason, "400_bad_request"); | ||
| assert_eq!( | ||
| QuarantineQueryResult::try_from(telemetry_request.quarantine_query_result).unwrap(), | ||
| QuarantineQueryResult::Disabled | ||
| ); | ||
|
|
||
| // HINT: View CLI output with `cargo test -- --nocapture` | ||
| println!("{assert}"); | ||
|
|
@@ -1308,11 +1313,126 @@ async fn telemetry_upload_metrics_on_upload_success() { | |
| assert_eq!(telemetry_request_repo.owner, "trunk-io"); | ||
| assert_eq!(telemetry_request_repo.name, "analytics-cli"); | ||
| assert_eq!(telemetry_request.failure_reason, ""); | ||
| assert_eq!( | ||
| QuarantineQueryResult::try_from(telemetry_request.quarantine_query_result).unwrap(), | ||
| QuarantineQueryResult::Disabled | ||
| ); | ||
|
|
||
| // HINT: View CLI output with `cargo test -- --nocapture` | ||
| println!("{assert}"); | ||
| } | ||
|
|
||
| #[tokio::test(flavor = "multi_thread")] | ||
| async fn telemetry_upload_metrics_quarantine_query_result_success() { | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These CLI integration tests require a bit more custom setup because of the scenarios they test |
||
| let temp_dir = tempdir().unwrap(); | ||
| generate_mock_git_repo(&temp_dir); | ||
| generate_mock_valid_junit_xmls_with_failures(&temp_dir); | ||
|
|
||
| let state = MockServerBuilder::new().spawn_mock_server().await; | ||
|
|
||
| CommandBuilder::upload(temp_dir.path(), state.host.clone()) | ||
| .command() | ||
| .assert() | ||
| .failure(); | ||
|
|
||
| let requests = state.requests.lock().unwrap().clone(); | ||
| let quarantine_query_result = requests | ||
| .iter() | ||
| .rev() | ||
| .find_map(|req| match req { | ||
| RequestPayload::TelemetryUploadMetrics(ur) => Some(ur.quarantine_query_result), | ||
| _ => None, | ||
| }) | ||
| .expect("telemetry upload metrics request"); | ||
| assert_eq!( | ||
| QuarantineQueryResult::try_from(quarantine_query_result).unwrap(), | ||
| QuarantineQueryResult::Success | ||
| ); | ||
| } | ||
|
|
||
| #[tokio::test(flavor = "multi_thread")] | ||
| async fn telemetry_upload_metrics_quarantine_query_result_failure() { | ||
| let temp_dir = tempdir().unwrap(); | ||
| generate_mock_git_repo(&temp_dir); | ||
| generate_mock_valid_junit_xmls_with_failures(&temp_dir); | ||
|
|
||
| let mut mock_server_builder = MockServerBuilder::new(); | ||
| mock_server_builder.set_get_quarantining_config_handler( | ||
| |Json(_): Json<GetQuarantineConfigRequest>| async { | ||
| Err::<Json<GetQuarantineConfigResponse>, StatusCode>(StatusCode::INTERNAL_SERVER_ERROR) | ||
| }, | ||
| ); | ||
| let state = mock_server_builder.spawn_mock_server().await; | ||
|
|
||
| CommandBuilder::upload(temp_dir.path(), state.host.clone()) | ||
| .command() | ||
| .assert() | ||
| .failure(); | ||
|
|
||
| let requests = state.requests.lock().unwrap().clone(); | ||
| let quarantine_query_result = requests | ||
| .iter() | ||
| .rev() | ||
| .find_map(|req| match req { | ||
| RequestPayload::TelemetryUploadMetrics(ur) => Some(ur.quarantine_query_result), | ||
| _ => None, | ||
| }) | ||
| .expect("telemetry upload metrics request"); | ||
| assert_eq!( | ||
| QuarantineQueryResult::try_from(quarantine_query_result).unwrap(), | ||
| QuarantineQueryResult::Failure | ||
| ); | ||
| } | ||
|
|
||
| #[tokio::test(flavor = "multi_thread")] | ||
| async fn telemetry_upload_metrics_quarantine_query_result_skipped() { | ||
| let temp_dir = tempdir().unwrap(); | ||
| generate_mock_git_repo(&temp_dir); | ||
|
|
||
| // All-passing JUnit so quarantine lookup is skipped (no failed tests). | ||
| let test_case_options = junit_mock::TestCaseOptions { | ||
| test_case_names: Some(vec![String::from("test_case")]), | ||
| test_case_classnames: Some(vec![String::from("TestClass")]), | ||
| test_case_random_count: 0usize, | ||
| test_case_sys_out_percentage: 0u8, | ||
| test_case_sys_err_percentage: 0u8, | ||
| test_case_duration_range: vec![Duration::new(10, 0).into(), Duration::new(20, 0).into()], | ||
| test_case_success_to_skip_to_fail_to_error_percentage: vec![vec![100u8, 0u8, 0u8, 0u8]], | ||
| }; | ||
| let options = junit_mock::Options { | ||
| global: junit_mock::GlobalOptions::try_parse_from([""]).unwrap(), | ||
| report: junit_mock::ReportOptions::try_parse_from([""]).unwrap(), | ||
| test_suite: junit_mock::TestSuiteOptions::try_parse_from([""]).unwrap(), | ||
| test_case: test_case_options, | ||
| test_rerun: junit_mock::TestRerunOptions::try_parse_from([""]).unwrap(), | ||
| }; | ||
| let mut mock = JunitMock::new(options); | ||
| let reports = mock.generate_reports(); | ||
| mock.write_reports_to_file(temp_dir.as_ref(), reports) | ||
| .unwrap(); | ||
|
|
||
| let state = MockServerBuilder::new().spawn_mock_server().await; | ||
|
|
||
| CommandBuilder::upload(temp_dir.path(), state.host.clone()) | ||
| .command() | ||
| .assert() | ||
| .success(); | ||
|
|
||
| let requests = state.requests.lock().unwrap().clone(); | ||
| let quarantine_query_result = requests | ||
| .iter() | ||
| .rev() | ||
| .find_map(|req| match req { | ||
| RequestPayload::TelemetryUploadMetrics(ur) => Some(ur.quarantine_query_result), | ||
| _ => None, | ||
| }) | ||
| .expect("telemetry upload metrics request"); | ||
| assert_eq!( | ||
| QuarantineQueryResult::try_from(quarantine_query_result).unwrap(), | ||
| QuarantineQueryResult::Skipped | ||
| ); | ||
| } | ||
|
|
||
| #[tokio::test(flavor = "multi_thread")] | ||
| async fn telemetry_does_not_impact_return() { | ||
| let temp_dir = tempdir().unwrap(); | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unit test for this