Skip to content
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

(Feat): Parse BEP TestSummary #242

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open

(Feat): Parse BEP TestSummary #242

wants to merge 16 commits into from

Conversation

TylerJang27
Copy link
Collaborator

@TylerJang27 TylerJang27 commented Dec 17, 2024

Follow-up to #215 (incomplete, just timestamps) and #226 (more BEP debugging). Parses bazel TestSummary events in order to override the failure status of a given junit. This allows us to properly return a zero exit code if bazel marks a test as flaky, rather than waiting for a quarantine status to properly return.

This should hopefully also allow us to better inform the rules engine for test runner-identified flakiness from bazel

Notes:

  • I have attempted to make this as generic as possible without entangling too much logic with bazel parsing
  • Unfortunately this logic does have to (and already does) live in the client, since we need to parse the junits in order to properly arrive at a quarantine result
  • I have added unit and integration tests here, and also validated this against the repros identified in thread.

Copy link

trunk-io bot commented Dec 17, 2024

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once again, sanitized to include real data but stripped for just relevant tests

@TylerJang27 TylerJang27 changed the title (Feat): (Feat): Parse BEP TestSummary Dec 17, 2024
Copy link

trunk-staging-io bot commented Dec 17, 2024

Static BadgeStatic BadgeStatic BadgeStatic Badge

View Full Report ↗︎Docs

@TylerJang27 TylerJang27 marked this pull request as ready for review December 17, 2024 07:35
context/src/bazel_bep/parser.rs Outdated Show resolved Hide resolved
});
bep_test_events.push(build_event);
}
_ => {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to explicitly match the remaining combinations so that we don't add more permutations without handling them in the future?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spoke offline, there are 28 different variants here, so probably not worth. I may just make this an if though

cli/src/main.rs Outdated Show resolved Hide resolved
bundle/src/files.rs Outdated Show resolved Hide resolved
Comment on lines 11 to 29
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
#[cfg_attr(feature = "pyo3", gen_stub_pyclass_enum, pyclass(eq, eq_int))]
#[cfg_attr(feature = "wasm", derive(Tsify))]
pub enum TestRunnerJunitStatus {
#[default]
Passed,
Failed,
Flaky,
}

/// Encapsulates the glob path for a junit and, if applicable, the flakiness already
/// assigned by the user's test runner. See bazel_bep/parser.rs for more.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct JunitPathWrapper {
/// Path or glob pattern to the junit file.
pub junit_path: String,
/// Refers to an optional status parsed from the test runner's output, before junits have been parsed.
pub status: Option<TestRunnerJunitStatus>,
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to genericizing this, I think we ought to consider this a JunitReportStatus and JunitReportFileWithStatus. Test runners can tell us the status, but it should be fairly trivial for us to derive it from the JUnit report by seeing how many failures and reruns there were. We could even record both what the test runner says and what we derive from the JUnit report for the express reason of checking if those agree and processing quarantining as the test runner says (lest our inference is incorrect). Given that, I think we should always be able to populate status and if that's not true, I think we should probably consider adding an Unknown variant instead of making status Option<T>. With this, we can then extend our quarantining check for all JUnit reports rather than just what Bazel or other test runners tell us.

Copy link
Member

@dfrankland dfrankland Dec 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a follow up ticket to add more generic support for all JUnit report files:
https://linear.app/trunk/issue/TRUNK-13911/parse-junit-files-and-check-for-reruns-for-quarantining-in-analytics

It's a part of a larger project to support same-upload reruns flake classification:
https://linear.app/trunk/project/same-upload-test-reruns-7cc622cfc105/issues

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spoke offline, I will undertake the small refactor/renaming here, and then those tickets will capture the follow-up work for parsing the junits themselves

@@ -39,6 +40,8 @@ pub struct FileSet {
pub file_set_type: FileSetType,
pub files: Vec<BundledFile>,
pub glob: String,
/// Added in v0.6.11. Populated when parsing from BEP, not from junit globs
pub test_runner_status: Option<JunitReportStatus>,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up making it optional again since that allows us to better deserialize. Otherwise we need to have some versioned logic here for deserializing from meta.json, which doesn't seem worth the effort for this particular case

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

Successfully merging this pull request may close these issues.

2 participants