Skip to content

Commit f71a1f9

Browse files
committed
Loosen the guarantees of this test
This test hits the race condition described in `onClose` a little less than once in a thousand runs on my machine, so we can't check for the same level of strict internal consistency between the two data structures (it's possible for the cache to contain a bitset that isn't referenced by the keysByIndex structure, and that's okay).
1 parent a8ffa25 commit f71a1f9

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authz/accesscontrol/DocumentSubsetBitsetCacheTests.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -314,12 +314,12 @@ public void testCacheUnderConcurrentAccess() throws Exception {
314314
.put(DocumentSubsetBitsetCache.CACHE_SIZE_SETTING.getKey(), maxCacheBytes + "b")
315315
.build();
316316

317+
final DocumentSubsetBitsetCache cache = new DocumentSubsetBitsetCache(settings);
318+
assertThat(cache.entryCount(), equalTo(0));
319+
assertThat(cache.ramBytesUsed(), equalTo(0L));
320+
317321
final ExecutorService threads = Executors.newFixedThreadPool(concurrentThreads + 1);
318322
try {
319-
final DocumentSubsetBitsetCache cache = new DocumentSubsetBitsetCache(settings);
320-
assertThat(cache.entryCount(), equalTo(0));
321-
assertThat(cache.ramBytesUsed(), equalTo(0L));
322-
323323
runTestOnIndices(numberOfIndices, contexts -> {
324324
final CountDownLatch start = new CountDownLatch(concurrentThreads);
325325
final CountDownLatch end = new CountDownLatch(concurrentThreads);
@@ -360,7 +360,7 @@ public void testCacheUnderConcurrentAccess() throws Exception {
360360

361361
threads.shutdown();
362362
assertTrue("Cleanup thread did not complete in expected time", threads.awaitTermination(3, TimeUnit.SECONDS));
363-
cache.verifyInternalConsistency();
363+
cache.verifyInternalConsistencyKeysToCache();
364364

365365
// Due to cache evictions, we must get more bitsets than fields
366366
assertThat(uniqueBitSets.size(), greaterThan(FIELD_COUNT));
@@ -373,6 +373,8 @@ public void testCacheUnderConcurrentAccess() throws Exception {
373373
} finally {
374374
threads.shutdown();
375375
}
376+
377+
cache.verifyInternalConsistencyKeysToCache();
376378
}
377379

378380
@AwaitsFix(bugUrl = "todo")

0 commit comments

Comments
 (0)