Fix a flaky test, it seems if the document is not closed, the automatic

closing of file-handles interferes with subsequent tests, by closing the
document this flakiness seems to be gone.

Flakiness could be reproduced locally by continuously running test with IntelliJ
"run until failure" run-config option and after aprox. 17,000 test-executions!

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1857068 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2019-04-07 07:17:47 +00:00
parent b88c6b12e5
commit 6119c0ecec

View File

@ -49,7 +49,7 @@ public class TestBug47563 {
data.add(new Object[] {6, 1});
data.add(new Object[] {2, 2});
data.add(new Object[] {3, 2});
data.add(new Object[] {2, 3});
data.add(new Object[] {2, 3}); //
data.add(new Object[] {3, 3});
return data;
@ -62,8 +62,7 @@ public class TestBug47563 {
// POI apparently can't create a document from scratch,
// so we need an existing empty dummy document
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("empty.doc");
try (HWPFDocument doc = HWPFTestDataSamples.openSampleFile("empty.doc")) {
Range range = doc.getRange();
range.sanityCheck();
@ -98,10 +97,12 @@ public class TestBug47563 {
int mustBeAfter = 0;
for (int i = 0; i < rows * columns; i++) {
int next = text.indexOf(Integer.toString(i), mustBeAfter);
assertTrue("Test with " + rows + "/" + columns + ": Should not find " + i + " but found it at " + next + " with " + mustBeAfter + " in " + text + "\n" +
assertTrue("Test with " + rows + "/" + columns + ": Should not find " + i +
" but found it at " + next + " with " + mustBeAfter + " in " + text + "\n" +
text.indexOf(Integer.toString(i), mustBeAfter),
next != -1);
mustBeAfter = next;
}
}
}
}