commit e8afa71: [Test] Various robot fixes

Vsevolod Stakhov vsevolod at highsecure.ru
Fri Jul 19 17:42:04 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-07-19 18:26:03 +0100
URL: https://github.com/rspamd/rspamd/commit/e8afa71d30815ed997ee7b5bafc5067bea7a94c1

[Test] Various robot fixes

---
 test/functional/cases/330_neural.robot    |  2 +-
 test/functional/configs/redis-server.conf |  2 ++
 test/functional/lib/rspamd.py             | 23 +++++++++++++++++++++++
 test/functional/lib/rspamd.robot          | 14 ++++++--------
 4 files changed, 32 insertions(+), 9 deletions(-)

diff --git a/test/functional/cases/330_neural.robot b/test/functional/cases/330_neural.robot
index 67c8c0373..e08a36145 100644
--- a/test/functional/cases/330_neural.robot
+++ b/test/functional/cases/330_neural.robot
@@ -66,5 +66,5 @@ Neural Setup
   Run Redis
 
 Neural Teardown
-  Normal Teardown
   Shutdown Process With Children  ${REDIS_PID}
+  Normal Teardown
diff --git a/test/functional/configs/redis-server.conf b/test/functional/configs/redis-server.conf
index e44f8ab02..0636a36ef 100644
--- a/test/functional/configs/redis-server.conf
+++ b/test/functional/configs/redis-server.conf
@@ -1,5 +1,7 @@
 bind ${REDIS_ADDR}
 daemonize yes
+loglevel debug
 logfile ${TMPDIR}/redis.log
 pidfile ${TMPDIR}/redis.pid
 port ${REDIS_PORT}
+dir ${TMPDIR}
diff --git a/test/functional/lib/rspamd.py b/test/functional/lib/rspamd.py
index 928414868..295484f9e 100644
--- a/test/functional/lib/rspamd.py
+++ b/test/functional/lib/rspamd.py
@@ -27,6 +27,7 @@ except:
 
 def Check_JSON(j):
     d = json.loads(j, strict=True)
+    logger.debug('got json %s' % d)
     assert len(d) > 0
     assert 'error' not in d
     return d
@@ -38,6 +39,8 @@ def save_run_results(directory, filenames):
     current_directory = os.getcwd()
     suite_name = BuiltIn().get_variable_value("${SUITE_NAME}")
     test_name = BuiltIn().get_variable_value("${TEST NAME}")
+    onlyfiles = [f for f in os.listdir(directory) if os.path.isfile(os.path.join(directory, f))]
+    logger.debug('%s content before cleanup: %s' % (directory, onlyfiles))
     if test_name is None:
         # this is suite-level tear down
         destination_directory = "%s/robot-save/%s" % (current_directory, suite_name)
@@ -47,7 +50,9 @@ def save_run_results(directory, filenames):
         os.makedirs(destination_directory)
     for file in filenames.split(' '):
         source_file = "%s/%s" % (directory, file)
+        logger.debug('check if we can save %s' % source_file)
         if os.path.isfile(source_file):
+            logger.debug('found %s, save it' % file)
             shutil.copy(source_file, "%s/%s" % (destination_directory, file))
             shutil.copy(source_file, "%s/robot-save/%s.last" % (current_directory, file))
 
@@ -183,6 +188,24 @@ def TCP_Connect(addr, port):
     s.connect((addr, port))
     s.close()
 
+def ping_rspamd(addr, port):
+    return str(urlopen("http://%s:%s/ping" % (addr, port)).read())
+
+def redis_check(addr, port):
+    """Attempts to open a TCP connection to specified address:port
+
+    Example:
+    | Wait Until Keyword Succeeds | 5s | 10ms | TCP Connect | localhost | 8080 |
+    """
+    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+    s.settimeout(1.0) # seconds
+    s.connect((addr, port))
+    if s.sendall(b"ECHO TEST\n"):
+        result = s.recv(128)
+        return result == b'TEST\n'
+    else:
+        return False
+
 def update_dictionary(a, b):
     a.update(b)
     return a
