summaryrefslogtreecommitdiff
path: root/src/integration-tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/integration-tests')
-rw-r--r--src/integration-tests/gnunet_pyexpect.py.in115
-rw-r--r--src/integration-tests/gnunet_testing.py.in100
-rwxr-xr-xsrc/integration-tests/test_integration_bootstrap_and_connect.py.in2
-rwxr-xr-xsrc/integration-tests/test_integration_clique.py.in14
-rwxr-xr-xsrc/integration-tests/test_integration_disconnect.py.in300
-rwxr-xr-xsrc/integration-tests/test_integration_disconnect_nat.py.in22
-rwxr-xr-xsrc/integration-tests/test_integration_reconnect.py.in272
-rwxr-xr-xsrc/integration-tests/test_integration_reconnect_nat.py.in25
8 files changed, 469 insertions, 381 deletions
diff --git a/src/integration-tests/gnunet_pyexpect.py.in b/src/integration-tests/gnunet_pyexpect.py.in
index d757634a5..aad84e4f7 100644
--- a/src/integration-tests/gnunet_pyexpect.py.in
+++ b/src/integration-tests/gnunet_pyexpect.py.in
@@ -11,7 +11,7 @@
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Affero General Public License for more details.
-#
+#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
@@ -26,58 +26,69 @@ import sys
import shutil
import time
-class pexpect (object):
- def __init__ (self):
- super (pexpect, self).__init__ ()
- def spawn (self, stdin, arglist, *pargs, **kwargs):
- env = kwargs.pop ('env', None)
- if env is None:
- env = os.environ.copy ()
- # This messes up some testcases, disable log redirection
- env.pop ('GNUNET_FORCE_LOGFILE', None)
- self.proc = subprocess.Popen (arglist, *pargs, env=env, **kwargs)
- if self.proc is None:
- print ("Failed to spawn a process {0}".format (arglist))
- sys.exit (1)
- if stdin is not None:
- self.stdo, self.stde = self.proc.communicate (stdin)
- else:
- self.stdo, self.stde = self.proc.communicate ()
- return self.proc
+class pexpect(object):
+ def __init__(self):
+ super(pexpect, self).__init__()
+
+ def spawn(self, stdin, arglist, *pargs, **kwargs):
+ env = kwargs.pop('env', None)
+ if env is None:
+ env = os.environ.copy()
+ # This messes up some testcases, disable log redirection
+ env.pop('GNUNET_FORCE_LOGFILE', None)
+ self.proc = subprocess.Popen(arglist, *pargs, env=env, **kwargs)
+ if self.proc is None:
+ print("Failed to spawn a process {0}".format(arglist))
+ sys.exit(1)
+ if stdin is not None:
+ self.stdo, self.stde = self.proc.communicate(stdin)
+ else:
+ self.stdo, self.stde = self.proc.communicate()
+ return self.proc
- def expect (self, s, r, flags=0):
- stream = self.stdo if s == 'stdout' else self.stde
- if isinstance (r, str):
- if r == "EOF":
- if len (stream) == 0:
- return True
+ def expect(self, s, r, flags=0):
+ stream = self.stdo if s == 'stdout' else self.stde
+ if isinstance(r, str):
+ if r == "EOF":
+ if len(stream) == 0:
+ return True
+ else:
+ print(
+ "Failed to find `{1}' in {0}, which is `{2}' ({3})".
+ format(s, r, stream, len(stream))
+ )
+ sys.exit(2)
+ raise ValueError(
+ "Argument `r' should be an instance of re.RegexObject or a special string, but is `{0}'"
+ .format(r)
+ )
+ m = r.search(stream, flags)
+ if not m:
+ print(
+ "Failed to find `{1}' in {0}, which is is `{2}'".format(
+ s, r.pattern, stream
+ )
+ )
+ sys.exit(2)
+ stream = stream[m.end():]
+ if s == 'stdout':
+ self.stdo = stream
else:
- print ("Failed to find `{1}' in {0}, which is `{2}' ({3})".format (s, r, stream, len (stream)))
- sys.exit (2)
- raise ValueError ("Argument `r' should be an instance of re.RegexObject or a special string, but is `{0}'".format (r))
- m = r.search (stream, flags)
- if not m:
- print ("Failed to find `{1}' in {0}, which is is `{2}'".format (s, r.pattern, stream))
- sys.exit (2)
- stream = stream[m.end ():]
- if s == 'stdout':
- self.stdo = stream
- else:
- self.stde = stream
- return m
+ self.stde = stream
+ return m
- def read (self, s, size=-1):
- stream = self.stdo if s == 'stdout' else self.stde
- result = ""
- if size < 0:
- result = stream
- new_stream = ""
- else:
- result = stream[0:size]
- new_stream = stream[size:]
- if s == 'stdout':
- self.stdo = new_stream
- else:
- self.stde = new_stream
- return result
+ def read(self, s, size=-1):
+ stream = self.stdo if s == 'stdout' else self.stde
+ result = ""
+ if size < 0:
+ result = stream
+ new_stream = ""
+ else:
+ result = stream[0:size]
+ new_stream = stream[size:]
+ if s == 'stdout':
+ self.stdo = new_stream
+ else:
+ self.stde = new_stream
+ return result
diff --git a/src/integration-tests/gnunet_testing.py.in b/src/integration-tests/gnunet_testing.py.in
index c3596d232..10f9d4475 100644
--- a/src/integration-tests/gnunet_testing.py.in
+++ b/src/integration-tests/gnunet_testing.py.in
@@ -30,11 +30,13 @@ import logging
logger = logging.getLogger()
handler = logging.StreamHandler()
formatter = logging.Formatter(
- '%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
+ '%(asctime)s %(name)-12s %(levelname)-8s %(message)s'
+)
handler.setFormatter(formatter)
logger.addHandler(handler)
logger.setLevel(logging.DEBUG)
+
class Check(object):
def __init__(self, test):
self.fulfilled = False
@@ -92,7 +94,9 @@ class Check(object):
neg += 1
else:
pos += 1
- logger.debug('%s out of %s conditions fulfilled', str(pos), str(pos+neg))
+ logger.debug(
+ '%s out of %s conditions fulfilled', str(pos), str(pos + neg)
+ )
return self.fulfilled
def reset(self):
@@ -115,9 +119,13 @@ class Condition(object):
def evaluate(self, failed_only):
if ((self.fulfilled == False) and (failed_only == True)):
- logger.debug('%s condition for was %s', str(self.type), str(self.fulfilled))
+ logger.debug(
+ '%s condition for was %s', str(self.type), str(self.fulfilled)
+ )
elif (failed_only == False):
- logger.debug('%s condition for was %s', str(self.type), str(self.fulfilled))
+ logger.debug(
+ '%s condition for was %s', str(self.type), str(self.fulfilled)
+ )
return self.fulfilled
@@ -140,9 +148,15 @@ class FileExistCondition(Condition):
def evaluate(self, failed_only):
if ((self.fulfilled == False) and (failed_only == True)):
- logger.debug('%s confition for file %s was %s', str(self.type), self.file, str(self.fulfilled))
+ logger.debug(
+ '%s confition for file %s was %s', str(self.type), self.file,
+ str(self.fulfilled)
+ )
elif (failed_only == False):
- logger.debug('%s confition for file %s was %s', str(self.type), self.file, str(self.fulfilled))
+ logger.debug(
+ '%s confition for file %s was %s', str(self.type), self.file,
+ str(self.fulfilled)
+ )
return self.fulfilled
@@ -158,7 +172,9 @@ class StatisticsCondition(Condition):
def check(self):
if (self.fulfilled == False):
- self.result = self.peer.get_statistics_value(self.subsystem, self.name)
+ self.result = self.peer.get_statistics_value(
+ self.subsystem, self.name
+ )
if (self.result == self.value):
self.fulfilled = True
return True
@@ -174,8 +190,14 @@ class StatisticsCondition(Condition):
else:
fail = ""
op = " == "
- if (((self.fulfilled == False) and (failed_only == True)) or (failed_only == False)):
- logger.debug('%s %s condition in subsystem %s: %s: (expected/real value) %s %s %s %s', self.peer.id[:4].decode("utf-8"), self.peer.cfg, self.subsystem.ljust(12), self.name.ljust(30), self.value, op, self.result, fail)
+ if (((self.fulfilled == False) and (failed_only == True))
+ or (failed_only == False)):
+ logger.debug(
+ '%s %s condition in subsystem %s: %s: (expected/real value) %s %s %s %s',
+ self.peer.id[:4].decode("utf-8"), self.peer.cfg,
+ self.subsystem.ljust(12), self.name.ljust(30), self.value, op,
+ self.result, fail
+ )
return self.fulfilled
@@ -195,8 +217,12 @@ class EqualStatisticsCondition(Condition):
def check(self):
if (self.fulfilled == False):
- self.result = self.peer.get_statistics_value(self.subsystem, self.name)
- self.result2 = self.peer2.get_statistics_value(self.subsystem2, self.name2)
+ self.result = self.peer.get_statistics_value(
+ self.subsystem, self.name
+ )
+ self.result2 = self.peer2.get_statistics_value(
+ self.subsystem2, self.name2
+ )
if (self.result == self.result2):
self.fulfilled = True
return True
@@ -206,8 +232,14 @@ class EqualStatisticsCondition(Condition):
return True
def evaluate(self, failed_only):
- if (((self.fulfilled == False) and (failed_only == True)) or (failed_only == False)):
- logger.debug('%s %s %s == %s %s %s %s %s', self.peer.id[:4], self.subsystem.ljust(12), self.name.ljust(30), self.result, self.peer2.id[:4], self.subsystem2.ljust(12), self.name2.ljust(30), self.result2)
+ if (((self.fulfilled == False) and (failed_only == True))
+ or (failed_only == False)):
+ logger.debug(
+ '%s %s %s == %s %s %s %s %s', self.peer.id[:4],
+ self.subsystem.ljust(12), self.name.ljust(30), self.result,
+ self.peer2.id[:4], self.subsystem2.ljust(12),
+ self.name2.ljust(30), self.result2
+ )
return self.fulfilled
@@ -262,19 +294,23 @@ class Peer(object):
# print('ERROR! Peer using cfg ' +
# self.cfg +
# ' could not be stopped')
- logger.debug('ERROR! Peer using cfg %s could not be stopped', self.cfg)
+ logger.debug(
+ 'ERROR! Peer using cfg %s could not be stopped', self.cfg
+ )
self.started = False
return ret
else:
return False
def start(self):
- os.unsetenv ("XDG_CONFIG_HOME")
- os.unsetenv ("XDG_DATA_HOME")
- os.unsetenv ("XDG_CACHE_HOME")
+ os.unsetenv("XDG_CONFIG_HOME")
+ os.unsetenv("XDG_DATA_HOME")
+ os.unsetenv("XDG_CACHE_HOME")
self.test.p("Starting peer using cfg " + self.cfg)
try:
- server = subprocess.Popen([self.test.gnunetarm, '-sq', '-c', self.cfg])
+ server = subprocess.Popen([
+ self.test.gnunetarm, '-sq', '-c', self.cfg
+ ])
server.communicate()
except OSError:
# print("Can not start peer")
@@ -285,7 +321,11 @@ class Peer(object):
test = ''
try:
server = pexpect()
- server.spawn(None, [self.test.gnunetpeerinfo, '-c', self.cfg, '-s'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+ server.spawn(
+ None, [self.test.gnunetpeerinfo, '-c', self.cfg, '-s'],
+ stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT
+ )
test = server.read("stdout", 1024)
except OSError:
# print("Can not get peer identity")
@@ -299,7 +339,9 @@ class Peer(object):
return False
self.test.p("Stopping peer using cfg " + self.cfg)
try:
- server = subprocess.Popen([self.test.gnunetarm, '-eq', '-c', self.cfg])
+ server = subprocess.Popen([
+ self.test.gnunetarm, '-eq', '-c', self.cfg
+ ])
server.communicate()
except OSError:
# print("Can not stop peer")
@@ -310,7 +352,14 @@ class Peer(object):
def get_statistics_value(self, subsystem, name):
server = pexpect()
- server.spawn(None, [self.test.gnunetstatistics, '-c', self.cfg, '-q', '-n', name, '-s', subsystem], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+ server.spawn(
+ None, [
+ self.test.gnunetstatistics, '-c', self.cfg, '-q', '-n', name,
+ '-s', subsystem
+ ],
+ stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT
+ )
# server.expect ("stdout", re.compile (r""))
test = server.read("stdout", 10240)
tests = test.partition(b'\n')
@@ -319,9 +368,14 @@ class Peer(object):
tests = (tests[0][:-1], tests[1], tests[2])
tests = tests[0]
result = tests.decode("utf-8").strip()
- logger.debug('running gnunet-statistics %s for %s "/" %s yields %s', self.cfg, name, subsystem, result)
+ logger.debug(
+ 'running gnunet-statistics %s for %s "/" %s yields %s', self.cfg,
+ name, subsystem, result
+ )
if (result.isdigit() == True):
return result
else:
- logger.debug('Invalid statistics value: %s is not a number!', result)
+ logger.debug(
+ 'Invalid statistics value: %s is not a number!', result
+ )
return -1
diff --git a/src/integration-tests/test_integration_bootstrap_and_connect.py.in b/src/integration-tests/test_integration_bootstrap_and_connect.py.in
index 4b4b35629..ddac326cd 100755
--- a/src/integration-tests/test_integration_bootstrap_and_connect.py.in
+++ b/src/integration-tests/test_integration_bootstrap_and_connect.py.in
@@ -32,7 +32,6 @@ from gnunet_testing import Check
from gnunet_testing import Condition
from gnunet_testing import *
-
#
# This test tests if a fresh peer bootstraps from a hostlist server and then
# successfully connects to the server
@@ -124,6 +123,7 @@ def check():
check.run_blocking(check_timeout, success_cont, fail_cont)
+
#
# Test execution
#
diff --git a/src/integration-tests/test_integration_clique.py.in b/src/integration-tests/test_integration_clique.py.in
index 0444cf249..a23c025ca 100755
--- a/src/integration-tests/test_integration_clique.py.in
+++ b/src/integration-tests/test_integration_clique.py.in
@@ -11,7 +11,7 @@
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Affero General Public License for more details.
-#
+#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
@@ -113,9 +113,13 @@ def check_connect():
check.add(StatisticsCondition(client, 'dht', '# peers connected', 2))
check.add(StatisticsCondition(client, 'fs', '# peers connected', 2))
- check.add(StatisticsCondition(client_nat, 'transport', '# peers connected', 2))
+ check.add(
+ StatisticsCondition(client_nat, 'transport', '# peers connected', 2)
+ )
check.add(StatisticsCondition(client_nat, 'core', '# peers connected', 2))
- check.add(StatisticsCondition(client_nat, 'topology', '# peers connected', 2))
+ check.add(
+ StatisticsCondition(client_nat, 'topology', '# peers connected', 2)
+ )
check.add(StatisticsCondition(client_nat, 'dht', '# peers connected', 2))
check.add(StatisticsCondition(client_nat, 'fs', '# peers connected', 2))
@@ -127,6 +131,7 @@ def check_connect():
check.run_blocking(check_timeout, success_cont, fail_cont)
+
#
# Test execution
#
@@ -199,7 +204,8 @@ def run():
cleanup()
sys.exit(success)
- if ((client.started == True) and (client_nat.started == True) and (server.started == True)):
+ if ((client.started == True) and (client_nat.started == True)
+ and (server.started == True)):
test.p('Peers started, running check')
check_connect()
diff --git a/src/integration-tests/test_integration_disconnect.py.in b/src/integration-tests/test_integration_disconnect.py.in
index 737014e61..9861728c2 100755
--- a/src/integration-tests/test_integration_disconnect.py.in
+++ b/src/integration-tests/test_integration_disconnect.py.in
@@ -32,7 +32,6 @@ from gnunet_testing import Check
from gnunet_testing import Condition
from gnunet_testing import *
-
#
# This test tests if a fresh peer bootstraps from a hostlist server and then
# successfully connects to the server. When both peers are connected
@@ -48,158 +47,169 @@ verbose = True
check_timeout = 180
if os.name == "nt":
- tmp = os.getenv ("TEMP")
- signals = [signal.SIGTERM, signal.SIGINT]
+ tmp = os.getenv("TEMP")
+ signals = [signal.SIGTERM, signal.SIGINT]
else:
- tmp = "/tmp"
- signals = [signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGQUIT]
-
-def cleanup_onerror (function, path, excinfo):
- import stat
- if not os.path.exists (path):
- pass
- elif not os.access(path, os.W_OK):
- # Is the error an access error ?
- os.chmod (path, stat.S_IWUSR)
- function (path)
- else:
- raise
-
-def cleanup ():
- shutil.rmtree (os.path.join (tmp, "c_bootstrap_server"), False, cleanup_onerror)
- shutil.rmtree (os.path.join (tmp, "c_no_nat_client"), False, cleanup_onerror)
-
-
-def success_disconnect_cont (check):
- print('Peers disconnected successfully')
- global success
- success = True;
-
-
-def fail_disconnect_cont (check):
- global success
- success = False;
- print('Peers failed to disconnect')
- check.evaluate(True)
-
-def check_disconnect ():
- test.p ('Shutting down bootstrap server')
- server.stop ()
- check = Check (test)
- check.add (StatisticsCondition (client, 'transport', '# peers connected',0))
- check.add (StatisticsCondition (client, 'core', '# peers connected',0))
- check.add (StatisticsCondition (client, 'topology', '# peers connected',0))
- check.add (StatisticsCondition (client, 'dht', '# peers connected',0))
- check.add (StatisticsCondition (client, 'fs', '# peers connected',0))
- check.run_blocking (check_timeout, success_disconnect_cont, fail_disconnect_cont)
-
-
-def success_connect_cont (check):
- print('Peers connected successfully')
- check_disconnect ()
-
-
-def fail_connect_cont (check):
- global success
- success= False
- print('Peers failed to connected!')
- check.evaluate(True)
-
-
-def check_connect ():
- check = Check (test)
- check.add (StatisticsCondition (server, 'transport', '# peers connected',1))
- check.add (StatisticsCondition (server, 'core', '# peers connected',1))
- check.add (StatisticsCondition (server, 'topology', '# peers connected',1))
- check.add (StatisticsCondition (server, 'dht', '# peers connected',1))
- check.add (StatisticsCondition (server, 'fs', '# peers connected',1))
-
- check.add (StatisticsCondition (client, 'transport', '# peers connected',1))
- check.add (StatisticsCondition (client, 'core', '# peers connected',1))
- check.add (StatisticsCondition (client, 'topology', '# peers connected',1))
- check.add (StatisticsCondition (client, 'dht', '# peers connected',1))
- check.add (StatisticsCondition (client, 'fs', '# peers connected',1))
-
- check.run_blocking (check_timeout, success_connect_cont, fail_connect_cont)
+ tmp = "/tmp"
+ signals = [signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGQUIT]
+
+
+def cleanup_onerror(function, path, excinfo):
+ import stat
+ if not os.path.exists(path):
+ pass
+ elif not os.access(path, os.W_OK):
+ # Is the error an access error ?
+ os.chmod(path, stat.S_IWUSR)
+ function(path)
+ else:
+ raise
+
+
+def cleanup():
+ shutil.rmtree(
+ os.path.join(tmp, "c_bootstrap_server"), False, cleanup_onerror
+ )
+ shutil.rmtree(os.path.join(tmp, "c_no_nat_client"), False, cleanup_onerror)
+
+
+def success_disconnect_cont(check):
+ print('Peers disconnected successfully')
+ global success
+ success = True
+
+
+def fail_disconnect_cont(check):
+ global success
+ success = False
+ print('Peers failed to disconnect')
+ check.evaluate(True)
+
+
+def check_disconnect():
+ test.p('Shutting down bootstrap server')
+ server.stop()
+ check = Check(test)
+ check.add(StatisticsCondition(client, 'transport', '# peers connected', 0))
+ check.add(StatisticsCondition(client, 'core', '# peers connected', 0))
+ check.add(StatisticsCondition(client, 'topology', '# peers connected', 0))
+ check.add(StatisticsCondition(client, 'dht', '# peers connected', 0))
+ check.add(StatisticsCondition(client, 'fs', '# peers connected', 0))
+ check.run_blocking(
+ check_timeout, success_disconnect_cont, fail_disconnect_cont
+ )
+
+
+def success_connect_cont(check):
+ print('Peers connected successfully')
+ check_disconnect()
+
+
+def fail_connect_cont(check):
+ global success
+ success = False
+ print('Peers failed to connected!')
+ check.evaluate(True)
+
+
+def check_connect():
+ check = Check(test)
+ check.add(StatisticsCondition(server, 'transport', '# peers connected', 1))
+ check.add(StatisticsCondition(server, 'core', '# peers connected', 1))
+ check.add(StatisticsCondition(server, 'topology', '# peers connected', 1))
+ check.add(StatisticsCondition(server, 'dht', '# peers connected', 1))
+ check.add(StatisticsCondition(server, 'fs', '# peers connected', 1))
+
+ check.add(StatisticsCondition(client, 'transport', '# peers connected', 1))
+ check.add(StatisticsCondition(client, 'core', '# peers connected', 1))
+ check.add(StatisticsCondition(client, 'topology', '# peers connected', 1))
+ check.add(StatisticsCondition(client, 'dht', '# peers connected', 1))
+ check.add(StatisticsCondition(client, 'fs', '# peers connected', 1))
+
+ check.run_blocking(check_timeout, success_connect_cont, fail_connect_cont)
+
#
# Test execution
#
-def SigHandler(signum = None, frame = None):
- global success
- global server
- global client
-
- print('Test was aborted!')
- if (None != server):
- server.stop ()
- if (None != client):
- client.stop ()
- cleanup ()
- sys.exit(success)
-
-def run ():
- global success
- global test
- global server
- global client
-
- server = None
- client = None
- success = False
-
- for sig in signals:
- signal.signal(sig, SigHandler)
-
- test = Test ('test_integration_bootstrap_and_connect.py', verbose)
- cleanup ()
-
- server = Peer(test, './confs/c_bootstrap_server.conf');
- client = Peer(test, './confs/c_no_nat_client.conf');
-
- if (True != server.start()):
- print('Failed to start server')
- if (None != server):
- server.stop ()
- cleanup ()
- sys.exit(success)
-
- # Give the server time to start
- time.sleep(5)
-
- if (True != client.start()):
- print('Failed to start client')
- if (None != server):
- server.stop ()
- if (None != client):
- client.stop ()
- cleanup ()
- sys.exit(success)
-
- if ((client.started == True) and (server.started == True)):
- test.p ('Peers started, running check')
- time.sleep(5)
- check_connect ()
- server.stop ()
- client.stop ()
-
- cleanup ()
-
- if (success == False):
- print ('Test failed')
- return False
- else:
- return True
+
+def SigHandler(signum=None, frame=None):
+ global success
+ global server
+ global client
+
+ print('Test was aborted!')
+ if (None != server):
+ server.stop()
+ if (None != client):
+ client.stop()
+ cleanup()
+ sys.exit(success)
+
+
+def run():
+ global success
+ global test
+ global server
+ global client
+
+ server = None
+ client = None
+ success = False
+
+ for sig in signals:
+ signal.signal(sig, SigHandler)
+
+ test = Test('test_integration_bootstrap_and_connect.py', verbose)
+ cleanup()
+
+ server = Peer(test, './confs/c_bootstrap_server.conf')
+ client = Peer(test, './confs/c_no_nat_client.conf')
+
+ if (True != server.start()):
+ print('Failed to start server')
+ if (None != server):
+ server.stop()
+ cleanup()
+ sys.exit(success)
+
+ # Give the server time to start
+ time.sleep(5)
+
+ if (True != client.start()):
+ print('Failed to start client')
+ if (None != server):
+ server.stop()
+ if (None != client):
+ client.stop()
+ cleanup()
+ sys.exit(success)
+
+ if ((client.started == True) and (server.started == True)):
+ test.p('Peers started, running check')
+ time.sleep(5)
+ check_connect()
+ server.stop()
+ client.stop()
+
+ cleanup()
+
+ if (success == False):
+ print('Test failed')
+ return False
+ else:
+ return True
+
try:
- run ()
+ run()
except (KeyboardInterrupt, SystemExit):
- print('Test interrupted')
- server.stop ()
- client.stop ()
- cleanup ()
+ print('Test interrupted')
+ server.stop()
+ client.stop()
+ cleanup()
if (success == False):
- sys.exit(1)
+ sys.exit(1)
else:
- sys.exit(0)
+ sys.exit(0)
diff --git a/src/integration-tests/test_integration_disconnect_nat.py.in b/src/integration-tests/test_integration_disconnect_nat.py.in
index c3d5d8901..d3ff84ebe 100755
--- a/src/integration-tests/test_integration_disconnect_nat.py.in
+++ b/src/integration-tests/test_integration_disconnect_nat.py.in
@@ -32,7 +32,6 @@ from gnunet_testing import Check
from gnunet_testing import Condition
from gnunet_testing import *
-
#
# This test tests if a fresh peer bootstraps from a hostlist server and then
# successfully connects to the server. When both peers are connected
@@ -68,7 +67,9 @@ def cleanup_onerror(function, path, excinfo):
def cleanup():
- shutil.rmtree(os.path.join(tmp, "c_bootstrap_server"), False, cleanup_onerror)
+ shutil.rmtree(
+ os.path.join(tmp, "c_bootstrap_server"), False, cleanup_onerror
+ )
shutil.rmtree(os.path.join(tmp, "c_nat_client"), False, cleanup_onerror)
@@ -80,7 +81,7 @@ def success_disconnect_cont(check):
def fail_disconnect_cont(check):
global success
- success = False;
+ success = False
print('Peers failed to disconnect')
check.evaluate(True)
@@ -96,7 +97,9 @@ def check_disconnect():
check.add(StatisticsCondition(server, 'topology', '# peers connected', 0))
check.add(StatisticsCondition(server, 'dht', '# peers connected', 0))
check.add(StatisticsCondition(server, 'fs', '# peers connected', 0))
- check.run_blocking(check_timeout, success_disconnect_cont, fail_disconnect_cont)
+ check.run_blocking(
+ check_timeout, success_disconnect_cont, fail_disconnect_cont
+ )
def success_connect_cont(check):
@@ -115,9 +118,13 @@ def check_connect():
global server
global nat_client
check = Check(test)
- check.add(StatisticsCondition(nat_client, 'transport', '# peers connected', 1))
+ check.add(
+ StatisticsCondition(nat_client, 'transport', '# peers connected', 1)
+ )
check.add(StatisticsCondition(nat_client, 'core', '# peers connected', 1))
- check.add(StatisticsCondition(nat_client, 'topology', '# peers connected', 1))
+ check.add(
+ StatisticsCondition(nat_client, 'topology', '# peers connected', 1)
+ )
check.add(StatisticsCondition(nat_client, 'dht', '# peers connected', 1))
check.add(StatisticsCondition(nat_client, 'fs', '# peers connected', 1))
@@ -134,6 +141,7 @@ def check_connect():
# Test execution
#
+
def SigHandler(signum=None, frame=None):
global success
global server
@@ -204,7 +212,7 @@ def run():
try:
run()
-except(KeyboardInterrupt, SystemExit):
+except (KeyboardInterrupt, SystemExit):
print('Test interrupted')
server.stop()
nat_client.stop()
diff --git a/src/integration-tests/test_integration_reconnect.py.in b/src/integration-tests/test_integration_reconnect.py.in
index 8c4193680..5bffb72e3 100755
--- a/src/integration-tests/test_integration_reconnect.py.in
+++ b/src/integration-tests/test_integration_reconnect.py.in
@@ -32,7 +32,6 @@ from gnunet_testing import Check
from gnunet_testing import Condition
from gnunet_testing import *
-
#
# This test tests if a fresh peer bootstraps from a hostlist server and then
# successfully connects to the server. When both peers are connected
@@ -43,195 +42,196 @@ from gnunet_testing import *
#definitions
-
testname = "test_integration_restart"
verbose = True
check_timeout = 180
if os.name == "nt":
- tmp = os.getenv ("TEMP")
- signals = [signal.SIGTERM, signal.SIGINT]
+ tmp = os.getenv("TEMP")
+ signals = [signal.SIGTERM, signal.SIGINT]
else:
- tmp = "/tmp"
- signals = [signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGQUIT]
-
-def cleanup_onerror (function, path, excinfo):
- import stat
- if not os.path.exists (path):
- pass
- elif not os.access(path, os.W_OK):
- # Is the error an access error ?
- os.chmod (path, stat.S_IWUSR)
- function (path)
- else:
- raise
-
-def cleanup ():
+ tmp = "/tmp"
+ signals = [signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGQUIT]
+
+
+def cleanup_onerror(function, path, excinfo):
+ import stat
+ if not os.path.exists(path):
+ pass
+ elif not os.access(path, os.W_OK):
+ # Is the error an access error ?
+ os.chmod(path, stat.S_IWUSR)
+ function(path)
+ else:
+ raise
+
+
+def cleanup():
retries = 10
- path = os.path.join (tmp, "c_bootstrap_server")
- test.p ("Removing " + path)
+ path = os.path.join(tmp, "c_bootstrap_server")
+ test.p("Removing " + path)
while ((os.path.exists(path)) and (retries > 0)):
- shutil.rmtree ((path), False, cleanup_onerror)
- time.sleep (1)
+ shutil.rmtree((path), False, cleanup_onerror)
+ time.sleep(1)
retries -= 1
if (os.path.exists(path)):
- test.p ("Failed to remove " + path)
-
+ test.p("Failed to remove " + path)
retries = 10
- path = os.path.join (tmp, "c_no_nat_client")
- test.p ("Removing " + path)
+ path = os.path.join(tmp, "c_no_nat_client")
+ test.p("Removing " + path)
while ((os.path.exists(path)) and (retries > 0)):
- shutil.rmtree ((path), False, cleanup_onerror)
- time.sleep (1)
+ shutil.rmtree((path), False, cleanup_onerror)
+ time.sleep(1)
retries -= 1
if (os.path.exists(path)):
- test.p ("Failed to remove " + path)
+ test.p("Failed to remove " + path)
+
-def success_restart_cont (check):
- global success
- print('Peers connected successfully after restart')
- server.stop ()
- client.stop ()
- success = True;
+def success_restart_cont(check):
+ global success
+ print('Peers connected successfully after restart')
+ server.stop()
+ client.stop()
+ success = True
-def fail_restart_cont (check):
- global success
- success = False;
- print('Peers failed to connect after restart')
- check.evaluate(True)
+def fail_restart_cont(check):
+ global success
+ success = False
+ print('Peers failed to connect after restart')
+ check.evaluate(True)
-def success_connect_cont (check):
- print('Peers connected successfully')
- server.stop ()
- client.stop ()
+def success_connect_cont(check):
+ print('Peers connected successfully')
+ server.stop()
+ client.stop()
- time.sleep(5)
+ time.sleep(5)
- test.p ('Restarting client & server')
- server.start ()
- client.start ()
+ test.p('Restarting client & server')
+ server.start()
+ client.start()
- check = Check (test)
- check.add (StatisticsCondition (client, 'transport', '# peers connected',1))
- check.add (StatisticsCondition (client, 'core', '# peers connected',1))
- check.add (StatisticsCondition (client, 'topology', '# peers connected',1))
- check.add (StatisticsCondition (client, 'fs', '# peers connected',1))
+ check = Check(test)
+ check.add(StatisticsCondition(client, 'transport', '# peers connected', 1))
+ check.add(StatisticsCondition(client, 'core', '# peers connected', 1))
+ check.add(StatisticsCondition(client, 'topology', '# peers connected', 1))
+ check.add(StatisticsCondition(client, 'fs', '# peers connected', 1))
- check.add (StatisticsCondition (server, 'transport', '# peers connected',1))
- check.add (StatisticsCondition (server, 'core', '# peers connected',1))
- check.add (StatisticsCondition (server, 'topology', '# peers connected',1))
- check.add (StatisticsCondition (server, 'fs', '# peers connected',1))
+ check.add(StatisticsCondition(server, 'transport', '# peers connected', 1))
+ check.add(StatisticsCondition(server, 'core', '# peers connected', 1))
+ check.add(StatisticsCondition(server, 'topology', '# peers connected', 1))
+ check.add(StatisticsCondition(server, 'fs', '# peers connected', 1))
- check.run_blocking (check_timeout, success_restart_cont, fail_restart_cont)
+ check.run_blocking(check_timeout, success_restart_cont, fail_restart_cont)
-def fail_connect_cont (check):
- global success
- success= False;
- print('Peers failed to connect')
- check.evaluate(True)
+def fail_connect_cont(check):
+ global success
+ success = False
+ print('Peers failed to connect')
+ check.evaluate(True)
-def check_connect ():
- check = Check (test)
- check.add (StatisticsCondition (client, 'transport', '# peers connected',1))
- check.add (StatisticsCondition (client, 'core', '# peers connected',1))
- check.add (StatisticsCondition (client, 'topology', '# peers connected',1))
- check.add (StatisticsCondition (client, 'fs', '# peers connected',1))
+def check_connect():
+ check = Check(test)
+ check.add(StatisticsCondition(client, 'transport', '# peers connected', 1))
+ check.add(StatisticsCondition(client, 'core', '# peers connected', 1))
+ check.add(StatisticsCondition(client, 'topology', '# peers connected', 1))
+ check.add(StatisticsCondition(client, 'fs', '# peers connected', 1))
- check.add (StatisticsCondition (server, 'transport', '# peers connected',1))
- check.add (StatisticsCondition (server, 'core', '# peers connected',1))
- check.add (StatisticsCondition (server, 'topology', '# peers connected',1))
- check.add (StatisticsCondition (server, 'fs', '# peers connected',1))
+ check.add(StatisticsCondition(server, 'transport', '# peers connected', 1))
+ check.add(StatisticsCondition(server, 'core', '# peers connected', 1))
+ check.add(StatisticsCondition(server, 'topology', '# peers connected', 1))
+ check.add(StatisticsCondition(server, 'fs', '# peers connected', 1))
+
+ check.run_blocking(check_timeout, success_connect_cont, fail_connect_cont)
- check.run_blocking (check_timeout, success_connect_cont, fail_connect_cont)
#
# Test execution
#
-def SigHandler(signum = None, frame = None):
- global success
- global server
- global client
-
- print('Test was aborted!')
- if (None != server):
- server.stop ()
- if (None != client):
- client.stop ()
- cleanup ()
- sys.exit(success)
+def SigHandler(signum=None, frame=None):
+ global success
+ global server
+ global client
-def run ():
- global success
- global test
- global server
- global client
+ print('Test was aborted!')
+ if (None != server):
+ server.stop()
+ if (None != client):
+ client.stop()
+ cleanup()
+ sys.exit(success)
- success = False
- server = None
- client = None
- for sig in signals:
- signal.signal(sig, SigHandler)
+def run():
+ global success
+ global test
+ global server
+ global client
+ success = False
+ server = None
+ client = None
- test = Test ('test_integration_disconnect', verbose)
- cleanup ()
- server = Peer(test, './confs/c_bootstrap_server.conf');
- server.start();
+ for sig in signals:
+ signal.signal(sig, SigHandler)
- client = Peer(test, './confs/c_no_nat_client.conf');
- client.start();
+ test = Test('test_integration_disconnect', verbose)
+ cleanup()
+ server = Peer(test, './confs/c_bootstrap_server.conf')
+ server.start()
+ client = Peer(test, './confs/c_no_nat_client.conf')
+ client.start()
- if (True != server.start()):
- print('Failed to start server')
- if (None != server):
- server.stop ()
- if (None != server):
- client.stop ()
- cleanup ()
- sys.exit(success)
+ if (True != server.start()):
+ print('Failed to start server')
+ if (None != server):
+ server.stop()
+ if (None != server):
+ client.stop()
+ cleanup()
+ sys.exit(success)
- # Give the server time to start
- time.sleep(5)
+ # Give the server time to start
+ time.sleep(5)
- if (True != client.start()):
- print('Failed to start client')
- if (None != server):
- server.stop ()
- if (None != server):
- client.stop ()
- cleanup ()
- sys.exit(success)
+ if (True != client.start()):
+ print('Failed to start client')
+ if (None != server):
+ server.stop()
+ if (None != server):
+ client.stop()
+ cleanup()
+ sys.exit(success)
- check_connect ()
+ check_connect()
- server.stop ()
- client.stop ()
- cleanup ()
+ server.stop()
+ client.stop()
+ cleanup()
- if (success == False):
- print ('Test failed')
- return True
- else:
- return False
+ if (success == False):
+ print('Test failed')
+ return True
+ else:
+ return False
try:
- run ()
+ run()
except (KeyboardInterrupt, SystemExit):
print('Test interrupted')
- server.stop ()
- client.stop ()
- cleanup ()
+ server.stop()
+ client.stop()
+ cleanup()
if (success == False):
- sys.exit(1)
+ sys.exit(1)
else:
- sys.exit(0)
+ sys.exit(0)
diff --git a/src/integration-tests/test_integration_reconnect_nat.py.in b/src/integration-tests/test_integration_reconnect_nat.py.in
index 45626d50d..751a0484b 100755
--- a/src/integration-tests/test_integration_reconnect_nat.py.in
+++ b/src/integration-tests/test_integration_reconnect_nat.py.in
@@ -32,7 +32,6 @@ from gnunet_testing import Check
from gnunet_testing import Condition
from gnunet_testing import *
-
#
# This test tests if a fresh peer bootstraps from a hostlist server and then
# successfully connects to the server. When both peers are connected
@@ -43,7 +42,6 @@ from gnunet_testing import *
# definitions
-
testname = "test_integration_restart"
verbose = True
check_timeout = 180
@@ -82,7 +80,7 @@ def cleanup():
retries = 10
path = os.path.join(tmp, "c_nat_client")
test.p("Removing " + path)
- while((os.path.exists(path)) and(retries > 0)):
+ while ((os.path.exists(path)) and (retries > 0)):
shutil.rmtree((path), False, cleanup_onerror)
time.sleep(1)
retries -= 1
@@ -91,18 +89,18 @@ def cleanup():
def success_restart_cont(check):
- global success
- print('Peers connected successfully after restart')
- server.stop()
- client.stop()
- success = True
+ global success
+ print('Peers connected successfully after restart')
+ server.stop()
+ client.stop()
+ success = True
def fail_restart_cont(check):
- global success
- success = False
- print('Peers failed to connect after restart')
- check.evaluate(True)
+ global success
+ success = False
+ print('Peers failed to connect after restart')
+ check.evaluate(True)
def success_connect_cont(check):
@@ -151,6 +149,7 @@ def check_connect():
check.run_blocking(check_timeout, success_connect_cont, fail_connect_cont)
+
#
# Test execution
#
@@ -227,7 +226,7 @@ def run():
try:
run()
-except(KeyboardInterrupt, SystemExit):
+except (KeyboardInterrupt, SystemExit):
print('Test interrupted')
server.stop()
client.stop()