From b7be8c856f8e500dcc10ca39757c8dccf33769c3 Mon Sep 17 00:00:00 2001 From: Valentin Kovalenko Date: Mon, 8 Jul 2024 18:00:46 -0600 Subject: [PATCH] Add `attemptJava5516` - a non-deterministic reproducer JAVA-5516 --- ...AsyncCommandBatchCursorFunctionalTest.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/driver-core/src/test/functional/com/mongodb/internal/operation/AsyncCommandBatchCursorFunctionalTest.java b/driver-core/src/test/functional/com/mongodb/internal/operation/AsyncCommandBatchCursorFunctionalTest.java index 3b8addf6596..147d0e268bd 100644 --- a/driver-core/src/test/functional/com/mongodb/internal/operation/AsyncCommandBatchCursorFunctionalTest.java +++ b/driver-core/src/test/functional/com/mongodb/internal/operation/AsyncCommandBatchCursorFunctionalTest.java @@ -45,6 +45,7 @@ import java.util.ArrayList; import java.util.List; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ForkJoinPool; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; @@ -299,6 +300,24 @@ void testLimitWithGetMore() { assertTrue(cursor.isClosed()); } + @Test + void attemptJava5516() { + BsonDocument commandResult = executeFindCommand(5, 2); + cursor = new AsyncCommandBatchCursor<>(commandResult, 2, 0, DOCUMENT_DECODER, + null, connectionSource, connection); + assertNotNull(cursorNext()); + // Calling `close` twice is the key to reproducing. + // It does not matter whether we call `close` twice from the same thread or not. + ForkJoinPool.commonPool().execute(() -> cursor.close()); + ForkJoinPool.commonPool().execute(() -> cursor.close()); + try { + assertNotNull(cursorNext()); + assertNotNull(cursorNext()); + } catch (IllegalStateException e) { + // one of the expected outcomes, because we call `cursorNext` concurrently with `close` + } + } + @Test @DisplayName("test limit with large documents") void testLimitWithLargeDocuments() {