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

Custom buck test runner #147

Closed
wants to merge 26 commits into from
Closed

Conversation

baioc
Copy link
Contributor

@baioc baioc commented Aug 1, 2021

Custom buck test runner for #145

This PR provides an external test runner which is currently able to list out individual unit tests from Python and Rust binaries coming from buck tests, execute them in parallel and report results in JUnit's XML format, which should be CI-compatible (although integration with the test reporter is yet to be tested).
It can also retry tests and will silently ignore those manually marked for exclusion (for instance, those with a "disabled" label).

The next step after this is implementing the rest of #145, namely a way to keep track of state between test runs on the CI so as to automatically disable some tests.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 1, 2021
Copy link
Contributor

@vmagro vmagro left a comment

Choose a reason for hiding this comment

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

Great start!
I think we can get this landed in its own CI job soon (I don't want to lose the full buck test functionality until this is at feature parity)

tools/test-runner/src/main.rs Outdated Show resolved Hide resolved
tools/test-runner/src/main.rs Outdated Show resolved Hide resolved
tools/test-runner/src/main.rs Show resolved Hide resolved
tools/test-runner/src/main.rs Outdated Show resolved Hide resolved
tools/test-runner/src/main.rs Outdated Show resolved Hide resolved
tools/test-runner/src/main.rs Outdated Show resolved Hide resolved
tools/test-runner/src/main.rs Outdated Show resolved Hide resolved
tools/test-runner/src/main.rs Show resolved Hide resolved
tools/test-runner/src/main.rs Outdated Show resolved Hide resolved
env: HashMap<String, String>,

/// Labels that are defined on the test rule. NOTE: not used
labels: Vec<String>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Just leaving a note here - this is a good place if we ever need a way to control the test runner behavior from the unitttest target itself - it's a common pattern we use internally but I don't see a need for it in oss yet

tools/test-runner/src/buck_test.rs Show resolved Hide resolved
/// Absolute paths to any files required by this test target.
required_paths: Option<Vec<PathBuf>>,
}
fn default_kind() -> TestKind {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this allow falling back to shell tests for the unsupported gtest type? If so cool, otherwise I still like it :)

Copy link
Contributor Author

@baioc baioc Aug 16, 2021

Choose a reason for hiding this comment

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

I don't think so. This default only applies when the JSON doesn't have a type tag at all, so If serde finds "type" : <something> in the test spec, <something> needs to match some case in the TestKind enum.
This means that, right now, passing gtest will give a syntax error when parsing the JSON spec

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha, makes sense

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After realizing buck does add a "custom" tag when no type is provided in sh_test, I removed this default.
In the future, we could change the parsing behavior so as to assign the Shell type to anything not recognized. This would mean implementing a custom serde Deserialize for the TestKind enum.

tools/test-runner/src/buck_test.rs Outdated Show resolved Hide resolved
tools/test-runner/src/buck_test.rs Outdated Show resolved Hide resolved
return Ok(());
}

fn xml_escape_text(unescaped: String) -> String {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is fine for now, but may end up causing unexpected issues in the future. Don't fix it in this PR, but serde_xml_rs may work (https://docs.rs/serde-xml-rs/0.5.0/serde_xml_rs/) - if not (there are some things that it can't serialize) then I have used quick_xml in the past

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah since I had a very specific format to generate, I thought doing it by hand would be easier.
Later on I realized we would need to escape stdout/err, so using a dedicated library would probably be less error prone.

tools/test-runner/src/pyunit.rs Outdated Show resolved Hide resolved
@baioc baioc marked this pull request as ready for review August 17, 2021 11:52
@baioc baioc requested a review from vmagro August 17, 2021 11:53
Copy link
Contributor

@vmagro vmagro left a comment

Choose a reason for hiding this comment

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

Just one simple change then I will import this PR internally :)

tools/test-runner/src/buck_test.rs Outdated Show resolved Hide resolved
}

if !error.is_empty() {
bail!("Invalid context for test target {}\n{}", spec.target, error);
Copy link
Contributor

Choose a reason for hiding this comment

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

I like how you collect all the errors instead of just bailing on the first one :)

Copy link
Contributor

@vmagro vmagro left a comment

Choose a reason for hiding this comment

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

Cool, I think this looks good. Going to import it now and fixup the buck targets

@facebook-github-bot
Copy link
Contributor

@vmagro has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@vmagro merged this pull request in 654435b.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants