-
Notifications
You must be signed in to change notification settings - Fork 674
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
SOLR-16696: Breakpoint injection for testing with CommonTestInjection #1457
SOLR-16696: Breakpoint injection for testing with CommonTestInjection #1457
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks really useful -- indeed basically required in order to specifically target certain kinds of race/deadlock issues. Basically identical in spirit to injectDelay()
, but more nuanced and reliable.
I left one minor suggestion, but aside from that, I'm wondering if it might be better to introduce this along with the PR that presumably motivated its addition? I think on usefulness it stands in its own right, but it might be clearer in terms of commit history to bundle this as incorporated with a concrete use case.
if (breakpoint != null) { | ||
breakpoint.executeAndResume(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should add logging here, analogous to what's found in injectDelay()
? The concept is similar, and we have a ready-made "key" to use in the log message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added with commit 53ee6f8
Would you mind to review #1460 ? :) that PR actually contains this breakpoint change too and uses it. I have added extra logging when breakpoint is triggered to that branch instead |
6c4590f
to
9183232
Compare
Added logging message on breakpoint trigger
9183232
to
53ee6f8
Compare
Closing this as the same change is introduced in #1460 |
https://issues.apache.org/jira/browse/SOLR-16696
Description
Proposing a new
Breakpoint
feature inCommonTestInjection
which acts similar to breakpoints in IDE.This allows blocking/checking conditions at the injection point, which could be useful for race condition emulation and exception verification.
Solution
Added a new interface
CommonTestInjection$Breakpoint
, with a single methodexecuteAndResume
. 2 new methods are introduced inCommonTestInjection
.injectBreakpoint(breakpointKey)
should be added in the actual code flow guarded byassert
, for exampleassert injectBreakpoint(MyClass.getClass().getName())
.assert
will make sure the breakpoint logic would only be evaluated during testing.The actual breakpoint is set by test cases as
setBreakpoint(breakpointKey, breakpointImpl)
, the breakpoint implementation would implementexecuteAndResume
method. Example usages:Race condition
In the
RaceClass
instance:in unit test case:
Caught exception verification
In the target class:
In unit test case:
Tests
No extra tests are added.
Checklist
Please review the following and check all that apply:
main
branch../gradlew check
.