From e6ee21e18eb21def12041dcbb73dcfd536e30690 Mon Sep 17 00:00:00 2001 From: Benoit TELLIER Date: Sun, 23 Aug 2026 11:25:15 +0700 Subject: [PATCH] [BUILD] IMAPServerIDCommandTest::concurrentIdCommandsInTheSameSessionShouldSucceed was instable --- .../netty/IMAPServerIDCommandTest.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/server/protocols/protocols-imap4/src/test/java/org/apache/james/imapserver/netty/IMAPServerIDCommandTest.java b/server/protocols/protocols-imap4/src/test/java/org/apache/james/imapserver/netty/IMAPServerIDCommandTest.java index a26b53c7efe..8fb6bbdbd31 100644 --- a/server/protocols/protocols-imap4/src/test/java/org/apache/james/imapserver/netty/IMAPServerIDCommandTest.java +++ b/server/protocols/protocols-imap4/src/test/java/org/apache/james/imapserver/netty/IMAPServerIDCommandTest.java @@ -24,6 +24,7 @@ import java.time.Duration; import org.apache.james.util.concurrency.ConcurrentTestRunner; +import org.apache.james.utils.TestIMAPClient; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; @@ -61,15 +62,21 @@ void idCommandShouldReturnConfiguredResponse() throws Exception { } @Test - void concurrentIdCommandsInTheSameSessionShouldSucceed() throws Exception { + void concurrentIdCommandsShouldSucceed() throws Exception { imapServer = createImapServer("imapServer.xml"); + int port = imapServer.getListenAddresses().getFirst().getPort(); - testIMAPClient.connect("127.0.0.1", imapServer.getListenAddresses().getFirst().getPort()); + // One client per thread: a single TestIMAPClient wraps one socket and one + // reader, so sharing it across threads interleaves the replies and a thread + // can read an empty string that belongs to nobody. ConcurrentTestRunner.builder() .operation((threadNumber, step) -> { - assertThat(testIMAPClient.sendCommand("ID (\"name\" \"Apache James\")")) - .contains("* ID NIL") - .contains("OK ID completed."); + try (TestIMAPClient client = new TestIMAPClient()) { + client.connect("127.0.0.1", port); + assertThat(client.sendCommand("ID (\"name\" \"Apache James\")")) + .contains("* ID NIL") + .contains("OK ID completed."); + } }) .threadCount(20) .operationCount(1)