Browse Source

[Test] Various robot fixes

tags/2.0
Vsevolod Stakhov 4 years ago
parent
commit
e8afa71d30

+ 1
- 1
test/functional/cases/330_neural.robot View File

@@ -66,5 +66,5 @@ Neural Setup
Run Redis

Neural Teardown
Normal Teardown
Shutdown Process With Children ${REDIS_PID}
Normal Teardown

+ 2
- 0
test/functional/configs/redis-server.conf View File

@@ -1,5 +1,7 @@
bind ${REDIS_ADDR}
daemonize yes
loglevel debug
logfile ${TMPDIR}/redis.log
pidfile ${TMPDIR}/redis.pid
port ${REDIS_PORT}
dir ${TMPDIR}

+ 23
- 0
test/functional/lib/rspamd.py View File

@@ -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

+ 6
- 8
test/functional/lib/rspamd.robot View File

@@ -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}

Loading…
Cancel
Save