Fix SearchableSnapshotDirectoryStatsTests (#58912)

Similar to #58847 but in a different tests. The failure never 
reproduced locally but occurs from time to time on CI.
This commit is contained in:
Tanguy Leroux 2020-07-02 16:38:05 +02:00
parent e32623ef52
commit 6aa669c8bb
1 changed files with 27 additions and 22 deletions

View File

@ -112,24 +112,27 @@ public class SearchableSnapshotDirectoryStatsTests extends ESIndexInputTestCase
final long cachedBytesWriteCount = TestUtils.numberOfRanges(length, rangeSize.getBytes()); final long cachedBytesWriteCount = TestUtils.numberOfRanges(length, rangeSize.getBytes());
assertThat(inputStats.getCachedBytesWritten(), notNullValue()); // cache writes are executed in a different thread pool and can take some time to be processed
assertThat(inputStats.getCachedBytesWritten().total(), equalTo(length)); assertBusy(() -> {
assertThat(inputStats.getCachedBytesWritten().count(), equalTo(cachedBytesWriteCount)); assertThat(inputStats.getCachedBytesWritten(), notNullValue());
assertThat(inputStats.getCachedBytesWritten().min(), greaterThan(0L)); assertThat(inputStats.getCachedBytesWritten().total(), equalTo(length));
assertThat( assertThat(inputStats.getCachedBytesWritten().count(), equalTo(cachedBytesWriteCount));
inputStats.getCachedBytesWritten().max(), assertThat(inputStats.getCachedBytesWritten().min(), greaterThan(0L));
(length < rangeSize.getBytes()) ? equalTo(length) : equalTo(rangeSize.getBytes()) assertThat(
); inputStats.getCachedBytesWritten().max(),
assertThat( (length < rangeSize.getBytes()) ? equalTo(length) : equalTo(rangeSize.getBytes())
inputStats.getCachedBytesWritten().totalNanoseconds(), );
allOf( assertThat(
// each read takes at least FAKE_CLOCK_ADVANCE_NANOS time inputStats.getCachedBytesWritten().totalNanoseconds(),
greaterThanOrEqualTo(FAKE_CLOCK_ADVANCE_NANOS * cachedBytesWriteCount), allOf(
// each read takes at least FAKE_CLOCK_ADVANCE_NANOS time
greaterThanOrEqualTo(FAKE_CLOCK_ADVANCE_NANOS * cachedBytesWriteCount),
// worst case: we start all reads before finishing any of them // worst case: we start all reads before finishing any of them
lessThanOrEqualTo(FAKE_CLOCK_ADVANCE_NANOS * cachedBytesWriteCount * cachedBytesWriteCount) lessThanOrEqualTo(FAKE_CLOCK_ADVANCE_NANOS * cachedBytesWriteCount * cachedBytesWriteCount)
) )
); );
});
assertThat(inputStats.getCachedBytesRead(), notNullValue()); assertThat(inputStats.getCachedBytesRead(), notNullValue());
assertThat(inputStats.getCachedBytesRead().total(), greaterThanOrEqualTo(length)); assertThat(inputStats.getCachedBytesRead().total(), greaterThanOrEqualTo(length));
@ -146,7 +149,7 @@ public class SearchableSnapshotDirectoryStatsTests extends ESIndexInputTestCase
assertCounter(inputStats.getOptimizedBytesRead(), 0L, 0L, 0L, 0L); assertCounter(inputStats.getOptimizedBytesRead(), 0L, 0L, 0L, 0L);
assertThat(inputStats.getOptimizedBytesRead().totalNanoseconds(), equalTo(0L)); assertThat(inputStats.getOptimizedBytesRead().totalNanoseconds(), equalTo(0L));
} catch (IOException e) { } catch (Exception e) {
throw new AssertionError(e); throw new AssertionError(e);
} }
}); });
@ -337,15 +340,17 @@ public class SearchableSnapshotDirectoryStatsTests extends ESIndexInputTestCase
} }
} }
// cache file has been written in a single chunk // cache file has been written in a single chunk in a different thread pool and can take some time to be processed
assertCounter(inputStats.getCachedBytesWritten(), input.length(), 1L, input.length(), input.length()); assertBusy(() -> {
assertThat(inputStats.getCachedBytesWritten().totalNanoseconds(), equalTo(FAKE_CLOCK_ADVANCE_NANOS)); assertCounter(inputStats.getCachedBytesWritten(), input.length(), 1L, input.length(), input.length());
assertThat(inputStats.getCachedBytesWritten().totalNanoseconds(), equalTo(FAKE_CLOCK_ADVANCE_NANOS));
});
assertCounter(inputStats.getNonContiguousReads(), 0L, 0L, 0L, 0L); assertCounter(inputStats.getNonContiguousReads(), 0L, 0L, 0L, 0L);
assertCounter(inputStats.getDirectBytesRead(), 0L, 0L, 0L, 0L); assertCounter(inputStats.getDirectBytesRead(), 0L, 0L, 0L, 0L);
assertThat(inputStats.getDirectBytesRead().totalNanoseconds(), equalTo(0L)); assertThat(inputStats.getDirectBytesRead().totalNanoseconds(), equalTo(0L));
} catch (IOException e) { } catch (Exception e) {
throw new AssertionError(e); throw new AssertionError(e);
} }
}); });