From 7fbf591db57aae418cc8ec82410d7e14626344a5 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Thu, 8 Oct 2015 11:08:41 +0000 Subject: [PATCH] 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 --- .../usermodel/TestXSSFSheetMergeRegions.java | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetMergeRegions.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetMergeRegions.java index 416c6217b..88530dc03 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetMergeRegions.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetMergeRegions.java @@ -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 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 mergedRegions = sheet.getMergedRegions(); + assertEquals(50000, mergedRegions.size()); + for (CellRangeAddress cellRangeAddress : mergedRegions) { + assertEquals(cellRangeAddress.getFirstRow(), cellRangeAddress.getLastRow()); + assertEquals(2, cellRangeAddress.getNumberOfCells()); + } + return System.currentTimeMillis() - start; + } }