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

Make some blocking tests non-blocking #11650

Merged
merged 5 commits into from Feb 24, 2023

Conversation

hi-rustin
Copy link
Member

@hi-rustin hi-rustin commented Jan 30, 2023

Signed-off-by: hi-rustin rustin.liu@gmail.com

What does this PR try to resolve?

close #11615

Make some blocking tests non-blocking.

Check the unit tests.

Additional information

None

r? @ehuss

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 30, 2023
@hi-rustin
Copy link
Member Author

Use -Zpublish-timeout and .cargo/config to disable publish timeout for some tests.

@ehuss Do you think this is reasonable?

@ehuss
Copy link
Contributor

ehuss commented Feb 14, 2023

Just checking in @hi-rustin if you had any questions. I think enabling the API for publish is probably the right way to go.

@hi-rustin
Copy link
Member Author

I think enabling the API for publish is probably the right way to go.

Yeah, I am going to fix some tests that do not need to check the content first. Then I will make the HTTP mock server support assert its content to support other tests.

@hi-rustin hi-rustin changed the title Disable publish timeout for some tests Make some blocking tests non-blocking Feb 15, 2023
@hi-rustin hi-rustin marked this pull request as ready for review February 15, 2023 02:13
@hi-rustin hi-rustin requested a review from epage February 15, 2023 02:13
@hi-rustin
Copy link
Member Author

@ehuss @epage Do you mind taking another look at this PR first? I need more time to support checking the content of the HTTP mock server. So maybe we can review and merge this PR first?

@ehuss
Copy link
Contributor

ehuss commented Feb 15, 2023

I need more time to support checking the content of the HTTP mock server. So maybe we can review and merge this PR first?

I would prefer to not remove test coverage just to merge a PR sooner.

For the tests that want to validate the JSON of the API request, I would suggest doing the following:

Factor out the code from _validate_upload so that it works with a &[u8] instead of a File.

In tests, add a responder to the registry builder:

.add_responder("/api/v1/crates/new", 
    validate_api_publish(
        r#"{
            "authors": [],
            ...
        }"#,
        "foo-0.0.1.crate",
        &["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/main.rs"],
    ))

The validate_api_publish function should return a function:

fn validate_publish(...) -> impl Fn(&Request, &HttpServer) -> Response {
    |request, server| -> Response {
        // code here should take request.body and feed that into _validate_upload
        // and return the appropriate response 
        server.ok(request)
    }
}

Let me know if you have any questions or thoughts on that approach.

@hi-rustin
Copy link
Member Author

hi-rustin commented Feb 16, 2023

I would prefer to not remove test coverage just to merge a PR sooner.

Sorry I wasn't clear, my current changes are for tests that don't require checking content. Because they don't have any specificity in their content. We can just check it via stdout. So I think these changes sould not change any test coverages.

But if you prefer, we can include any changes in this PR. That's fine with me.

@hi-rustin
Copy link
Member Author

Let me know if you have any questions or thoughts on that approach.

Thanks a lot! I'll try it.

@rustbot rustbot added the A-testing-cargo-itself Area: cargo's tests label Feb 17, 2023
@ehuss
Copy link
Contributor

ehuss commented Feb 17, 2023

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 17, 2023
@hi-rustin
Copy link
Member Author

@ehuss I added validate_api_publish and validate_api_publish_with_contents to support checking the HTTP request for a crate publish.

But I found if we use normalize_expected in another thread it will panic. Because we try to normalize TEST_ID, and it is a thread-local variable, it causes panic.

Do you have any suggestions about how to fix it?

@ehuss
Copy link
Contributor

ehuss commented Feb 18, 2023

Oh, that's unfortunate! Ok, new strategy: In check_authorized_publish, save the contents of req.body into api_path().join("v1/crates/new"). No need to add a custom responder, or modify validate_upload. That should significantly reduce the number of changes needed here. Does that sound like it should work?

@hi-rustin
Copy link
Member Author

Ok, new strategy: In check_authorized_publish, save the contents of req.body into api_path().join("v1/crates/new"). No need to add a custom responder, or modify validate_upload. That should significantly reduce the number of changes needed here. Does that sound like it should work?

Yes. I think it would work. I'll try it tomorrow. Thanks!

@hi-rustin hi-rustin force-pushed the rustin-patch-tests branch 3 times, most recently from a34cbc0 to 155906c Compare February 19, 2023 13:23
@hi-rustin
Copy link
Member Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author. labels Feb 19, 2023
@hi-rustin
Copy link
Member Author

For CI failed, see more at zulip.

@hi-rustin hi-rustin requested review from ehuss and removed request for arlosi February 23, 2023 01:28
@epage
Copy link
Contributor

epage commented Feb 24, 2023

I rebased this on top of #11738 so I could use cargo nextests test-time reporting and I am not seeing any slow registery tests, so I believe that confirms the issue is resolved with this change.

Of note, the lto tests are very slow, taking 17-35s each

@bors r+

@bors
Copy link
Collaborator

bors commented Feb 24, 2023

