-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix flaky test SlowIntegrationTests.testDelayInSecurityIndexInitializ…
…ation (#3763) Signed-off-by: Craig Perkins <[email protected]>
- Loading branch information
Showing
5 changed files
with
144 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
package org.opensearch.security.util; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import static java.lang.annotation.ElementType.ANNOTATION_TYPE; | ||
import static java.lang.annotation.ElementType.METHOD; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ METHOD, ANNOTATION_TYPE }) | ||
public @interface Repeat { | ||
int value() default 1; | ||
} |
48 changes: 48 additions & 0 deletions
48
src/test/java/org/opensearch/security/util/RepeatRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
package org.opensearch.security.util; | ||
|
||
import org.junit.rules.TestRule; | ||
import org.junit.runner.Description; | ||
import org.junit.runners.model.Statement; | ||
|
||
public class RepeatRule implements TestRule { | ||
|
||
private static class RepeatStatement extends Statement { | ||
private final Statement statement; | ||
private final int repeat; | ||
|
||
public RepeatStatement(Statement statement, int repeat) { | ||
this.statement = statement; | ||
this.repeat = repeat; | ||
} | ||
|
||
@Override | ||
public void evaluate() throws Throwable { | ||
for (int i = 0; i < repeat; i++) { | ||
statement.evaluate(); | ||
} | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public Statement apply(Statement statement, Description description) { | ||
Statement result = statement; | ||
Repeat repeat = description.getAnnotation(Repeat.class); | ||
if (repeat != null) { | ||
int times = repeat.value(); | ||
result = new RepeatStatement(statement, times); | ||
} | ||
return result; | ||
} | ||
} |