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

Add ability to wrap test execution + check for quarantining #31

Merged
merged 12 commits into from
Mar 22, 2024

Conversation

gnalh
Copy link
Contributor

@gnalh gnalh commented Mar 20, 2024

In order to be able to quarantine tests we need to wrap the test execution and inspect the results of the test. If a test fails and that test is quarantined then we will override the exit code, otherwise we will return the original exit code.

Example:

cargo run test --junit-paths=py/*.xml --org-url-slug trunk-staging-org --token=[REDACTED] --dry-run -- pytest py/test.py --junitxml=py/test.xml

Copy link

trunk-staging-io bot commented Mar 20, 2024

💊 0 quarantined ✅ 10 passed 🕐 10 new ⋅ (learn more)

docs ⋅ learn more about trunk.io

@gnalh gnalh force-pushed the gabe/analytics-wrapper branch 2 times, most recently from b7d232c to 36259d8 Compare March 20, 2024 16:23
@@ -45,7 +45,7 @@ jobs:

- name: Upload results using action from ${{ matrix.target }}
env:
TRUNK_API_ADDRESS: https://api.trunk-staging.io/v1/metrics/createBundleUpload
TRUNK_API_ADDRESS: https://api.trunk-staging.io
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We'll need to update our own repo to match once this is live.

Copy link
Contributor

Choose a reason for hiding this comment

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

should we still call this TRUNK_API_ADDRESS? maybe TRUNK_API_ORIGIN would be more appropriate?

Copy link
Contributor Author

@gnalh gnalh Mar 20, 2024

Choose a reason for hiding this comment

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

TRUNK_API_ADDRESS is a pattern we use elsewhere.

src/constants.rs Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
@gnalh gnalh requested review from zaycev and riya-n March 20, 2024 16:31
@gnalh gnalh marked this pull request as ready for review March 20, 2024 16:31
@gnalh gnalh marked this pull request as draft March 20, 2024 16:31
@gnalh gnalh marked this pull request as ready for review March 20, 2024 18:10
@gnalh gnalh changed the title Add ability to wrap test execution Add ability to wrap test execution + check for quarantining Mar 20, 2024
src/main.rs Show resolved Hide resolved
if let Err(e) = run(cli).await {
log::error!("Error: {:?}", e);
std::process::exit(exitcode::SOFTWARE);
match run(cli).await {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe I'm missing something but if we already have result which can be either success or failure, why do we also need to return exit code? What would Ok(EXIT_FAILURE) mean? Does it mean we successfully captured failure of a test run and we want to propagate it to the caller of cli?

Copy link
Contributor Author

@gnalh gnalh Mar 20, 2024

Choose a reason for hiding this comment

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

We need to pipe the original exit code up so that we surface the expected results to the caller. Since the plan is to wrap test executions, we don't want to hide it if the results weren't quarantined.

src/main.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
let file = std::fs::File::open(&file.original_path)?;
let reader = std::io::BufReader::new(file);
let junitxml = junit_parser::from_reader(reader)?;
for suite in junitxml.suites {
Copy link
Contributor

@zaycev zaycev Mar 20, 2024

Choose a reason for hiding this comment

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

Feel free to do it in the next PR, testing parsing of XMLs is totally something we should test before rolling this out.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Running into issues getting tests running on my machine. Will address in a follow-up.

command: &String,
args: Vec<&String>,
output_paths: Vec<&String>,
) -> anyhow::Result<RunResult> {
Copy link
Contributor

Choose a reason for hiding this comment

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

If this function fails to process output of the command, what will happen? Do we ever want to override exit code of the child command?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We should only override the exit code if the only failures parsed were quarantined.

@zaycev
Copy link
Contributor

zaycev commented Mar 20, 2024

Overall – LGTM.

// Tokio-retry uses base ^ retry * factor formula.
// This will give us 8ms, 64ms, 512ms, 4096ms, 32768ms
const RETRY_BASE_MS: u64 = 8;
const RETRY_FACTOR: u64 = 1;
const RETRY_COUNT: usize = 5;
const RETRY_COUNT: usize = 3;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

5 was causing very long delays when there were issues with the api.

Copy link
Contributor

Choose a reason for hiding this comment

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

I've brought this up with Vlad before and he suggested keeping it at 5 because this gives the backend enough time to auto-resolve issues, expensive queries to finish, etc. Not sure if this is still a concern though cc @zaycev

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The delay is very long with 5 (10+ seconds). I think we need a lower number.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I'd mentioned that to Vlad as well. Will let him comment on this

Copy link
Contributor

Choose a reason for hiding this comment

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

5 was causing very long delays when there were issues with the api.

That was the original point for adding this delay - wait enough for transient issue to resolve. What are the down sites of it?

Copy link
Contributor Author

@gnalh gnalh Mar 21, 2024

Choose a reason for hiding this comment

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

It feels broken when nothing happens for 20 seconds. If every api call has this retry logic then we end up wasting a lot of time.

@gnalh gnalh requested a review from zaycev March 20, 2024 18:45
src/clients.rs Outdated Show resolved Hide resolved
src/clients.rs Show resolved Hide resolved
@@ -45,7 +45,7 @@ jobs:

- name: Upload results using action from ${{ matrix.target }}
env:
TRUNK_API_ADDRESS: https://api.trunk-staging.io/v1/metrics/createBundleUpload
TRUNK_API_ADDRESS: https://api.trunk-staging.io
Copy link
Contributor

Choose a reason for hiding this comment

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

should we still call this TRUNK_API_ADDRESS? maybe TRUNK_API_ORIGIN would be more appropriate?

// Tokio-retry uses base ^ retry * factor formula.
// This will give us 8ms, 64ms, 512ms, 4096ms, 32768ms
const RETRY_BASE_MS: u64 = 8;
const RETRY_FACTOR: u64 = 1;
const RETRY_COUNT: usize = 5;
const RETRY_COUNT: usize = 3;
Copy link
Contributor

Choose a reason for hiding this comment

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

I've brought this up with Vlad before and he suggested keeping it at 5 because this gives the backend enough time to auto-resolve issues, expensive queries to finish, etc. Not sure if this is still a concern though cc @zaycev

src/main.rs Outdated Show resolved Hide resolved
@riya-n riya-n self-requested a review March 20, 2024 19:49
@gnalh
Copy link
Contributor Author

gnalh commented Mar 20, 2024

This is ready for a re-review.

@zaycev
Copy link
Contributor

zaycev commented Mar 21, 2024

LGTM

@gnalh gnalh merged commit ffc06f3 into main Mar 22, 2024
5 checks passed
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.

3 participants