Retry which measures duration a few times to see if that reduces the number of failures caused by this test sometimes when CI machines are loaded.

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1707488 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2015-10-08 11:08:41 +00:00
parent 710aa84544
commit 5735e23853
1 changed files with 23 additions and 8 deletions

View File

@ -30,19 +30,34 @@ public class TestXSSFSheetMergeRegions {
public void testMergeRegionsSpeed() throws IOException {
final XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("57893-many-merges.xlsx");
try {
final XSSFSheet sheet = wb.getSheetAt(0);
final long start = System.currentTimeMillis();
final List<CellRangeAddress> mergedRegions = sheet.getMergedRegions();
assertEquals(50000, mergedRegions.size());
for (CellRangeAddress cellRangeAddress : mergedRegions) {
assertEquals(cellRangeAddress.getFirstRow(), cellRangeAddress.getLastRow());
assertEquals(2, cellRangeAddress.getNumberOfCells());
long millis = Long.MAX_VALUE;
// in order to reduce the number of false positives we run it a few times before we fail,
// sometimes it fails on machines that are busy at the moment.
for(int i = 0;i < 5;i++) {
millis = runTest(wb);
if(millis < 2000) {
break;
}
System.out.println("Retry " + i + " because run-time is too high: " + millis);
}
long millis = System.currentTimeMillis() - start;
// This time is typically ~800ms, versus ~7800ms to iterate getMergedRegion(int).
assertTrue("Should have taken <2000 ms to iterate 50k merged regions but took " + millis, millis < 2000);
} finally {
wb.close();
}
}
private long runTest(final XSSFWorkbook wb) {
final long start = System.currentTimeMillis();
final XSSFSheet sheet = wb.getSheetAt(0);
final List<CellRangeAddress> mergedRegions = sheet.getMergedRegions();
assertEquals(50000, mergedRegions.size());
for (CellRangeAddress cellRangeAddress : mergedRegions) {
assertEquals(cellRangeAddress.getFirstRow(), cellRangeAddress.getLastRow());
assertEquals(2, cellRangeAddress.getNumberOfCells());
}
return System.currentTimeMillis() - start;
}
}