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

fail: add test-mutex pattern directly to the library #40

Merged
merged 2 commits into from Jul 9, 2019

Conversation

lucab
Copy link
Member

@lucab lucab commented Jun 14, 2019

This adds a FailScenario to the library, exposing the usual idiom
of a global testing mutex and individual guards owned by each test.

The global mutex is kept as an internal detail and not exposed,
consumers can only borrow a guard via the scenario.

Closes: #23

@lucab
Copy link
Member Author

lucab commented Jun 14, 2019

/cc @BusyJay @brson @overvenus for review.

Do Not Merge (DNM): I haven't tested this on any consumer yet. It would be good if somebody familiar with tikv test-base could try to drop this one in place there and confirm I haven't missed/overlooked anything, before merging.

I'm not in a hurry to land this, I can wait till after 0.3 release (see #37 (comment)).

@lucab lucab force-pushed the ups/scenario branch 2 times, most recently from eddfd5f to 15898ce Compare June 16, 2019 09:04
@lucab lucab changed the title [DNM] fail: add test-mutex pattern directly to the library fail: add test-mutex pattern directly to the library Jun 16, 2019
@lucab
Copy link
Member Author

lucab commented Jun 16, 2019

I updated tikv testsuite to consume this: tikv/tikv#4903. CI is green.
This is ready for review and fine to land before 0.3, if you like.

@BusyJay
Copy link
Member

BusyJay commented Jun 17, 2019

This is so cool! @brson would you like to take a look?

Copy link
Collaborator

@brson brson left a comment

Choose a reason for hiding this comment

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

Thanks for taking an interest in this crate @lucab. I think I'm happy with this approach. Though it does force users to use the guard pattern, as you point out in the README it's simple to just apply the guard to the entire program. I did make a note asking to move cfg from a free function to a method.

src/lib.rs Outdated
//! let _gaurd = setup();
//! fail::cfg("read-dir", "panic").unwrap();
//! let scenario = FailScenario::setup();
//! scenario.cfg("read-dir", "panic").unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks to me like in this patch cfg is still a free function. Can you make it a method on FailScenario as depicted here?

Copy link
Member Author

Choose a reason for hiding this comment

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

That was my initial approach, but I had to revert back to a free function. This doc error is a leftover I didn't catch when undoing.

The reason why this needs to be a free function is that there is a case for consumers like this one in tikv: https://github.com/tikv/tikv/blob/82de1403905cb12ed988d85fa8da2ab99fb0adde/src/server/service/debug.rs#L269.
There, fail::cfg is used in project logic to override fail-points configuration, if any. That is decoupled from the scenario, thus we can't use FailScenario::cfg there.

Copy link
Member

Choose a reason for hiding this comment

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

If both fail::cfg and fail_point! can be made as methods of FailScenario, maybe we don't need the global lock at all. And tests can be run in parallel.

But I'm happy with current approach as it makes life easier at least.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this could be another PR? :)

Copy link
Member

Choose a reason for hiding this comment

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

Yes, of course.

Changing them into methods also loses the flexibility of macros, which can be put to anywhere you want without any context. However, it maybe worthy to speedup tests when failpoint are used heavily like TiKV.

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 think this is the same topic as #24. I guess, we can brainstorm that design and its implication there a bit more. From what I can see, it will be a major/invasive change anyway.

@brson
Copy link
Collaborator

brson commented Jun 17, 2019

Seem like after this we should finally bump to 0.3, and integrate this pattern into tikv per @luca's patch.

@brson
Copy link
Collaborator

brson commented Jun 17, 2019

The issue to bump to 0.3 is #31. I know I don't have the permissions to tag and publish. So probably @BusyJay or @overvenus will need to do that.

@lucab lucab force-pushed the ups/scenario branch 2 times, most recently from 153122c to 9ca990f Compare June 18, 2019 09:26
@lucab
Copy link
Member Author

lucab commented Jun 18, 2019

@brson I've updated the docs to fix the example, and explained the reason for keeping cfg as a free-function: #40 (comment).

@BusyJay after #32, the appveyor configuration should be removed. It is still triggering (and failing) on PRs. I think it is under your account.

@lucab
Copy link
Member Author

lucab commented Jun 20, 2019

Gentle bump.

Hoverbear
Hoverbear previously approved these changes Jun 25, 2019
@Hoverbear
Copy link
Contributor

Thanks for this Luca! :)

BusyJay
BusyJay previously approved these changes Jul 3, 2019
Copy link
Member

@BusyJay BusyJay left a comment

Choose a reason for hiding this comment

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

@brson would you like to give another look?

This adds a `FailScenario` to the library, exposing the usual idiom
of a global testing mutex and individual guards owned by each test.

The global mutex is kept as an internal detail and not exposed,
consumers can only borrow a guard via the scenario.
@lucab
Copy link
Member Author

lucab commented Jul 4, 2019

Rebased on latest master to get rid of appveyor hanging status.

(EDIT: that seems to have dropped the two LGTMs too, sorry)

@brson brson merged commit 3f3f8e1 into tikv:master Jul 9, 2019
@brson
Copy link
Collaborator

brson commented Jul 9, 2019

Thanks and sorry for the delay @lucab

@lucab
Copy link
Member Author

lucab commented Jul 9, 2019

@brson no prob. Actually, thanks for the reviews!

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.

Add the global failpoint lock pattern directly to the library
4 participants