8000 tests: use the json visitor to implement a simple path matcher by schopin-mozilla · Pull Request #207 · rust-minidump/minidump-writer · GitHub
[go: up one dir, main page]

Skip to content

tests: use the json visitor to implement a simple path matcher - #207

Merged
marti4d merged 1 commit into
rust-minidump:mainfrom
schopin-mozilla:soft-errors-brittle
Aug 20, 2026
Merged

marti4d merged 1 commit into
rust-minidump:mainfrom
schopin-mozilla:soft-errors-brittle

Conversation

@schopin-mozilla
@schopin-mozilla schopin-mozilla commented Aug 17, 2026 •
Copy link
Copy Markdown
Collaborator

The adhoc visitor in soft_error_stream_content is checking for some
basic structure properties without being as strict as assert_soft_errors_in_minidump
is. This patch simply hides the struct walking behind a helper, so that
the intent is clearly shown in the test itself, and the nitty-gritty of
walking through the JSON are hidden away in a helper.

Extracted from #195

@marti4d marti4d left a comment
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Lol you and I had a mid-air collision on this. Sorry about that -- I did not realize, and mine has already been merged in: https://github.com/rust-minidump/minidump-writer/blob/main/tests/linux_minidump_writer_soft_error.rs#L35

I don't know which one we should keep, honestly. Yours reads better, and it looks like yours might be a bit more strict about what it will accept. Whether that's good or bad might be debatable -- My version of this allows you to use a function to evaluate whether each terminal node has a specific value and path leading to it. Flexible, but... More work to maintain.

Curious to hear your thoughts?

@schopin-mozilla
Copy link
Copy Markdown
Collaborator Author

I think having a json walker is probably a good idea in the long run, however I do think we need to have assert_soft_errors_in_minidump wrap that helper into something easier to use, yet with less strict semantics than it currently has, for the reasons I outlined in my commit log.

Let me rework this commit to use your helper instead, see how it goes.


// Ensure the MozSoftErrors stream contains the expected errors
let expected_errors = vec![
(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

So... With the understanding that I like the way you actually implemented this, I'm torn on re-adding the strictness that this implies.

The reason I moved to a bit more of a loose matching is experience with this crate -- Basically, every time somebody goes and refactors things a bit so that it slightly changes the structure of the errors, this test breaks.

So, I figured it might be worth stepping back and asking "What are the bits that we really care about, and what is just noise?"

And overall, my conclusion is: If the thing that we've done is "Ask failspot to return EPERM on StopProcess", then the thing we should be checking is "there exists a soft error somewhere that indicates StopProcess failed with EPERM".

So -- You see how the code I have accomplished that minimalism, and so I think that the structure like this is actually over-specified for what we actually need to test.

What do you think?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

To be completely honest, I didn't know what the purpose of the test really was. I'm all for loosening it, however I do think your approach is really hurtful in terms of readability of the test. I want to see what you're expecting out of the test, not how you go about finding that info!

Basically, something like this:

let dump = Minidump::read_path(tmpfile.path()).expect("failed to read minidump");
assert_minidump_soft_errors_match_all(&dump, &[
    ErrorPattern::value(EPERM).with_ancestor("StopProcessFailed"),
    ErrorPattern::value(AuxvError::InvalidFormat).with_ancestor("FillMissingAuxvInfoErrors"),
    ErrorPattern::value(EPERM).with_ancestor("ReadThreadNameFailed"),
    ErrorPattern::value(EPERM).with_ancestor("SuspendThreadErrors"),
    ErrorPattern::value(EPERM).with_ancestor("WriteCpuInformationFailed"),
]);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yep -- This is way better!

@schopin-mozilla
schopin-mozilla force-pushed the soft-errors-brittle branch 4 times, most recently from 70e95e6 to 886a0af Compare August 19, 2026 18:14
@marti4d marti4d left a comment
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM! Weird... Is panic not already part of the prelude?

Comment thread tests/common/mod.rs Outdated
@@ -1,10 +1,13 @@
use core::panic;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I assume this was needed for some reason?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

No it's not, I think it's a snippet thingy that was too zealous, and a committer that was in a hurry. Fixed.

The adhoc visitor in soft_error_stream_content is checking for some
basic structure properties without being as strict as assert_soft_errors_in_minidump
is. This patch simply hides the struct walking behind a helper, so that
the intent is clearly shown in the test itself, and the nitty-gritty of
walking through the JSON are hidden away in a helper.
@schopin-mozilla schopin-mozilla changed the title tests: match soft errors structurally rather than by whole value tests: use the json visitor to implement a simple path matcher Aug 20, 2026
@schopin-mozilla
Copy link
Copy Markdown
Collaborator Author

Yes of course, panic is in the prelude, and I'm pretty sure I never wrote this line manually. My bad.

I took the opportunity to change the description of the PR to reflect how it has evolved since (basically pasted the commit description).

@marti4d
marti4d merged commit 25cbd74 into rust-minidump:main Aug 20, 2026
16 checks passed
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

0