diff options
Diffstat (limited to 'src/integration-tests')
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 @@ | |||
11 | # WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | # WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | # Affero General Public License for more details. | 13 | # Affero General Public License for more details. |
14 | # | 14 | # |
15 | # You should have received a copy of the GNU Affero General Public License | 15 | # You should have received a copy of the GNU Affero General Public License |
16 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | # | 17 | # |
@@ -26,58 +26,69 @@ import sys | |||
26 | import shutil | 26 | import shutil |
27 | import time | 27 | import time |
28 | 28 | ||
29 | class pexpect (object): | ||
30 | def __init__ (self): | ||
31 | super (pexpect, self).__init__ () | ||
32 | 29 | ||
33 | def spawn (self, stdin, arglist, *pargs, **kwargs): | 30 | class pexpect(object): |
34 | env = kwargs.pop ('env', None) | 31 | def __init__(self): |
35 | if env is None: | 32 | super(pexpect, self).__init__() |
36 | env = os.environ.copy () | 33 | |
37 | # This messes up some testcases, disable log redirection | 34 | def spawn(self, stdin, arglist, *pargs, **kwargs): |
38 | env.pop ('GNUNET_FORCE_LOGFILE', None) | 35 | env = kwargs.pop('env', None) |
39 | self.proc = subprocess.Popen (arglist, *pargs, env=env, **kwargs) | 36 | if env is None: |
40 | if self.proc is None: | 37 | env = os.environ.copy() |
41 | print ("Failed to spawn a process {0}".format (arglist)) | 38 | # This messes up some testcases, disable log redirection |
42 | sys.exit (1) | 39 | env.pop('GNUNET_FORCE_LOGFILE', None) |
43 | if stdin is not None: | 40 | self.proc = subprocess.Popen(arglist, *pargs, env=env, **kwargs) |
44 | self.stdo, self.stde = self.proc.communicate (stdin) | 41 | if self.proc is None: |
45 | else: | 42 | print("Failed to spawn a process {0}".format(arglist)) |
46 | self.stdo, self.stde = self.proc.communicate () | 43 | sys.exit(1) |
47 | return self.proc | 44 | if stdin is not None: |
45 | self.stdo, self.stde = self.proc.communicate(stdin) | ||
46 | else: | ||
47 | self.stdo, self.stde = self.proc.communicate() | ||
48 | return self.proc | ||
48 | 49 | ||
49 | def expect (self, s, r, flags=0): | 50 | def expect(self, s, r, flags=0): |
50 | stream = self.stdo if s == 'stdout' else self.stde | 51 | stream = self.stdo if s == 'stdout' else self.stde |
51 | if isinstance (r, str): | 52 | if isinstance(r, str): |
52 | if r == "EOF": | 53 | if r == "EOF": |
53 | if len (stream) == 0: | 54 | if len(stream) == 0: |
54 | return True | 55 | return True |
56 | else: | ||
57 | print( | ||
58 | "Failed to find `{1}' in {0}, which is `{2}' ({3})". | ||
59 | format(s, r, stream, len(stream)) | ||
60 | ) | ||
61 | sys.exit(2) | ||
62 | raise ValueError( | ||
63 | "Argument `r' should be an instance of re.RegexObject or a special string, but is `{0}'" | ||
64 | .format(r) | ||
65 | ) | ||
66 | m = r.search(stream, flags) | ||
67 | if not m: | ||
68 | print( | ||
69 | "Failed to find `{1}' in {0}, which is is `{2}'".format( | ||
70 | s, r.pattern, stream | ||
71 | ) | ||
72 | ) | ||
73 | sys.exit(2) | ||
74 | stream = stream[m.end():] | ||
75 | if s == 'stdout': | ||
76 | self.stdo = stream | ||
55 | else: | 77 | else: |
56 | print ("Failed to find `{1}' in {0}, which is `{2}' ({3})".format (s, r, stream, len (stream))) | 78 | self.stde = stream |
57 | sys.exit (2) | 79 | return m |
58 | raise ValueError ("Argument `r' should be an instance of re.RegexObject or a special string, but is `{0}'".format (r)) | ||
59 | m = r.search (stream, flags) | ||
60 | if not m: | ||
61 | print ("Failed to find `{1}' in {0}, which is is `{2}'".format (s, r.pattern, stream)) | ||
62 | sys.exit (2) | ||
63 | stream = stream[m.end ():] | ||
64 | if s == 'stdout': | ||
65 | self.stdo = stream | ||
66 | else: | ||
67 | self.stde = stream | ||
68 | return m | ||
69 | 80 | ||
70 | def read (self, s, size=-1): | 81 | def read(self, s, size=-1): |
71 | stream = self.stdo if s == 'stdout' else self.stde | 82 | stream = self.stdo if s == 'stdout' else self.stde |
72 | result = "" | 83 | result = "" |
73 | if size < 0: | 84 | if size < 0: |
74 | result = stream | 85 | result = stream |
75 | new_stream = "" | 86 | new_stream = "" |
76 | else: | 87 | else: |
77 | result = stream[0:size] | 88 | result = stream[0:size] |
78 | new_stream = stream[size:] | 89 | new_stream = stream[size:] |
79 | if s == 'stdout': | 90 | if s == 'stdout': |
80 | self.stdo = new_stream | 91 | self.stdo = new_stream |
81 | else: | 92 | else: |
82 | self.stde = new_stream | 93 | self.stde = new_stream |
83 | return result | 94 | 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 | |||
30 | logger = logging.getLogger() | 30 | logger = logging.getLogger() |
31 | handler = logging.StreamHandler() | 31 | handler = logging.StreamHandler() |
32 | formatter = logging.Formatter( | 32 | formatter = logging.Formatter( |
33 | '%(asctime)s %(name)-12s %(levelname)-8s %(message)s') | 33 | '%(asctime)s %(name)-12s %(levelname)-8s %(message)s' |
34 | ) | ||
34 | handler.setFormatter(formatter) | 35 | handler.setFormatter(formatter) |
35 | logger.addHandler(handler) | 36 | logger.addHandler(handler) |
36 | logger.setLevel(logging.DEBUG) | 37 | logger.setLevel(logging.DEBUG) |
37 | 38 | ||
39 | |||
38 | class Check(object): | 40 | class Check(object): |
39 | def __init__(self, test): | 41 | def __init__(self, test): |
40 | self.fulfilled = False | 42 | self.fulfilled = False |
@@ -92,7 +94,9 @@ class Check(object): | |||
92 | neg += 1 | 94 | neg += 1 |
93 | else: | 95 | else: |
94 | pos += 1 | 96 | pos += 1 |
95 | logger.debug('%s out of %s conditions fulfilled', str(pos), str(pos+neg)) | 97 | logger.debug( |
98 | '%s out of %s conditions fulfilled', str(pos), str(pos + neg) | ||
99 | ) | ||
96 | return self.fulfilled | 100 | return self.fulfilled |
97 | 101 | ||
98 | def reset(self): | 102 | def reset(self): |
@@ -115,9 +119,13 @@ class Condition(object): | |||
115 | 119 | ||
116 | def evaluate(self, failed_only): | 120 | def evaluate(self, failed_only): |
117 | if ((self.fulfilled == False) and (failed_only == True)): | 121 | if ((self.fulfilled == False) and (failed_only == True)): |
118 | logger.debug('%s condition for was %s', str(self.type), str(self.fulfilled)) | 122 | logger.debug( |
123 | '%s condition for was %s', str(self.type), str(self.fulfilled) | ||
124 | ) | ||
119 | elif (failed_only == False): | 125 | elif (failed_only == False): |
120 | logger.debug('%s condition for was %s', str(self.type), str(self.fulfilled)) | 126 | logger.debug( |
127 | '%s condition for was %s', str(self.type), str(self.fulfilled) | ||
128 | ) | ||
121 | return self.fulfilled | 129 | return self.fulfilled |
122 | 130 | ||
123 | 131 | ||
@@ -140,9 +148,15 @@ class FileExistCondition(Condition): | |||
140 | 148 | ||
141 | def evaluate(self, failed_only): | 149 | def evaluate(self, failed_only): |
142 | if ((self.fulfilled == False) and (failed_only == True)): | 150 | if ((self.fulfilled == False) and (failed_only == True)): |
143 | logger.debug('%s confition for file %s was %s', str(self.type), self.file, str(self.fulfilled)) | 151 | logger.debug( |
152 | '%s confition for file %s was %s', str(self.type), self.file, | ||
153 | str(self.fulfilled) | ||
154 | ) | ||
144 | elif (failed_only == False): | 155 | elif (failed_only == False): |
145 | logger.debug('%s confition for file %s was %s', str(self.type), self.file, str(self.fulfilled)) | 156 | logger.debug( |
157 | '%s confition for file %s was %s', str(self.type), self.file, | ||
158 | str(self.fulfilled) | ||
159 | ) | ||
146 | return self.fulfilled | 160 | return self.fulfilled |
147 | 161 | ||
148 | 162 | ||
@@ -158,7 +172,9 @@ class StatisticsCondition(Condition): | |||
158 | 172 | ||
159 | def check(self): | 173 | def check(self): |
160 | if (self.fulfilled == False): | 174 | if (self.fulfilled == False): |
161 | self.result = self.peer.get_statistics_value(self.subsystem, self.name) | 175 | self.result = self.peer.get_statistics_value( |
176 | self.subsystem, self.name | ||
177 | ) | ||
162 | if (self.result == self.value): | 178 | if (self.result == self.value): |
163 | self.fulfilled = True | 179 | self.fulfilled = True |
164 | return True | 180 | return True |
@@ -174,8 +190,14 @@ class StatisticsCondition(Condition): | |||
174 | else: | 190 | else: |
175 | fail = "" | 191 | fail = "" |
176 | op = " == " | 192 | op = " == " |
177 | if (((self.fulfilled == False) and (failed_only == True)) or (failed_only == False)): | 193 | if (((self.fulfilled == False) and (failed_only == True)) |
178 | 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) | 194 | or (failed_only == False)): |
195 | logger.debug( | ||
196 | '%s %s condition in subsystem %s: %s: (expected/real value) %s %s %s %s', | ||
197 | self.peer.id[:4].decode("utf-8"), self.peer.cfg, | ||
198 | self.subsystem.ljust(12), self.name.ljust(30), self.value, op, | ||
199 | self.result, fail | ||
200 | ) | ||
179 | return self.fulfilled | 201 | return self.fulfilled |
180 | 202 | ||
181 | 203 | ||
@@ -195,8 +217,12 @@ class EqualStatisticsCondition(Condition): | |||
195 | 217 | ||
196 | def check(self): | 218 | def check(self): |
197 | if (self.fulfilled == False): | 219 | if (self.fulfilled == False): |
198 | self.result = self.peer.get_statistics_value(self.subsystem, self.name) | 220 | self.result = self.peer.get_statistics_value( |
199 | self.result2 = self.peer2.get_statistics_value(self.subsystem2, self.name2) | 221 | self.subsystem, self.name |
222 | ) | ||
223 | self.result2 = self.peer2.get_statistics_value( | ||
224 | self.subsystem2, self.name2 | ||
225 | ) | ||
200 | if (self.result == self.result2): | 226 | if (self.result == self.result2): |
201 | self.fulfilled = True | 227 | self.fulfilled = True |
202 | return True | 228 | return True |
@@ -206,8 +232,14 @@ class EqualStatisticsCondition(Condition): | |||
206 | return True | 232 | return True |
207 | 233 | ||
208 | def evaluate(self, failed_only): | 234 | def evaluate(self, failed_only): |
209 | if (((self.fulfilled == False) and (failed_only == True)) or (failed_only == False)): | 235 | if (((self.fulfilled == False) and (failed_only == True)) |
210 | 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) | 236 | or (failed_only == False)): |
237 | logger.debug( | ||
238 | '%s %s %s == %s %s %s %s %s', self.peer.id[:4], | ||
239 | self.subsystem.ljust(12), self.name.ljust(30), self.result, | ||
240 | self.peer2.id[:4], self.subsystem2.ljust(12), | ||
241 | self.name2.ljust(30), self.result2 | ||
242 | ) | ||
211 | return self.fulfilled | 243 | return self.fulfilled |
212 | 244 | ||
213 | 245 | ||
@@ -262,19 +294,23 @@ class Peer(object): | |||
262 | # print('ERROR! Peer using cfg ' + | 294 | # print('ERROR! Peer using cfg ' + |
263 | # self.cfg + | 295 | # self.cfg + |
264 | # ' could not be stopped') | 296 | # ' could not be stopped') |
265 | logger.debug('ERROR! Peer using cfg %s could not be stopped', self.cfg) | 297 | logger.debug( |
298 | 'ERROR! Peer using cfg %s could not be stopped', self.cfg | ||
299 | ) | ||
266 | self.started = False | 300 | self.started = False |
267 | return ret | 301 | return ret |
268 | else: | 302 | else: |
269 | return False | 303 | return False |
270 | 304 | ||
271 | def start(self): | 305 | def start(self): |
272 | os.unsetenv ("XDG_CONFIG_HOME") | 306 | os.unsetenv("XDG_CONFIG_HOME") |
273 | os.unsetenv ("XDG_DATA_HOME") | 307 | os.unsetenv("XDG_DATA_HOME") |
274 | os.unsetenv ("XDG_CACHE_HOME") | 308 | os.unsetenv("XDG_CACHE_HOME") |
275 | self.test.p("Starting peer using cfg " + self.cfg) | 309 | self.test.p("Starting peer using cfg " + self.cfg) |
276 | try: | 310 | try: |
277 | server = subprocess.Popen([self.test.gnunetarm, '-sq', '-c', self.cfg]) | 311 | server = subprocess.Popen([ |
312 | self.test.gnunetarm, '-sq', '-c', self.cfg | ||
313 | ]) | ||
278 | server.communicate() | 314 | server.communicate() |
279 | except OSError: | 315 | except OSError: |
280 | # print("Can not start peer") | 316 | # print("Can not start peer") |
@@ -285,7 +321,11 @@ class Peer(object): | |||
285 | test = '' | 321 | test = '' |
286 | try: | 322 | try: |
287 | server = pexpect() | 323 | server = pexpect() |
288 | server.spawn(None, [self.test.gnunetpeerinfo, '-c', self.cfg, '-s'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | 324 | server.spawn( |
325 | None, [self.test.gnunetpeerinfo, '-c', self.cfg, '-s'], | ||
326 | stdout=subprocess.PIPE, | ||
327 | stderr=subprocess.STDOUT | ||
328 | ) | ||
289 | test = server.read("stdout", 1024) | 329 | test = server.read("stdout", 1024) |
290 | except OSError: | 330 | except OSError: |
291 | # print("Can not get peer identity") | 331 | # print("Can not get peer identity") |
@@ -299,7 +339,9 @@ class Peer(object): | |||
299 | return False | 339 | return False |
300 | self.test.p("Stopping peer using cfg " + self.cfg) | 340 | self.test.p("Stopping peer using cfg " + self.cfg) |
301 | try: | 341 | try: |
302 | server = subprocess.Popen([self.test.gnunetarm, '-eq', '-c', self.cfg]) | 342 | server = subprocess.Popen([ |
343 | self.test.gnunetarm, '-eq', '-c', self.cfg | ||
344 | ]) | ||
303 | server.communicate() | 345 | server.communicate() |
304 | except OSError: | 346 | except OSError: |
305 | # print("Can not stop peer") | 347 | # print("Can not stop peer") |
@@ -310,7 +352,14 @@ class Peer(object): | |||
310 | 352 | ||
311 | def get_statistics_value(self, subsystem, name): | 353 | def get_statistics_value(self, subsystem, name): |
312 | server = pexpect() | 354 | server = pexpect() |
313 | server.spawn(None, [self.test.gnunetstatistics, '-c', self.cfg, '-q', '-n', name, '-s', subsystem], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | 355 | server.spawn( |
356 | None, [ | ||
357 | self.test.gnunetstatistics, '-c', self.cfg, '-q', '-n', name, | ||
358 | '-s', subsystem | ||
359 | ], | ||
360 | stdout=subprocess.PIPE, | ||
361 | stderr=subprocess.STDOUT | ||
362 | ) | ||
314 | # server.expect ("stdout", re.compile (r"")) | 363 | # server.expect ("stdout", re.compile (r"")) |
315 | test = server.read("stdout", 10240) | 364 | test = server.read("stdout", 10240) |
316 | tests = test.partition(b'\n') | 365 | tests = test.partition(b'\n') |
@@ -319,9 +368,14 @@ class Peer(object): | |||
319 | tests = (tests[0][:-1], tests[1], tests[2]) | 368 | tests = (tests[0][:-1], tests[1], tests[2]) |
320 | tests = tests[0] | 369 | tests = tests[0] |
321 | result = tests.decode("utf-8").strip() | 370 | result = tests.decode("utf-8").strip() |
322 | logger.debug('running gnunet-statistics %s for %s "/" %s yields %s', self.cfg, name, subsystem, result) | 371 | logger.debug( |
372 | 'running gnunet-statistics %s for %s "/" %s yields %s', self.cfg, | ||
373 | name, subsystem, result | ||
374 | ) | ||
323 | if (result.isdigit() == True): | 375 | if (result.isdigit() == True): |
324 | return result | 376 | return result |
325 | else: | 377 | else: |
326 | logger.debug('Invalid statistics value: %s is not a number!', result) | 378 | logger.debug( |
379 | 'Invalid statistics value: %s is not a number!', result | ||
380 | ) | ||
327 | return -1 | 381 | 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 | |||
32 | from gnunet_testing import Condition | 32 | from gnunet_testing import Condition |
33 | from gnunet_testing import * | 33 | from gnunet_testing import * |
34 | 34 | ||
35 | |||
36 | # | 35 | # |
37 | # This test tests if a fresh peer bootstraps from a hostlist server and then | 36 | # This test tests if a fresh peer bootstraps from a hostlist server and then |
38 | # successfully connects to the server | 37 | # successfully connects to the server |
@@ -124,6 +123,7 @@ def check(): | |||
124 | 123 | ||
125 | check.run_blocking(check_timeout, success_cont, fail_cont) | 124 | check.run_blocking(check_timeout, success_cont, fail_cont) |
126 | 125 | ||
126 | |||
127 | # | 127 | # |
128 | # Test execution | 128 | # Test execution |
129 | # | 129 | # |
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 @@ | |||
11 | # WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | # WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | # Affero General Public License for more details. | 13 | # Affero General Public License for more details. |
14 | # | 14 | # |
15 | # You should have received a copy of the GNU Affero General Public License | 15 | # You should have received a copy of the GNU Affero General Public License |
16 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | # | 17 | # |
@@ -113,9 +113,13 @@ def check_connect(): | |||
113 | check.add(StatisticsCondition(client, 'dht', '# peers connected', 2)) | 113 | check.add(StatisticsCondition(client, 'dht', '# peers connected', 2)) |
114 | check.add(StatisticsCondition(client, 'fs', '# peers connected', 2)) | 114 | check.add(StatisticsCondition(client, 'fs', '# peers connected', 2)) |
115 | 115 | ||
116 | check.add(StatisticsCondition(client_nat, 'transport', '# peers connected', 2)) | 116 | check.add( |
117 | StatisticsCondition(client_nat, 'transport', '# peers connected', 2) | ||
118 | ) | ||
117 | check.add(StatisticsCondition(client_nat, 'core', '# peers connected', 2)) | 119 | check.add(StatisticsCondition(client_nat, 'core', '# peers connected', 2)) |
118 | check.add(StatisticsCondition(client_nat, 'topology', '# peers connected', 2)) | 120 | check.add( |
121 | StatisticsCondition(client_nat, 'topology', '# peers connected', 2) | ||
122 | ) | ||
119 | check.add(StatisticsCondition(client_nat, 'dht', '# peers connected', 2)) | 123 | check.add(StatisticsCondition(client_nat, 'dht', '# peers connected', 2)) |
120 | check.add(StatisticsCondition(client_nat, 'fs', '# peers connected', 2)) | 124 | check.add(StatisticsCondition(client_nat, 'fs', '# peers connected', 2)) |
121 | 125 | ||
@@ -127,6 +131,7 @@ def check_connect(): | |||
127 | 131 | ||
128 | check.run_blocking(check_timeout, success_cont, fail_cont) | 132 | check.run_blocking(check_timeout, success_cont, fail_cont) |
129 | 133 | ||
134 | |||
130 | # | 135 | # |
131 | # Test execution | 136 | # Test execution |
132 | # | 137 | # |
@@ -199,7 +204,8 @@ def run(): | |||
199 | cleanup() | 204 | cleanup() |
200 | sys.exit(success) | 205 | sys.exit(success) |
201 | 206 | ||
202 | if ((client.started == True) and (client_nat.started == True) and (server.started == True)): | 207 | if ((client.started == True) and (client_nat.started == True) |
208 | and (server.started == True)): | ||
203 | test.p('Peers started, running check') | 209 | test.p('Peers started, running check') |
204 | check_connect() | 210 | check_connect() |
205 | 211 | ||
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 | |||
32 | from gnunet_testing import Condition | 32 | from gnunet_testing import Condition |
33 | from gnunet_testing import * | 33 | from gnunet_testing import * |
34 | 34 | ||
35 | |||
36 | # | 35 | # |
37 | # This test tests if a fresh peer bootstraps from a hostlist server and then | 36 | # This test tests if a fresh peer bootstraps from a hostlist server and then |
38 | # successfully connects to the server. When both peers are connected | 37 | # successfully connects to the server. When both peers are connected |
@@ -48,158 +47,169 @@ verbose = True | |||
48 | check_timeout = 180 | 47 | check_timeout = 180 |
49 | 48 | ||
50 | if os.name == "nt": | 49 | if os.name == "nt": |
51 | tmp = os.getenv ("TEMP") | 50 | tmp = os.getenv("TEMP") |
52 | signals = [signal.SIGTERM, signal.SIGINT] | 51 | signals = [signal.SIGTERM, signal.SIGINT] |
53 | else: | 52 | else: |
54 | tmp = "/tmp" | 53 | tmp = "/tmp" |
55 | signals = [signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGQUIT] | 54 | signals = [signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGQUIT] |
56 | 55 | ||
57 | def cleanup_onerror (function, path, excinfo): | 56 | |
58 | import stat | 57 | def cleanup_onerror(function, path, excinfo): |
59 | if not os.path.exists (path): | 58 | import stat |
60 | pass | 59 | if not os.path.exists(path): |
61 | elif not os.access(path, os.W_OK): | 60 | pass |
62 | # Is the error an access error ? | 61 | elif not os.access(path, os.W_OK): |
63 | os.chmod (path, stat.S_IWUSR) | 62 | # Is the error an access error ? |
64 | function (path) | 63 | os.chmod(path, stat.S_IWUSR) |
65 | else: | 64 | function(path) |
66 | raise | 65 | else: |
67 | 66 | raise | |
68 | def cleanup (): | 67 | |
69 | shutil.rmtree (os.path.join (tmp, "c_bootstrap_server"), False, cleanup_onerror) | 68 | |
70 | shutil.rmtree (os.path.join (tmp, "c_no_nat_client"), False, cleanup_onerror) | 69 | def cleanup(): |
71 | 70 | shutil.rmtree( | |
72 | 71 | os.path.join(tmp, "c_bootstrap_server"), False, cleanup_onerror | |
73 | def success_disconnect_cont (check): | 72 | ) |
74 | print('Peers disconnected successfully') | 73 | shutil.rmtree(os.path.join(tmp, "c_no_nat_client"), False, cleanup_onerror) |
75 | global success | 74 | |
76 | success = True; | 75 | |
77 | 76 | def success_disconnect_cont(check): | |
78 | 77 | print('Peers disconnected successfully') | |
79 | def fail_disconnect_cont (check): | 78 | global success |
80 | global success | 79 | success = True |
81 | success = False; | 80 | |
82 | print('Peers failed to disconnect') | 81 | |
83 | check.evaluate(True) | 82 | def fail_disconnect_cont(check): |
84 | 83 | global success | |
85 | def check_disconnect (): | 84 | success = False |
86 | test.p ('Shutting down bootstrap server') | 85 | print('Peers failed to disconnect') |
87 | server.stop () | 86 | check.evaluate(True) |
88 | check = Check (test) | 87 | |
89 | check.add (StatisticsCondition (client, 'transport', '# peers connected',0)) | 88 | |
90 | check.add (StatisticsCondition (client, 'core', '# peers connected',0)) | 89 | def check_disconnect(): |
91 | check.add (StatisticsCondition (client, 'topology', '# peers connected',0)) | 90 | test.p('Shutting down bootstrap server') |
92 | check.add (StatisticsCondition (client, 'dht', '# peers connected',0)) | 91 | server.stop() |
93 | check.add (StatisticsCondition (client, 'fs', '# peers connected',0)) | 92 | check = Check(test) |
94 | check.run_blocking (check_timeout, success_disconnect_cont, fail_disconnect_cont) | 93 | check.add(StatisticsCondition(client, 'transport', '# peers connected', 0)) |
95 | 94 | check.add(StatisticsCondition(client, 'core', '# peers connected', 0)) | |
96 | 95 | check.add(StatisticsCondition(client, 'topology', '# peers connected', 0)) | |
97 | def success_connect_cont (check): | 96 | check.add(StatisticsCondition(client, 'dht', '# peers connected', 0)) |
98 | print('Peers connected successfully') | 97 | check.add(StatisticsCondition(client, 'fs', '# peers connected', 0)) |
99 | check_disconnect () | 98 | check.run_blocking( |
100 | 99 | check_timeout, success_disconnect_cont, fail_disconnect_cont | |
101 | 100 | ) | |
102 | def fail_connect_cont (check): | 101 | |
103 | global success | 102 | |
104 | success= False | 103 | def success_connect_cont(check): |
105 | print('Peers failed to connected!') | 104 | print('Peers connected successfully') |
106 | check.evaluate(True) | 105 | check_disconnect() |
107 | 106 | ||
108 | 107 | ||
109 | def check_connect (): | 108 | def fail_connect_cont(check): |
110 | check = Check (test) | 109 | global success |
111 | check.add (StatisticsCondition (server, 'transport', '# peers connected',1)) | 110 | success = False |
112 | check.add (StatisticsCondition (server, 'core', '# peers connected',1)) | 111 | print('Peers failed to connected!') |
113 | check.add (StatisticsCondition (server, 'topology', '# peers connected',1)) | 112 | check.evaluate(True) |
114 | check.add (StatisticsCondition (server, 'dht', '# peers connected',1)) | 113 | |
115 | check.add (StatisticsCondition (server, 'fs', '# peers connected',1)) | 114 | |
116 | 115 | def check_connect(): | |
117 | check.add (StatisticsCondition (client, 'transport', '# peers connected',1)) | 116 | check = Check(test) |
118 | check.add (StatisticsCondition (client, 'core', '# peers connected',1)) | 117 | check.add(StatisticsCondition(server, 'transport', '# peers connected', 1)) |
119 | check.add (StatisticsCondition (client, 'topology', '# peers connected',1)) | 118 | check.add(StatisticsCondition(server, 'core', '# peers connected', 1)) |
120 | check.add (StatisticsCondition (client, 'dht', '# peers connected',1)) | 119 | check.add(StatisticsCondition(server, 'topology', '# peers connected', 1)) |
121 | check.add (StatisticsCondition (client, 'fs', '# peers connected',1)) | 120 | check.add(StatisticsCondition(server, 'dht', '# peers connected', 1)) |
122 | 121 | check.add(StatisticsCondition(server, 'fs', '# peers connected', 1)) | |
123 | check.run_blocking (check_timeout, success_connect_cont, fail_connect_cont) | 122 | |
123 | check.add(StatisticsCondition(client, 'transport', '# peers connected', 1)) | ||
124 | check.add(StatisticsCondition(client, 'core', '# peers connected', 1)) | ||
125 | check.add(StatisticsCondition(client, 'topology', '# peers connected', 1)) | ||
126 | check.add(StatisticsCondition(client, 'dht', '# peers connected', 1)) | ||
127 | check.add(StatisticsCondition(client, 'fs', '# peers connected', 1)) | ||
128 | |||
129 | check.run_blocking(check_timeout, success_connect_cont, fail_connect_cont) | ||
130 | |||
124 | 131 | ||
125 | # | 132 | # |
126 | # Test execution | 133 | # Test execution |
127 | # | 134 | # |
128 | 135 | ||
129 | def SigHandler(signum = None, frame = None): | 136 | |
130 | global success | 137 | def SigHandler(signum=None, frame=None): |
131 | global server | 138 | global success |
132 | global client | 139 | global server |
133 | 140 | global client | |
134 | print('Test was aborted!') | 141 | |
135 | if (None != server): | 142 | print('Test was aborted!') |
136 | server.stop () | 143 | if (None != server): |
137 | if (None != client): | 144 | server.stop() |
138 | client.stop () | 145 | if (None != client): |
139 | cleanup () | 146 | client.stop() |
140 | sys.exit(success) | 147 | cleanup() |
141 | 148 | sys.exit(success) | |
142 | def run (): | 149 | |
143 | global success | 150 | |
144 | global test | 151 | def run(): |
145 | global server | 152 | global success |
146 | global client | 153 | global test |
147 | 154 | global server | |
148 | server = None | 155 | global client |
149 | client = None | 156 | |
150 | success = False | 157 | server = None |
151 | 158 | client = None | |
152 | for sig in signals: | 159 | success = False |
153 | signal.signal(sig, SigHandler) | 160 | |
154 | 161 | for sig in signals: | |
155 | test = Test ('test_integration_bootstrap_and_connect.py', verbose) | 162 | signal.signal(sig, SigHandler) |
156 | cleanup () | 163 | |
157 | 164 | test = Test('test_integration_bootstrap_and_connect.py', verbose) | |
158 | server = Peer(test, './confs/c_bootstrap_server.conf'); | 165 | cleanup() |
159 | client = Peer(test, './confs/c_no_nat_client.conf'); | 166 | |
160 | 167 | server = Peer(test, './confs/c_bootstrap_server.conf') | |
161 | if (True != server.start()): | 168 | client = Peer(test, './confs/c_no_nat_client.conf') |
162 | print('Failed to start server') | 169 | |
163 | if (None != server): | 170 | if (True != server.start()): |
164 | server.stop () | 171 | print('Failed to start server') |
165 | cleanup () | 172 | if (None != server): |
166 | sys.exit(success) | 173 | server.stop() |
167 | 174 | cleanup() | |
168 | # Give the server time to start | 175 | sys.exit(success) |
169 | time.sleep(5) | 176 | |
170 | 177 | # Give the server time to start | |
171 | if (True != client.start()): | 178 | time.sleep(5) |
172 | print('Failed to start client') | 179 | |
173 | if (None != server): | 180 | if (True != client.start()): |
174 | server.stop () | 181 | print('Failed to start client') |
175 | if (None != client): | 182 | if (None != server): |
176 | client.stop () | 183 | server.stop() |
177 | cleanup () | 184 | if (None != client): |
178 | sys.exit(success) | 185 | client.stop() |
179 | 186 | cleanup() | |
180 | if ((client.started == True) and (server.started == True)): | 187 | sys.exit(success) |
181 | test.p ('Peers started, running check') | 188 | |
182 | time.sleep(5) | 189 | if ((client.started == True) and (server.started == True)): |
183 | check_connect () | 190 | test.p('Peers started, running check') |
184 | server.stop () | 191 | time.sleep(5) |
185 | client.stop () | 192 | check_connect() |
186 | 193 | server.stop() | |
187 | cleanup () | 194 | client.stop() |
188 | 195 | ||
189 | if (success == False): | 196 | cleanup() |
190 | print ('Test failed') | 197 | |
191 | return False | 198 | if (success == False): |
192 | else: | 199 | print('Test failed') |
193 | return True | 200 | return False |
201 | else: | ||
202 | return True | ||
203 | |||
194 | 204 | ||
195 | try: | 205 | try: |
196 | run () | 206 | run() |
197 | except (KeyboardInterrupt, SystemExit): | 207 | except (KeyboardInterrupt, SystemExit): |
198 | print('Test interrupted') | 208 | print('Test interrupted') |
199 | server.stop () | 209 | server.stop() |
200 | client.stop () | 210 | client.stop() |
201 | cleanup () | 211 | cleanup() |
202 | if (success == False): | 212 | if (success == False): |
203 | sys.exit(1) | 213 | sys.exit(1) |
204 | else: | 214 | else: |
205 | sys.exit(0) | 215 | 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 | |||
32 | from gnunet_testing import Condition | 32 | from gnunet_testing import Condition |
33 | from gnunet_testing import * | 33 | from gnunet_testing import * |
34 | 34 | ||
35 | |||
36 | # | 35 | # |
37 | # This test tests if a fresh peer bootstraps from a hostlist server and then | 36 | # This test tests if a fresh peer bootstraps from a hostlist server and then |
38 | # successfully connects to the server. When both peers are connected | 37 | # successfully connects to the server. When both peers are connected |
@@ -68,7 +67,9 @@ def cleanup_onerror(function, path, excinfo): | |||
68 | 67 | ||
69 | 68 | ||
70 | def cleanup(): | 69 | def cleanup(): |
71 | shutil.rmtree(os.path.join(tmp, "c_bootstrap_server"), False, cleanup_onerror) | 70 | shutil.rmtree( |
71 | os.path.join(tmp, "c_bootstrap_server"), False, cleanup_onerror | ||
72 | ) | ||
72 | shutil.rmtree(os.path.join(tmp, "c_nat_client"), False, cleanup_onerror) | 73 | shutil.rmtree(os.path.join(tmp, "c_nat_client"), False, cleanup_onerror) |
73 | 74 | ||
74 | 75 | ||
@@ -80,7 +81,7 @@ def success_disconnect_cont(check): | |||
80 | 81 | ||
81 | def fail_disconnect_cont(check): | 82 | def fail_disconnect_cont(check): |
82 | global success | 83 | global success |
83 | success = False; | 84 | success = False |
84 | print('Peers failed to disconnect') | 85 | print('Peers failed to disconnect') |
85 | check.evaluate(True) | 86 | check.evaluate(True) |
86 | 87 | ||
@@ -96,7 +97,9 @@ def check_disconnect(): | |||
96 | check.add(StatisticsCondition(server, 'topology', '# peers connected', 0)) | 97 | check.add(StatisticsCondition(server, 'topology', '# peers connected', 0)) |
97 | check.add(StatisticsCondition(server, 'dht', '# peers connected', 0)) | 98 | check.add(StatisticsCondition(server, 'dht', '# peers connected', 0)) |
98 | check.add(StatisticsCondition(server, 'fs', '# peers connected', 0)) | 99 | check.add(StatisticsCondition(server, 'fs', '# peers connected', 0)) |
99 | check.run_blocking(check_timeout, success_disconnect_cont, fail_disconnect_cont) | 100 | check.run_blocking( |
101 | check_timeout, success_disconnect_cont, fail_disconnect_cont | ||
102 | ) | ||
100 | 103 | ||
101 | 104 | ||
102 | def success_connect_cont(check): | 105 | def success_connect_cont(check): |
@@ -115,9 +118,13 @@ def check_connect(): | |||
115 | global server | 118 | global server |
116 | global nat_client | 119 | global nat_client |
117 | check = Check(test) | 120 | check = Check(test) |
118 | check.add(StatisticsCondition(nat_client, 'transport', '# peers connected', 1)) | 121 | check.add( |
122 | StatisticsCondition(nat_client, 'transport', '# peers connected', 1) | ||
123 | ) | ||
119 | check.add(StatisticsCondition(nat_client, 'core', '# peers connected', 1)) | 124 | check.add(StatisticsCondition(nat_client, 'core', '# peers connected', 1)) |
120 | check.add(StatisticsCondition(nat_client, 'topology', '# peers connected', 1)) | 125 | check.add( |
126 | StatisticsCondition(nat_client, 'topology', '# peers connected', 1) | ||
127 | ) | ||
121 | check.add(StatisticsCondition(nat_client, 'dht', '# peers connected', 1)) | 128 | check.add(StatisticsCondition(nat_client, 'dht', '# peers connected', 1)) |
122 | check.add(StatisticsCondition(nat_client, 'fs', '# peers connected', 1)) | 129 | check.add(StatisticsCondition(nat_client, 'fs', '# peers connected', 1)) |
123 | 130 | ||
@@ -134,6 +141,7 @@ def check_connect(): | |||
134 | # Test execution | 141 | # Test execution |
135 | # | 142 | # |
136 | 143 | ||
144 | |||
137 | def SigHandler(signum=None, frame=None): | 145 | def SigHandler(signum=None, frame=None): |
138 | global success | 146 | global success |
139 | global server | 147 | global server |
@@ -204,7 +212,7 @@ def run(): | |||
204 | 212 | ||
205 | try: | 213 | try: |
206 | run() | 214 | run() |
207 | except(KeyboardInterrupt, SystemExit): | 215 | except (KeyboardInterrupt, SystemExit): |
208 | print('Test interrupted') | 216 | print('Test interrupted') |
209 | server.stop() | 217 | server.stop() |
210 | nat_client.stop() | 218 | 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 | |||
32 | from gnunet_testing import Condition | 32 | from gnunet_testing import Condition |
33 | from gnunet_testing import * | 33 | from gnunet_testing import * |
34 | 34 | ||
35 | |||
36 | # | 35 | # |
37 | # This test tests if a fresh peer bootstraps from a hostlist server and then | 36 | # This test tests if a fresh peer bootstraps from a hostlist server and then |
38 | # successfully connects to the server. When both peers are connected | 37 | # successfully connects to the server. When both peers are connected |
@@ -43,195 +42,196 @@ from gnunet_testing import * | |||
43 | 42 | ||
44 | #definitions | 43 | #definitions |
45 | 44 | ||
46 | |||
47 | testname = "test_integration_restart" | 45 | testname = "test_integration_restart" |
48 | verbose = True | 46 | verbose = True |
49 | check_timeout = 180 | 47 | check_timeout = 180 |
50 | 48 | ||
51 | if os.name == "nt": | 49 | if os.name == "nt": |
52 | tmp = os.getenv ("TEMP") | 50 | tmp = os.getenv("TEMP") |
53 | signals = [signal.SIGTERM, signal.SIGINT] | 51 | signals = [signal.SIGTERM, signal.SIGINT] |
54 | else: | 52 | else: |
55 | tmp = "/tmp" | 53 | tmp = "/tmp" |
56 | signals = [signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGQUIT] | 54 | signals = [signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGQUIT] |
57 | 55 | ||
58 | def cleanup_onerror (function, path, excinfo): | 56 | |
59 | import stat | 57 | def cleanup_onerror(function, path, excinfo): |
60 | if not os.path.exists (path): | 58 | import stat |
61 | pass | 59 | if not os.path.exists(path): |
62 | elif not os.access(path, os.W_OK): | 60 | pass |
63 | # Is the error an access error ? | 61 | elif not os.access(path, os.W_OK): |
64 | os.chmod (path, stat.S_IWUSR) | 62 | # Is the error an access error ? |
65 | function (path) | 63 | os.chmod(path, stat.S_IWUSR) |
66 | else: | 64 | function(path) |
67 | raise | 65 | else: |
68 | 66 | raise | |
69 | def cleanup (): | 67 | |
68 | |||
69 | def cleanup(): | ||
70 | retries = 10 | 70 | retries = 10 |
71 | path = os.path.join (tmp, "c_bootstrap_server") | 71 | path = os.path.join(tmp, "c_bootstrap_server") |
72 | test.p ("Removing " + path) | 72 | test.p("Removing " + path) |
73 | while ((os.path.exists(path)) and (retries > 0)): | 73 | while ((os.path.exists(path)) and (retries > 0)): |
74 | shutil.rmtree ((path), False, cleanup_onerror) | 74 | shutil.rmtree((path), False, cleanup_onerror) |
75 | time.sleep (1) | 75 | time.sleep(1) |
76 | retries -= 1 | 76 | retries -= 1 |
77 | if (os.path.exists(path)): | 77 | if (os.path.exists(path)): |
78 | test.p ("Failed to remove " + path) | 78 | test.p("Failed to remove " + path) |
79 | |||
80 | 79 | ||
81 | retries = 10 | 80 | retries = 10 |
82 | path = os.path.join (tmp, "c_no_nat_client") | 81 | path = os.path.join(tmp, "c_no_nat_client") |
83 | test.p ("Removing " + path) | 82 | test.p("Removing " + path) |
84 | while ((os.path.exists(path)) and (retries > 0)): | 83 | while ((os.path.exists(path)) and (retries > 0)): |
85 | shutil.rmtree ((path), False, cleanup_onerror) | 84 | shutil.rmtree((path), False, cleanup_onerror) |
86 | time.sleep (1) | 85 | time.sleep(1) |
87 | retries -= 1 | 86 | retries -= 1 |
88 | if (os.path.exists(path)): | 87 | if (os.path.exists(path)): |
89 | test.p ("Failed to remove " + path) | 88 | test.p("Failed to remove " + path) |
89 | |||
90 | 90 | ||
91 | def success_restart_cont (check): | 91 | def success_restart_cont(check): |
92 | global success | 92 | global success |
93 | print('Peers connected successfully after restart') | 93 | print('Peers connected successfully after restart') |
94 | server.stop () | 94 | server.stop() |
95 | client.stop () | 95 | client.stop() |
96 | success = True; | 96 | success = True |
97 | 97 | ||
98 | 98 | ||
99 | def fail_restart_cont (check): | 99 | def fail_restart_cont(check): |
100 | global success | 100 | global success |
101 | success = False; | 101 | success = False |
102 | print('Peers failed to connect after restart') | 102 | print('Peers failed to connect after restart') |
103 | check.evaluate(True) | 103 | check.evaluate(True) |
104 | 104 | ||
105 | 105 | ||
106 | def success_connect_cont (check): | 106 | def success_connect_cont(check): |
107 | print('Peers connected successfully') | 107 | print('Peers connected successfully') |
108 | server.stop () | 108 | server.stop() |
109 | client.stop () | 109 | client.stop() |
110 | 110 | ||
111 | time.sleep(5) | 111 | time.sleep(5) |
112 | 112 | ||
113 | test.p ('Restarting client & server') | 113 | test.p('Restarting client & server') |
114 | server.start () | 114 | server.start() |
115 | client.start () | 115 | client.start() |
116 | 116 | ||
117 | check = Check (test) | 117 | check = Check(test) |
118 | check.add (StatisticsCondition (client, 'transport', '# peers connected',1)) | 118 | check.add(StatisticsCondition(client, 'transport', '# peers connected', 1)) |
119 | check.add (StatisticsCondition (client, 'core', '# peers connected',1)) | 119 | check.add(StatisticsCondition(client, 'core', '# peers connected', 1)) |
120 | check.add (StatisticsCondition (client, 'topology', '# peers connected',1)) | 120 | check.add(StatisticsCondition(client, 'topology', '# peers connected', 1)) |
121 | check.add (StatisticsCondition (client, 'fs', '# peers connected',1)) | 121 | check.add(StatisticsCondition(client, 'fs', '# peers connected', 1)) |
122 | 122 | ||
123 | check.add (StatisticsCondition (server, 'transport', '# peers connected',1)) | 123 | check.add(StatisticsCondition(server, 'transport', '# peers connected', 1)) |
124 | check.add (StatisticsCondition (server, 'core', '# peers connected',1)) | 124 | check.add(StatisticsCondition(server, 'core', '# peers connected', 1)) |
125 | check.add (StatisticsCondition (server, 'topology', '# peers connected',1)) | 125 | check.add(StatisticsCondition(server, 'topology', '# peers connected', 1)) |
126 | check.add (StatisticsCondition (server, 'fs', '# peers connected',1)) | 126 | check.add(StatisticsCondition(server, 'fs', '# peers connected', 1)) |
127 | 127 | ||
128 | check.run_blocking (check_timeout, success_restart_cont, fail_restart_cont) | 128 | check.run_blocking(check_timeout, success_restart_cont, fail_restart_cont) |
129 | 129 | ||
130 | 130 | ||
131 | def fail_connect_cont (check): | 131 | def fail_connect_cont(check): |
132 | global success | 132 | global success |
133 | success= False; | 133 | success = False |
134 | print('Peers failed to connect') | 134 | print('Peers failed to connect') |
135 | check.evaluate(True) | 135 | check.evaluate(True) |
136 | 136 | ||
137 | 137 | ||
138 | def check_connect (): | 138 | def check_connect(): |
139 | check = Check (test) | 139 | check = Check(test) |
140 | check.add (StatisticsCondition (client, 'transport', '# peers connected',1)) | 140 | check.add(StatisticsCondition(client, 'transport', '# peers connected', 1)) |
141 | check.add (StatisticsCondition (client, 'core', '# peers connected',1)) | 141 | check.add(StatisticsCondition(client, 'core', '# peers connected', 1)) |
142 | check.add (StatisticsCondition (client, 'topology', '# peers connected',1)) | 142 | check.add(StatisticsCondition(client, 'topology', '# peers connected', 1)) |
143 | check.add (StatisticsCondition (client, 'fs', '# peers connected',1)) | 143 | check.add(StatisticsCondition(client, 'fs', '# peers connected', 1)) |
144 | 144 | ||
145 | check.add (StatisticsCondition (server, 'transport', '# peers connected',1)) | 145 | check.add(StatisticsCondition(server, 'transport', '# peers connected', 1)) |
146 | check.add (StatisticsCondition (server, 'core', '# peers connected',1)) | 146 | check.add(StatisticsCondition(server, 'core', '# peers connected', 1)) |
147 | check.add (StatisticsCondition (server, 'topology', '# peers connected',1)) | 147 | check.add(StatisticsCondition(server, 'topology', '# peers connected', 1)) |
148 | check.add (StatisticsCondition (server, 'fs', '# peers connected',1)) | 148 | check.add(StatisticsCondition(server, 'fs', '# peers connected', 1)) |
149 | |||
150 | check.run_blocking(check_timeout, success_connect_cont, fail_connect_cont) | ||
149 | 151 | ||
150 | check.run_blocking (check_timeout, success_connect_cont, fail_connect_cont) | ||
151 | 152 | ||
152 | # | 153 | # |
153 | # Test execution | 154 | # Test execution |
154 | # | 155 | # |
155 | 156 | ||
156 | 157 | ||
157 | def SigHandler(signum = None, frame = None): | 158 | def SigHandler(signum=None, frame=None): |
158 | global success | 159 | global success |
159 | global server | 160 | global server |
160 | global client | 161 | global client |
161 | |||
162 | print('Test was aborted!') | ||
163 | if (None != server): | ||
164 | server.stop () | ||
165 | if (None != client): | ||
166 | client.stop () | ||
167 | cleanup () | ||
168 | sys.exit(success) | ||
169 | 162 | ||
170 | def run (): | 163 | print('Test was aborted!') |
171 | global success | 164 | if (None != server): |
172 | global test | 165 | server.stop() |
173 | global server | 166 | if (None != client): |
174 | global client | 167 | client.stop() |
168 | cleanup() | ||
169 | sys.exit(success) | ||
175 | 170 | ||
176 | success = False | ||
177 | server = None | ||
178 | client = None | ||
179 | 171 | ||
180 | for sig in signals: | 172 | def run(): |
181 | signal.signal(sig, SigHandler) | 173 | global success |
174 | global test | ||
175 | global server | ||
176 | global client | ||
182 | 177 | ||
178 | success = False | ||
179 | server = None | ||
180 | client = None | ||
183 | 181 | ||
184 | test = Test ('test_integration_disconnect', verbose) | 182 | for sig in signals: |
185 | cleanup () | 183 | signal.signal(sig, SigHandler) |
186 | server = Peer(test, './confs/c_bootstrap_server.conf'); | ||
187 | server.start(); | ||
188 | 184 | ||
189 | client = Peer(test, './confs/c_no_nat_client.conf'); | 185 | test = Test('test_integration_disconnect', verbose) |
190 | client.start(); | 186 | cleanup() |
187 | server = Peer(test, './confs/c_bootstrap_server.conf') | ||
188 | server.start() | ||
191 | 189 | ||
190 | client = Peer(test, './confs/c_no_nat_client.conf') | ||
191 | client.start() | ||
192 | 192 | ||
193 | if (True != server.start()): | 193 | if (True != server.start()): |
194 | print('Failed to start server') | 194 | print('Failed to start server') |
195 | if (None != server): | 195 | if (None != server): |
196 | server.stop () | 196 | server.stop() |
197 | if (None != server): | 197 | if (None != server): |
198 | client.stop () | 198 | client.stop() |
199 | cleanup () | 199 | cleanup() |
200 | sys.exit(success) | 200 | sys.exit(success) |
201 | 201 | ||
202 | # Give the server time to start | 202 | # Give the server time to start |
203 | time.sleep(5) | 203 | time.sleep(5) |
204 | 204 | ||
205 | if (True != client.start()): | 205 | if (True != client.start()): |
206 | print('Failed to start client') | 206 | print('Failed to start client') |
207 | if (None != server): | 207 | if (None != server): |
208 | server.stop () | 208 | server.stop() |
209 | if (None != server): | 209 | if (None != server): |
210 | client.stop () | 210 | client.stop() |
211 | cleanup () | 211 | cleanup() |
212 | sys.exit(success) | 212 | sys.exit(success) |
213 | 213 | ||
214 | check_connect () | 214 | check_connect() |
215 | 215 | ||
216 | server.stop () | 216 | server.stop() |
217 | client.stop () | 217 | client.stop() |
218 | cleanup () | 218 | cleanup() |
219 | 219 | ||
220 | if (success == False): | 220 | if (success == False): |
221 | print ('Test failed') | 221 | print('Test failed') |
222 | return True | 222 | return True |
223 | else: | 223 | else: |
224 | return False | 224 | return False |
225 | 225 | ||
226 | 226 | ||
227 | try: | 227 | try: |
228 | run () | 228 | run() |
229 | except (KeyboardInterrupt, SystemExit): | 229 | except (KeyboardInterrupt, SystemExit): |
230 | print('Test interrupted') | 230 | print('Test interrupted') |
231 | server.stop () | 231 | server.stop() |
232 | client.stop () | 232 | client.stop() |
233 | cleanup () | 233 | cleanup() |
234 | if (success == False): | 234 | if (success == False): |
235 | sys.exit(1) | 235 | sys.exit(1) |
236 | else: | 236 | else: |
237 | sys.exit(0) | 237 | 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 | |||
32 | from gnunet_testing import Condition | 32 | from gnunet_testing import Condition |
33 | from gnunet_testing import * | 33 | from gnunet_testing import * |
34 | 34 | ||
35 | |||
36 | # | 35 | # |
37 | # This test tests if a fresh peer bootstraps from a hostlist server and then | 36 | # This test tests if a fresh peer bootstraps from a hostlist server and then |
38 | # successfully connects to the server. When both peers are connected | 37 | # successfully connects to the server. When both peers are connected |
@@ -43,7 +42,6 @@ from gnunet_testing import * | |||
43 | 42 | ||
44 | # definitions | 43 | # definitions |
45 | 44 | ||
46 | |||
47 | testname = "test_integration_restart" | 45 | testname = "test_integration_restart" |
48 | verbose = True | 46 | verbose = True |
49 | check_timeout = 180 | 47 | check_timeout = 180 |
@@ -82,7 +80,7 @@ def cleanup(): | |||
82 | retries = 10 | 80 | retries = 10 |
83 | path = os.path.join(tmp, "c_nat_client") | 81 | path = os.path.join(tmp, "c_nat_client") |
84 | test.p("Removing " + path) | 82 | test.p("Removing " + path) |
85 | while((os.path.exists(path)) and(retries > 0)): | 83 | while ((os.path.exists(path)) and (retries > 0)): |
86 | shutil.rmtree((path), False, cleanup_onerror) | 84 | shutil.rmtree((path), False, cleanup_onerror) |
87 | time.sleep(1) | 85 | time.sleep(1) |
88 | retries -= 1 | 86 | retries -= 1 |
@@ -91,18 +89,18 @@ def cleanup(): | |||
91 | 89 | ||
92 | 90 | ||
93 | def success_restart_cont(check): | 91 | def success_restart_cont(check): |
94 | global success | 92 | global success |
95 | print('Peers connected successfully after restart') | 93 | print('Peers connected successfully after restart') |
96 | server.stop() | 94 | server.stop() |
97 | client.stop() | 95 | client.stop() |
98 | success = True | 96 | success = True |
99 | 97 | ||
100 | 98 | ||
101 | def fail_restart_cont(check): | 99 | def fail_restart_cont(check): |
102 | global success | 100 | global success |
103 | success = False | 101 | success = False |
104 | print('Peers failed to connect after restart') | 102 | print('Peers failed to connect after restart') |
105 | check.evaluate(True) | 103 | check.evaluate(True) |
106 | 104 | ||
107 | 105 | ||
108 | def success_connect_cont(check): | 106 | def success_connect_cont(check): |
@@ -151,6 +149,7 @@ def check_connect(): | |||
151 | 149 | ||
152 | check.run_blocking(check_timeout, success_connect_cont, fail_connect_cont) | 150 | check.run_blocking(check_timeout, success_connect_cont, fail_connect_cont) |
153 | 151 | ||
152 | |||
154 | # | 153 | # |
155 | # Test execution | 154 | # Test execution |
156 | # | 155 | # |
@@ -227,7 +226,7 @@ def run(): | |||
227 | 226 | ||
228 | try: | 227 | try: |
229 | run() | 228 | run() |
230 | except(KeyboardInterrupt, SystemExit): | 229 | except (KeyboardInterrupt, SystemExit): |
231 | print('Test interrupted') | 230 | print('Test interrupted') |
232 | server.stop() | 231 | server.stop() |
233 | client.stop() | 232 | client.stop() |