diff --git a/test/functional/lib/rspamd.robot b/test/functional/lib/rspamd.robot
index 01e85a8b3..10e8a0178 100644
--- a/test/functional/lib/rspamd.robot
+++ b/test/functional/lib/rspamd.robot
@@ -110,9 +110,6 @@ Redis SET
   Should Be Equal As Integers  ${result.rc}  0
 
 Run Redis
-  ${has_TMPDIR} =  Evaluate  'TMPDIR'
-  ${tmpdir} =  Run Keyword If  '${has_TMPDIR}' == 'True'  Set Variable  &{kwargs}[TMPDIR]
-  ...  ELSE  Make Temporary Directory
   ${template} =  Get File  ${TESTDIR}/configs/redis-server.conf
   ${config} =  Replace Variables  ${template}
   Create File  ${TMPDIR}/redis-server.conf  ${config}
@@ -120,8 +117,8 @@ Run Redis
   ${result} =  Run Process  redis-server  ${TMPDIR}/redis-server.conf
   Run Keyword If  ${result.rc} != 0  Log  ${result.stderr}
   Should Be Equal As Integers  ${result.rc}  0
-  Wait Until Keyword Succeeds  30 sec  1 sec  Check Pidfile  ${TMPDIR}/redis.pid
-  Wait Until Keyword Succeeds  30 sec  1 sec  TCP Connect  ${REDIS_ADDR}  ${REDIS_PORT}
+  Wait Until Keyword Succeeds  5x  1 sec  Check Pidfile  ${TMPDIR}/redis.pid  timeout=0.5s
+  Wait Until Keyword Succeeds  5x  1 sec  Redis Check  ${REDIS_ADDR}  ${REDIS_PORT}
   ${REDIS_PID} =  Get File  ${TMPDIR}/redis.pid
   Run Keyword If  '${REDIS_SCOPE}' == 'Test'  Set Test Variable  ${REDIS_PID}
   ...  ELSE IF  '${REDIS_SCOPE}' == 'Suite'  Set Suite Variable  ${REDIS_PID}
@@ -136,8 +133,8 @@ Run Nginx
   ${result} =  Run Process  nginx  -c  ${TMPDIR}/nginx.conf
   Run Keyword If  ${result.rc} != 0  Log  ${result.stderr}
   Should Be Equal As Integers  ${result.rc}  0
-  Wait Until Keyword Succeeds  30 sec  1 sec  Check Pidfile  ${TMPDIR}/nginx.pid
-  Wait Until Keyword Succeeds  30 sec  1 sec  TCP Connect  ${NGINX_ADDR}  ${NGINX_PORT}
+  Wait Until Keyword Succeeds  10x  1 sec  Check Pidfile  ${TMPDIR}/nginx.pid  timeout=0.5s
+  Wait Until Keyword Succeeds  5x  1 sec  TCP Connect  ${NGINX_ADDR}  ${NGINX_PORT}
   ${NGINX_PID} =  Get File  ${TMPDIR}/nginx.pid
   Run Keyword If  '${NGINX_SCOPE}' == 'Test'  Set Test Variable  ${NGINX_PID}
   ...  ELSE IF  '${NGINX_SCOPE}' == 'Suite'  Set Suite Variable  ${NGINX_PID}
@@ -174,7 +171,8 @@ Run Rspamd
   Run Keyword If  ${result.rc} != 0  Log  ${result.stderr}
   ${rspamd_logpos} =  Log Logs  ${tmpdir}/rspamd.log  0
   Should Be Equal As Integers  ${result.rc}  0
-  Wait Until Keyword Succeeds  30 sec  1 sec  Check Pidfile  ${tmpdir}/rspamd.pid
+  Wait Until Keyword Succeeds  10x  1 sec  Check Pidfile  ${tmpdir}/rspamd.pid  timeout=0.5s
+  Wait Until Keyword Succeeds  5x  1 sec  Ping Rspamd  ${LOCAL_ADDR}  ${PORT_NORMAL}
   ${rspamd_pid} =  Get File  ${tmpdir}/rspamd.pid
   Set To Dictionary  ${d}  RSPAMD_LOGPOS=${rspamd_logpos}  RSPAMD_PID=${rspamd_pid}  TMPDIR=${tmpdir}
   [Return]  &{d}


More information about the Commits mailing list