tomaswolf commented on code in PR #242:
URL: https://github.com/apache/mina-sshd/pull/242#discussion_r967621421


##########
sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java:
##########
@@ -1530,6 +1532,29 @@ public void testConnectUsingIPv6Address() throws 
IOException {
         }
     }
 
+    @Test // see SSHD-1295
+    public void testConnectTimeout() throws Exception {
+        client.start();
+        try {
+            ConnectFuture future = client.connect(getCurrentTestName(), 
TEST_LOCALHOST, port);
+            try {
+                future.verify(1);
+                fail("Timeout expected");
+            } catch (InterruptedIOException | SshException e) {
+                ClientSession session = null;
+                try {
+                    session = future.verify(CONNECT_TIMEOUT).getSession();
+                } catch (SshException e2) {
+                    assertTrue("Expected a timeout, got " + e2, 
e2.getMessage().contains("timeout"));
+                }
+
+                assertNull("Session should not set since client timeout", 
session);

Review Comment:
   Add before line 1537
   ```
           List<Session> sessions = new CopyOnWriteArrayList<>();
           client.addSessionListener(new SessionListener() {
   
               @Override
               public void sessionCreated(Session session) {
                   // Delay a little bit to ensure that verify(1) does time out 
below
                   try {
                       Thread.sleep(100);
                   } catch (InterruptedException e) {
                       Thread.currentThread().interrupt();
                   }
                   sessions.add(session);
               }
           });
   ```
   and then after line 1551
   ```
                   for (Session created : sessions) {
                       assertTrue("Created session should be closed", 
created.isClosed() || created.isClosing());
                   }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to