-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2816 from krmahadevan/fix_2798
Unexpected test runs count with retry analyzer
- Loading branch information
Showing
5 changed files
with
65 additions
and
18 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
20 changes: 20 additions & 0 deletions
20
testng-core/src/test/java/test/retryAnalyzer/issue2798/HashCodeAwareRetryAnalyzer.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,20 @@ | ||
package test.retryAnalyzer.issue2798; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.testng.IRetryAnalyzer; | ||
import org.testng.ITestResult; | ||
|
||
public class HashCodeAwareRetryAnalyzer implements IRetryAnalyzer { | ||
|
||
public static final List<Integer> hashCodes = new ArrayList<>(); | ||
|
||
int cnt = 0; | ||
static final int threshold = 2; | ||
|
||
@Override | ||
public synchronized boolean retry(ITestResult result) { | ||
hashCodes.add(this.hashCode()); | ||
return cnt++ < threshold; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
testng-core/src/test/java/test/retryAnalyzer/issue2798/TestClassSample.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,21 @@ | ||
package test.retryAnalyzer.issue2798; | ||
|
||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
import java.util.Arrays; | ||
import java.util.Iterator; | ||
import org.testng.annotations.DataProvider; | ||
import org.testng.annotations.Test; | ||
|
||
public class TestClassSample { | ||
|
||
@DataProvider(name = "test data", parallel = true) | ||
public Iterator<Object[]> data() { | ||
return Arrays.asList(new Object[] {"1"}, new Object[] {"2"}).iterator(); | ||
} | ||
|
||
@Test(dataProvider = "test data", retryAnalyzer = HashCodeAwareRetryAnalyzer.class) | ||
public void foo(String ignored) throws IOException { | ||
throw new FileNotFoundException("this can be retried"); | ||
} | ||
} |