Skip to content

Commit b7be8c8

Browse files
committed
Add attemptJava5516 - a non-deterministic reproducer
JAVA-5516
1 parent 88b4218 commit b7be8c8

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

driver-core/src/test/functional/com/mongodb/internal/operation/AsyncCommandBatchCursorFunctionalTest.java

+19
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import java.util.ArrayList;
4646
import java.util.List;
4747
import java.util.concurrent.CountDownLatch;
48+
import java.util.concurrent.ForkJoinPool;
4849
import java.util.concurrent.TimeUnit;
4950
import java.util.concurrent.atomic.AtomicInteger;
5051
import java.util.stream.Collectors;
@@ -299,6 +300,24 @@ void testLimitWithGetMore() {
299300
assertTrue(cursor.isClosed());
300301
}
301302

303+
@Test
304+
void attemptJava5516() {
305+
BsonDocument commandResult = executeFindCommand(5, 2);
306+
cursor = new AsyncCommandBatchCursor<>(commandResult, 2, 0, DOCUMENT_DECODER,
307+
null, connectionSource, connection);
308+
assertNotNull(cursorNext());
309+
// Calling `close` twice is the key to reproducing.
310+
// It does not matter whether we call `close` twice from the same thread or not.
311+
ForkJoinPool.commonPool().execute(() -> cursor.close());
312+
ForkJoinPool.commonPool().execute(() -> cursor.close());
313+
try {
314+
assertNotNull(cursorNext());
315+
assertNotNull(cursorNext());
316+
} catch (IllegalStateException e) {
317+
// one of the expected outcomes, because we call `cursorNext` concurrently with `close`
318+
}
319+
}
320+
302321
@Test
303322
@DisplayName("test limit with large documents")
304323
void testLimitWithLargeDocuments() {

0 commit comments

Comments
 (0)