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

Do not double panic in FakeParentArgs::drop #1856

Merged
merged 1 commit into from
Sep 15, 2024

Conversation

dvermd
Copy link
Contributor

@dvermd dvermd commented Sep 10, 2024

Check if we're already panicking before calling error which will also panic.

Comment on lines 859 to 880
fn test_process_testing_assert_never_used() {
let _args = FakeParentArgs::once("never used");

// causes a panic while panicking, so can't test:
// let _args = FakeParentArgs::for_scope(&"never used");
// let _args = FakeParentArgs::once(&"never used");
let _args = FakeParentArgs::for_scope(&"never used");
let _args = FakeParentArgs::once(&"never used");
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice. Now that this is testable, this test needs to be split into separate cases. once() should panic on drop, even stand-alone as before, because it is never used.

But calling for_scope twice should panic in the constructor because the previous state (in the thread local variable) was not cleared out properly (and previously the drop also panicked because it encountered bad state as well).

Actually, couldn't FakeParentArgs::error just set the state so that drop doesn't panic again? And to ensure the correct panic is hit maybe the more precise #[should_panic(expected = "msg here")] can be used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think all FakeParentArgs will go through drop before error being called in this construct.

            if FAKE_ARGS.with(|a| a.replace(initial(string_vec))) != TlsState::None {
                Self::error(from_);
            }

Thus, we'll only get panics from the drop method and none from the constructors

@dvermd dvermd force-pushed the do_not_double_panic branch 2 times, most recently from 4f852b2 to e8cf280 Compare September 12, 2024 02:13
src/utils/process.rs Outdated Show resolved Hide resolved
@th1000s th1000s merged commit c384eed into dandavison:main Sep 15, 2024
13 checks passed
@dvermd dvermd deleted the do_not_double_panic branch September 15, 2024 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants