You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by lg...@apache.org on 2020/04/08 08:04:49 UTC

[mina-sshd] 14/15: Added capability to control specific test duration timeout factor via system property

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 8d072ec660b52c022569ea50cbd6b59953261ca0
Author: Lyor Goldstein <lg...@apache.org>
AuthorDate: Wed Apr 8 09:17:50 2020 +0300

    Added capability to control specific test duration timeout factor via system property
---
 .../org/apache/sshd/util/test/BaseTestSupport.java | 33 +++++++++++++---------
 1 file changed, 19 insertions(+), 14 deletions(-)

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 3fabf96..d7a4be0 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
@@ -98,22 +98,27 @@ public abstract class BaseTestSupport extends JUnitTestSupport {
         logger.setLevel(level);
     }
 
-    public static Duration getTimeout(String property, Duration def) {
-        long dur;
+    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 (str == null) {
-            String fstr = System.getProperty("org.apache.sshd.test.timeout.factor");
-            double factor;
-            if (fstr != null) {
-                factor = Double.parseDouble(fstr);
-            } else {
-                factor = 1.0;
-            }
-            dur = (long) (def.toMillis() * factor);
-        } else {
-            dur = Long.parseLong(str);
+        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");
         }
-        return Duration.ofMillis(dur);
+
+        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() {