This is an automated email from the ASF dual-hosted git repository.

lgoldstein pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mina-sshd.git

commit 123140f2038bc8d00061126c6bce967e89bc210a
Author: Lyor Goldstein <[email protected]>
AuthorDate: Fri Aug 14 19:27:40 2020 +0300

    [SSHD-1020] Added a default NIO2-READ-TIMEOUT value for tests
---
 .../java/org/apache/sshd/KeyReExchangeTest.java    |  3 +-
 .../org/apache/sshd/util/test/BaseTestSupport.java | 33 ++++------------------
 .../sshd/util/test/CoreTestSupportUtils.java       | 30 ++++++++++++++++++++
 3 files changed, 37 insertions(+), 29 deletions(-)

diff --git a/sshd-core/src/test/java/org/apache/sshd/KeyReExchangeTest.java 
b/sshd-core/src/test/java/org/apache/sshd/KeyReExchangeTest.java
index 18bef92..2724a8e 100644
--- a/sshd-core/src/test/java/org/apache/sshd/KeyReExchangeTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/KeyReExchangeTest.java
@@ -62,6 +62,7 @@ import org.apache.sshd.server.channel.ChannelSession;
 import org.apache.sshd.server.command.Command;
 import org.apache.sshd.server.subsystem.SubsystemFactory;
 import org.apache.sshd.util.test.BaseTestSupport;
+import org.apache.sshd.util.test.CoreTestSupportUtils;
 import org.apache.sshd.util.test.JSchLogger;
 import org.apache.sshd.util.test.OutputCountTrackingOutputStream;
 import org.apache.sshd.util.test.SimpleUserInfo;
