Skip to content

Commit

Permalink
Fix SearchableSnapshotDirectoryStatsTests (#58912)
Browse files Browse the repository at this point in the history
Similar to #58847 but in a different tests. The failure never 
reproduced locally but occurs from time to time on CI.
  • Loading branch information
tlrx committed Jul 2, 2020
1 parent 5783b63 commit a6347a8
Showing 1 changed file with 28 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,24 +112,27 @@ public void testCachedBytesReadsAndWrites() {

final long cachedBytesWriteCount = TestUtils.numberOfRanges(length, rangeSize.getBytes());

assertThat(inputStats.getCachedBytesWritten(), notNullValue());
assertThat(inputStats.getCachedBytesWritten().total(), equalTo(length));
assertThat(inputStats.getCachedBytesWritten().count(), equalTo(cachedBytesWriteCount));
assertThat(inputStats.getCachedBytesWritten().min(), greaterThan(0L));
assertThat(
inputStats.getCachedBytesWritten().max(),
(length < rangeSize.getBytes()) ? equalTo(length) : equalTo(rangeSize.getBytes())
);
assertThat(
inputStats.getCachedBytesWritten().totalNanoseconds(),
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
lessThanOrEqualTo(FAKE_CLOCK_ADVANCE_NANOS * cachedBytesWriteCount * cachedBytesWriteCount)
)
);
// cache writes are executed in a different thread pool and can take some time to be processed
assertBusy(() -> {
assertThat(inputStats.getCachedBytesWritten(), notNullValue());
assertThat(inputStats.getCachedBytesWritten().total(), equalTo(length));
assertThat(inputStats.getCachedBytesWritten().count(), equalTo(cachedBytesWriteCount));
assertThat(inputStats.getCachedBytesWritten().min(), greaterThan(0L));
assertThat(
inputStats.getCachedBytesWritten().max(),
(length < rangeSize.getBytes()) ? equalTo(length) : equalTo(rangeSize.getBytes())
);
assertThat(
inputStats.getCachedBytesWritten().totalNanoseconds(),
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
lessThanOrEqualTo(FAKE_CLOCK_ADVANCE_NANOS * cachedBytesWriteCount * cachedBytesWriteCount)
)
);
});

assertThat(inputStats.getCachedBytesRead(), notNullValue());
assertThat(inputStats.getCachedBytesRead().total(), greaterThanOrEqualTo(length));
Expand All @@ -146,7 +149,7 @@ public void testCachedBytesReadsAndWrites() {
assertCounter(inputStats.getOptimizedBytesRead(), 0L, 0L, 0L, 0L);
assertThat(inputStats.getOptimizedBytesRead().totalNanoseconds(), equalTo(0L));

} catch (IOException e) {
} catch (Exception e) {
throw new AssertionError(e);
}
});
Expand Down Expand Up @@ -337,15 +340,17 @@ public void testReadBytesContiguously() {
}
}

// cache file has been written in a single chunk
assertCounter(inputStats.getCachedBytesWritten(), input.length(), 1L, input.length(), input.length());
assertThat(inputStats.getCachedBytesWritten().totalNanoseconds(), equalTo(FAKE_CLOCK_ADVANCE_NANOS));
// cache file has been written in a single chunk in a different thread pool and can take some time to be processed
assertBusy(() -> {
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.getDirectBytesRead(), 0L, 0L, 0L, 0L);
assertThat(inputStats.getDirectBytesRead().totalNanoseconds(), equalTo(0L));

} catch (IOException e) {
} catch (Exception e) {
throw new AssertionError(e);
}
});
Expand Down

0 comments on commit a6347a8

Please sign in to comment.