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 helpers to check events #392

Merged
merged 4 commits into from
Aug 26, 2021
Merged

Add helpers to check events #392

merged 4 commits into from
Aug 26, 2021

Conversation

ethanfrey
Copy link
Member

This may be a nice one for simplifying multi-tests.

Needs a unit test or two before merge.

Copy link
Contributor

@hashedone hashedone left a comment

Choose a reason for hiding this comment

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

Elegant and simple, love it - I was looking for something like this but I got braindead and couldn't figure it out.

Couple stylistic comments from my side. Naming issues are completely not important and I would not bring them up on their own, just gave my thought as I wanted to give some more relevant comments at particular line anyway - if you prefer your names don't bother with my suggestions on this field. However I would prefer to not take events by value as in one case I actually see benefit from checking for same event multiple times - don't see a reason to clone it. Also improving failure mesg is kind of imporant.

packages/multi-test/src/executor.rs Outdated Show resolved Hide resolved
packages/multi-test/src/executor.rs Outdated Show resolved Hide resolved
/// Like has_event but panics if no match
#[track_caller]
pub fn assert_event(&self, compare: Event) {
assert!(self.has_event(compare));
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't like how would failing test report looks like, it would be something like: "assertion failed, assert!(self.has_event(compare))" (probably somehow more details but in this shape). After all one would need to add some more prints to figure out what events actually got received (and also what was expected, but this can be probably read from tests itself). Hopefully assert macro may take additional arguments being the format string and its arguments for the failure case - but to make it work has_event cannot consume expected event.

Suggested change
assert!(self.has_event(compare));
assert!(self.has_event(expected), "Expected to find an event {:?}, but received: {:?}", self, expected);

packages/multi-test/src/executor.rs Outdated Show resolved Hide resolved
packages/multi-test/src/executor.rs Outdated Show resolved Hide resolved
@ethanfrey
Copy link
Member Author

Great feedback. Thanks

@ethanfrey
Copy link
Member Author

I updated to what you suggested (except a small change on the assert error message)

@ethanfrey ethanfrey marked this pull request as ready for review August 26, 2021 09:03
assert_eq!("transfer", &reply_events[0].ty);
let reply = res.result.unwrap();
assert_eq!(1, reply.events.len());
// Note: this shows we must make the helpers more generic
Copy link
Member Author

Choose a reason for hiding this comment

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

I will merge this as soon as the CI passes.

@hashedone this is one example where we want to make it more generic (also to work with your test suites). Happy if you have some follow-up PRs to extend this pattern other places.

@ethanfrey ethanfrey merged commit 3539081 into main Aug 26, 2021
@ethanfrey ethanfrey deleted the event-compare-helper branch August 26, 2021 09:10
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.

None yet

2 participants