📌 Commit fbe7ac2 has been approved by epage

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 24, 2023
@bors
Copy link
Collaborator

bors commented Feb 24, 2023

⌛ Testing commit fbe7ac2 with merge 65cab34...

@hi-rustin
Copy link
Member Author

Thanks for your review! 💚 💙 💜 💛 ❤️


// Now perform the actual publish
p.cargo("publish --registry alternative").run();

validate_alt_upload(
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you say why this validation was removed? I would not expect it to be removed.

Copy link
Contributor

Choose a reason for hiding this comment

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

sigh I was specifically looking for any still removed and missed this. Thanks for spotting it!

Copy link
Contributor

Choose a reason for hiding this comment

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

@hi-rustin Can you post a PR to return the publish_to_alt_registry test so that it validates the upload?

@bors
Copy link
Collaborator

bors commented Feb 24, 2023

☀️ Test successful - checks-actions
Approved by: epage
Pushing 65cab34 to master...

1 similar comment
@bors
Copy link
Collaborator

bors commented Feb 24, 2023

☀️ Test successful - checks-actions
Approved by: epage
Pushing 65cab34 to master...

@bors
Copy link
Collaborator

bors commented Feb 24, 2023

👀 Test was successful, but fast-forwarding failed: 422 Changes must be made through a pull request.

@bors bors merged commit 65cab34 into rust-lang:master Feb 24, 2023
@ehuss
Copy link
Contributor

ehuss commented Feb 24, 2023

@hi-rustin Were your concerns about the order of the output in inherit_dependencies resolved? I'm concerned that this is introducing non-deterministic behavior. Do you know why the order was different? Is it still having issues on your machine? Do you know what was behind that?

@hi-rustin
Copy link
Member Author

Were your concerns about the order of the output in inherit_dependencies resolved?

I didn't meet it anymore after I updated the output and rebased from the master branch.

Do you know why the order was different? Is it still having issues on your machine?

It's always been stable on my computer. It's only in CI that I've encountered instability. But the past few tests have passed stably. I'm not quite sure what exactly is affecting it. Maybe there was a mistake in my code at the time. I'll keep watching. I'll keep trying to fix it if there's a problem.

@hi-rustin hi-rustin deleted the rustin-patch-tests branch February 24, 2023 05:21
bors added a commit that referenced this pull request Feb 25, 2023
Fix tests with nondeterministic ordering

A couple tests updated in #11650 started using curl's http API. It appears to have a nondeterministic order for when crates will finish downloading. This addresses it by ignoring the order, which is not important for these tests.
weihanglo added a commit to weihanglo/rust that referenced this pull request Feb 28, 2023
10 commits in 9d5b32f503fc099c4064298465add14d4bce11e6..9880b408a3af50c08fab3dbf4aa2a972df71e951
2023-02-22 23:04:16 +0000 to 2023-02-28 19:39:39 +0000

- bump jobserver to respect `--jobserver-auth=fifo:PATH` (rust-lang/cargo#11767)
- Addition of support for -F as an alias for --features (rust-lang/cargo#11774)
- Added documentation for the configuration discovery of `cargo install` to the man pages (rust-lang/cargo#11763)
- Fix Cargo removing the sparse+ prefix from sparse URLs in .crates.toml (rust-lang/cargo#11756)
- Fix warning with tempfile (rust-lang/cargo#11771)
- Error message for transitive artifact dependencies with targets the package doesn't directly interact with (rust-lang/cargo#11643)
- Fix tests with nondeterministic ordering (rust-lang/cargo#11766)
- Make some blocking tests non-blocking (rust-lang/cargo#11650)
- Suggest cargo add when installing library crate (rust-lang/cargo#11410)
- chore: bump is-terminal to 0.4.4 (rust-lang/cargo#11759)
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 1, 2023
Update cargo

10 commits in 9d5b32f503fc099c4064298465add14d4bce11e6..9880b408a3af50c08fab3dbf4aa2a972df71e951 2023-02-22 23:04:16 +0000 to 2023-02-28 19:39:39 +0000

- bump jobserver to respect `--jobserver-auth=fifo:PATH` (rust-lang/cargo#11767)
- Addition of support for -F as an alias for --features (rust-lang/cargo#11774)
- Added documentation for the configuration discovery of `cargo install` to the man pages (rust-lang/cargo#11763)
- Fix Cargo removing the sparse+ prefix from sparse URLs in .crates.toml (rust-lang/cargo#11756)
- Fix warning with tempfile (rust-lang/cargo#11771)
- Error message for transitive artifact dependencies with targets the package doesn't directly interact with (rust-lang/cargo#11643)
- Fix tests with nondeterministic ordering (rust-lang/cargo#11766)
- Make some blocking tests non-blocking (rust-lang/cargo#11650)
- Suggest cargo add when installing library crate (rust-lang/cargo#11410)
- chore: bump is-terminal to 0.4.4 (rust-lang/cargo#11759)

r? `@ghost`
@ehuss ehuss added this to the 1.69.0 milestone Mar 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-testing-cargo-itself Area: cargo's tests S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Publish timeout issues with tests
6 participants