Skip to content

Commit

Permalink
Fix IllegalState Attempting to use a Ccm error (#338)
Browse files Browse the repository at this point in the history
If rule throw an exception on `before` it's `after` is not being
executed.
It needs to be respected in CustomCcmRule.
  • Loading branch information
dkropachev authored Sep 6, 2024
1 parent fe5d469 commit 4200ef8
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,15 @@ public class CustomCcmRule extends BaseCcmRule {
@Override
protected void before() {
if (CURRENT.get() == null && CURRENT.compareAndSet(null, this)) {
super.before();
try {
super.before();
} catch (Exception e) {
// If exception is thrown in this rule, `after` is not going to be executed and test suit is
// going to become broken
// So we need to drop CURRENT to let other tests run
CURRENT.set(null);
throw e;
}
} else if (CURRENT.get() != this) {
throw new IllegalStateException(
"Attempting to use a Ccm rule while another is in use. This is disallowed");
Expand All @@ -48,8 +56,11 @@ protected void before() {

@Override
protected void after() {
super.after();
CURRENT.compareAndSet(this, null);
try {
super.after();
} finally {
CURRENT.compareAndSet(this, null);
}
}

public CcmBridge getCcmBridge() {
Expand Down

0 comments on commit 4200ef8

Please sign in to comment.