Repository: james-project Updated Branches: refs/heads/master 4ecc8ba76 -> db703cd06
JAMES-1897 Ensure that client is really disconnected in SMTP tests Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/db703cd0 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/db703cd0 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/db703cd0 Branch: refs/heads/master Commit: db703cd06ca055ca924d7243a2527b5bcc6d75d1 Parents: 4ecc8ba Author: Antoine Duprat <adup...@linagora.com> Authored: Thu Dec 22 14:52:08 2016 +0100 Committer: Antoine Duprat <adup...@linagora.com> Committed: Thu Dec 22 16:47:11 2016 +0100 ---------------------------------------------------------------------- .../apache/james/smtpserver/SMTPServerTest.java | 22 ++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/db703cd0/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java b/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java index b212af3..8faca0f 100644 --- a/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java +++ b/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java @@ -165,6 +165,8 @@ public class SMTPServerTest { } } + private static final long HALF_SECOND = 500; + private static final int MAX_ITERATIONS = 10; private static final Logger log = LoggerFactory.getLogger(SMTPServerTest.class.getName()); protected SMTPTestConfiguration smtpConfiguration; @@ -369,16 +371,28 @@ public class SMTPServerTest { } catch (Exception e) { } - smtpProtocol.quit(); - smtpProtocol.disconnect(); - smtpProtocol2.quit(); - smtpProtocol2.disconnect(); + ensureIsDisconnected(smtpProtocol); + ensureIsDisconnected(smtpProtocol2); smtpProtocol3.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); Thread.sleep(3000); } + private void ensureIsDisconnected(SMTPClient client) throws IOException, InterruptedException { + int initialConnections = smtpServer.getCurrentConnections(); + client.quit(); + client.disconnect(); + assertIsDisconnected(initialConnections); + } + + private void assertIsDisconnected(int initialConnections) throws InterruptedException { + int iterations = 0; + while (smtpServer.getCurrentConnections() >= initialConnections && iterations++ < MAX_ITERATIONS) { + Thread.sleep(HALF_SECOND); + } + } + @After public void tearDown() throws Exception { queue.clear(); --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org