Skip to content

Commit

Permalink
Fix test ChainingInputStreamTests.testResetForDoubleMarkAnywhere
Browse files Browse the repository at this point in the history
Test should call verify with times param when randomisation stars allign

Closes elastic#67086
  • Loading branch information
albertzaharovits committed Jan 11, 2021
1 parent e3d3ecd commit a27da48
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,6 @@ InputStream nextComponent(InputStream currentComponentIn) throws IOException {
readAllBytes(test);
}

@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/67086")
public void testResetForDoubleMarkAnywhere() throws Exception {
Supplier<InputStream> mockInputStreamSupplier = () -> {
InputStream mockIn = mock(InputStream.class);
Expand Down Expand Up @@ -938,14 +937,18 @@ InputStream nextComponent(InputStream currentComponentIn) throws IOException {
}
InputStream lastCurrentIn = test.currentIn;
// second mark
readLimit = randomInt(63);
test.mark(readLimit);
int readLimit2 = randomInt(63);
test.mark(readLimit2);
if (lastCurrentIn != currentIn) {
verify(currentIn).close();
}
assertThat(test.currentIn, Matchers.is(lastCurrentIn));
assertThat(test.markIn, Matchers.is(lastCurrentIn));
verify(lastCurrentIn).mark(Mockito.eq(readLimit));
if (currentIn == lastCurrentIn && readLimit == readLimit2) {
verify(lastCurrentIn, times(2)).mark(Mockito.eq(readLimit));
} else {
verify(lastCurrentIn).mark(Mockito.eq(readLimit2));
}
currentIn = lastCurrentIn;
// possibly skips over several components
for (int i = 0; i < randomIntBetween(1, 2); i++) {
Expand All @@ -968,14 +971,14 @@ InputStream nextComponent(InputStream currentComponentIn) throws IOException {
}
lastCurrentIn = test.currentIn;
// third mark after reset
readLimit = randomInt(63);
test.mark(readLimit);
int readLimit3 = 128 + randomInt(63); // it is harder to assert the cases with the same readLimit
test.mark(readLimit3);
if (lastCurrentIn != currentIn) {
verify(currentIn).close();
}
assertThat(test.currentIn, Matchers.is(lastCurrentIn));
assertThat(test.markIn, Matchers.is(lastCurrentIn));
verify(lastCurrentIn).mark(Mockito.eq(readLimit));
verify(lastCurrentIn).mark(Mockito.eq(readLimit3));
nextComponentArg.set(lastCurrentIn);
currentIn = lastCurrentIn;
// possibly skips over several components
Expand Down

0 comments on commit a27da48

Please sign in to comment.