@@ -654,7 +655,7 @@ public class KeyReExchangeTest extends BaseTestSupport {
                     teeOut.write("exit\n".getBytes(StandardCharsets.UTF_8));
                     teeOut.flush();
 
-                    Duration timeout = getTimeout("KeyReExchangeTest", 
Duration.ofSeconds(15));
+                    Duration timeout = 
CoreTestSupportUtils.getTimeout("KeyReExchangeTest", Duration.ofSeconds(15));
 
                     Collection<ClientChannelEvent> result = 
channel.waitFor(EnumSet.of(ClientChannelEvent.CLOSED), timeout);
                     assertFalse("Timeout while waiting for channel closure", 
result.contains(ClientChannelEvent.TIMEOUT));
diff --git 
a/sshd-core/src/test/java/org/apache/sshd/util/test/BaseTestSupport.java 
b/sshd-core/src/test/java/org/apache/sshd/util/test/BaseTestSupport.java
index 69b2614..94765ef 100644
--- a/sshd-core/src/test/java/org/apache/sshd/util/test/BaseTestSupport.java
+++ b/sshd-core/src/test/java/org/apache/sshd/util/test/BaseTestSupport.java
@@ -45,11 +45,11 @@ public abstract class BaseTestSupport extends 
JUnitTestSupport {
     public static final String TEST_LOCALHOST
             = System.getProperty("org.apache.sshd.test.localhost", 
SshdSocketAddress.LOCALHOST_IPV4);
 
-    public static final Duration CONNECT_TIMEOUT = getTimeout("connect", 
Duration.ofSeconds(7));
-    public static final Duration AUTH_TIMEOUT = getTimeout("auth", 
Duration.ofSeconds(5));
-    public static final Duration OPEN_TIMEOUT = getTimeout("open", 
Duration.ofSeconds(9));
-    public static final Duration DEFAULT_TIMEOUT = getTimeout("default", 
Duration.ofSeconds(5));
-    public static final Duration CLOSE_TIMEOUT = getTimeout("close", 
Duration.ofSeconds(15));
+    public static final Duration CONNECT_TIMEOUT = 
CoreTestSupportUtils.getTimeout("connect", Duration.ofSeconds(7));
+    public static final Duration AUTH_TIMEOUT = 
CoreTestSupportUtils.getTimeout("auth", Duration.ofSeconds(5));
+    public static final Duration OPEN_TIMEOUT = 
CoreTestSupportUtils.getTimeout("open", Duration.ofSeconds(9));
+    public static final Duration DEFAULT_TIMEOUT = 
CoreTestSupportUtils.getTimeout("default", Duration.ofSeconds(5));
+    public static final Duration CLOSE_TIMEOUT = 
CoreTestSupportUtils.getTimeout("close", Duration.ofSeconds(15));
 
     @Rule
     public final TestWatcher rule = new TestWatcher() {
@@ -98,29 +98,6 @@ public abstract class BaseTestSupport extends 
JUnitTestSupport {
         logger.setLevel(level);
     }
 
-    public static Duration getTimeout(String property, Duration defaultValue) {
-        // Do we have a specific timeout value ?
-        String str = System.getProperty("org.apache.sshd.test.timeout." + 
property);
-        if (GenericUtils.isNotEmpty(str)) {
-            return Duration.ofMillis(Long.parseLong(str));
-        }
-
-        // Do we have a specific factor ?
-        str = System.getProperty("org.apache.sshd.test.timeout.factor." + 
property);
-        if (GenericUtils.isEmpty(str)) {
-            // Do we have a global factor ?
-            str = System.getProperty("org.apache.sshd.test.timeout.factor");
-        }
-
-        if (GenericUtils.isNotEmpty(str)) {
-            double factor = Double.parseDouble(str);
-            long dur = Math.round(defaultValue.toMillis() * factor);
-            return Duration.ofMillis(dur);
-        }
-
-        return defaultValue;
-    }
-
     protected SshServer setupTestServer() {
         return CoreTestSupportUtils.setupTestServer(getClass());
     }
diff --git 
a/sshd-core/src/test/java/org/apache/sshd/util/test/CoreTestSupportUtils.java 
b/sshd-core/src/test/java/org/apache/sshd/util/test/CoreTestSupportUtils.java
index 4ad8967..6e52784 100644
--- 
a/sshd-core/src/test/java/org/apache/sshd/util/test/CoreTestSupportUtils.java
+++ 
b/sshd-core/src/test/java/org/apache/sshd/util/test/CoreTestSupportUtils.java
@@ -21,6 +21,7 @@ package org.apache.sshd.util.test;
 import java.net.InetAddress;
 import java.net.InetSocketAddress;
 import java.net.ServerSocket;
+import java.time.Duration;
 import java.util.ArrayList;
 
 import org.apache.sshd.client.ClientBuilder;
@@ -32,12 +33,16 @@ import 
org.apache.sshd.common.helpers.AbstractFactoryManager;
 import org.apache.sshd.common.kex.BuiltinDHFactories;
 import org.apache.sshd.common.keyprovider.KeyIdentityProvider;
 import org.apache.sshd.common.signature.BuiltinSignatures;
+import org.apache.sshd.common.util.GenericUtils;
+import org.apache.sshd.core.CoreModuleProperties;
 import org.apache.sshd.server.ServerBuilder;
 import org.apache.sshd.server.SshServer;
 import org.apache.sshd.server.auth.pubkey.AcceptAllPublickeyAuthenticator;
 import org.apache.sshd.server.shell.UnknownCommandFactory;
 
 public final class CoreTestSupportUtils {
+    public static final Duration READ_TIMEOUT = getTimeout("read.nio2", 
Duration.ofSeconds(60));
+
     private CoreTestSupportUtils() {
         throw new UnsupportedOperationException("No instance");
     }
@@ -55,6 +60,7 @@ public final class CoreTestSupportUtils {
         client.setServerKeyVerifier(AcceptAllServerKeyVerifier.INSTANCE);
         client.setHostConfigEntryResolver(HostConfigEntryResolver.EMPTY);
         client.setKeyIdentityProvider(KeyIdentityProvider.EMPTY_KEYS_PROVIDER);
+        CoreModuleProperties.NIO2_READ_TIMEOUT.set(client, READ_TIMEOUT);
         return client;
     }
 
@@ -77,6 +83,7 @@ public final class CoreTestSupportUtils {
         
sshd.setPublickeyAuthenticator(AcceptAllPublickeyAuthenticator.INSTANCE);
         sshd.setShellFactory(EchoShellFactory.INSTANCE);
         sshd.setCommandFactory(UnknownCommandFactory.INSTANCE);
+        CoreModuleProperties.NIO2_READ_TIMEOUT.set(sshd, READ_TIMEOUT);
         return sshd;
     }
 
@@ -97,4 +104,27 @@ public final class CoreTestSupportUtils {
         manager.setSignatureFactories(new 
ArrayList<>(BuiltinSignatures.VALUES));
         return manager;
     }
+
+    public static Duration getTimeout(String property, Duration defaultValue) {
+        // Do we have a specific timeout value ?
+        String str = System.getProperty("org.apache.sshd.test.timeout." + 
property);
+        if (GenericUtils.isNotEmpty(str)) {
+            return Duration.ofMillis(Long.parseLong(str));
+        }
+
+        // Do we have a specific factor ?
+        str = System.getProperty("org.apache.sshd.test.timeout.factor." + 
property);
+        if (GenericUtils.isEmpty(str)) {
+            // Do we have a global factor ?
+            str = System.getProperty("org.apache.sshd.test.timeout.factor");
+        }
+
+        if (GenericUtils.isNotEmpty(str)) {
+            double factor = Double.parseDouble(str);
+            long dur = Math.round(defaultValue.toMillis() * factor);
+            return Duration.ofMillis(dur);
+        }
+
+        return defaultValue;
+    }
 }

Reply via email to