aboutsummaryrefslogtreecommitdiff
path: root/src/integration-tests/test_integration_reconnect.py.in
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-12-17 15:32:54 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-12-17 15:32:54 +0000
commit00b211d05bf9ba8a82d120237963c5e84e57afeb (patch)
tree0860a2f0fd4212f242235a08f7535ea7c55006a6 /src/integration-tests/test_integration_reconnect.py.in
parent2098bde27ecaa44210d225db9cf45773785e4ba4 (diff)
downloadgnunet-00b211d05bf9ba8a82d120237963c5e84e57afeb.tar.gz
gnunet-00b211d05bf9ba8a82d120237963c5e84e57afeb.zip
restructuring configs + enabling additional plugins
Diffstat (limited to 'src/integration-tests/test_integration_reconnect.py.in')
-rwxr-xr-xsrc/integration-tests/test_integration_reconnect.py.in225
1 files changed, 225 insertions, 0 deletions
diff --git a/src/integration-tests/test_integration_reconnect.py.in b/src/integration-tests/test_integration_reconnect.py.in
new file mode 100755
index 000000000..62bd4bd98
--- /dev/null
+++ b/src/integration-tests/test_integration_reconnect.py.in
@@ -0,0 +1,225 @@
1#!@PYTHON@
2# This file is part of GNUnet.
3# (C) 2010 Christian Grothoff (and other contributing authors)
4#
5# GNUnet is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published
7# by the Free Software Foundation; either version 2, or (at your
8# option) any later version.
9#
10# GNUnet is distributed in the hope that it will be useful, but
11# WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with GNUnet; see the file COPYING. If not, write to the
17# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18# Boston, MA 02111-1307, USA.
19#
20#
21import sys
22import os
23import subprocess
24import re
25import shutil
26import time
27import signal
28from gnunet_testing import Peer
29from gnunet_testing import Test
30from gnunet_testing import Check
31from gnunet_testing import Condition
32from gnunet_testing import *
33
34
35#
36# This test tests if a fresh peer bootstraps from a hostlist server and then
37# successfully connects to the server. When both peers are connected
38# in transport, core, topology, fs, botth peers are shutdown and restarted
39#
40# Conditions for successful exit:
41# Both peers have 1 connected peer in transport, core, topology, fs after restart
42
43#definitions
44
45
46testname = "test_integration_restart"
47verbose = True
48check_timeout = 180
49
50if os.name == "nt":
51 tmp = os.getenv ("TEMP")
52else:
53 tmp = "/tmp"
54
55def cleanup ():
56 retries = 10
57 path = os.path.join (tmp, "c_bootstrap_server")
58 test.p ("Removing " + path)
59 while ((os.path.exists(path)) and (retries > 0)):
60 shutil.rmtree ((path), False)
61 time.sleep (1)
62 retries -= 1
63 if (os.path.exists(path)):
64 test.p ("Failed to remove " + path)
65
66
67 retries = 10
68 path = os.path.join (tmp, "c_no_nat_client")
69 test.p ("Removing " + path)
70 while ((os.path.exists(path)) and (retries > 0)):
71 shutil.rmtree ((path), False)
72 time.sleep (1)
73 retries -= 1
74 if (os.path.exists(path)):
75 test.p ("Failed to remove " + path)
76
77def success_restart_cont (check):
78 global success
79 print 'Peers connected successfully after restart'
80 server.stop ()
81 client.stop ()
82 success = True;
83
84
85def fail_restart_cont (check):
86 global success
87 success = False;
88 print 'Peers failed to connect after restart'
89 check.evaluate(True)
90
91
92def success_connect_cont (check):
93 print 'Peers connected successfully'
94 server.stop ()
95 client.stop ()
96
97 time.sleep(5)
98
99 test.p ('Restarting client & server')
100 server.start ()
101 client.start ()
102
103 check = Check (test)
104 check.add (StatisticsCondition (client, 'transport', '# peers connected',1))
105 check.add (StatisticsCondition (client, 'core', '# neighbour entries allocated',1))
106 check.add (StatisticsCondition (client, 'core', '# peers connected',1))
107 check.add (StatisticsCondition (client, 'topology', '# peers connected',1))
108 check.add (StatisticsCondition (client, 'fs', '# peers connected',1))
109
110 check.add (StatisticsCondition (server, 'transport', '# peers connected',1))
111 check.add (StatisticsCondition (server, 'core', '# neighbour entries allocated',1))
112 check.add (StatisticsCondition (server, 'core', '# peers connected',1))
113 check.add (StatisticsCondition (server, 'topology', '# peers connected',1))
114 check.add (StatisticsCondition (server, 'fs', '# peers connected',1))
115
116 check.run_blocking (check_timeout, success_restart_cont, fail_restart_cont)
117
118
119def fail_connect_cont (check):
120 global success
121 success= False;
122 print 'Peers failed to connect'
123 check.evaluate(True)
124
125
126def check_connect ():
127 check = Check (test)
128 check.add (StatisticsCondition (client, 'transport', '# peers connected',1))
129 check.add (StatisticsCondition (client, 'core', '# neighbour entries allocated',1))
130 check.add (StatisticsCondition (client, 'core', '# peers connected',1))
131 check.add (StatisticsCondition (client, 'topology', '# peers connected',1))
132 check.add (StatisticsCondition (client, 'fs', '# peers connected',1))
133
134 check.add (StatisticsCondition (server, 'transport', '# peers connected',1))
135 check.add (StatisticsCondition (server, 'core', '# neighbour entries allocated',1))
136 check.add (StatisticsCondition (server, 'core', '# peers connected',1))
137 check.add (StatisticsCondition (server, 'topology', '# peers connected',1))
138 check.add (StatisticsCondition (server, 'fs', '# peers connected',1))
139
140 check.run_blocking (check_timeout, success_connect_cont, fail_connect_cont)
141
142#
143# Test execution
144#
145
146
147def SigHandler(signum = None, frame = None):
148 global success
149 global server
150 global client
151
152 print 'Test was aborted!'
153 if (None != server):
154 server.stop ()
155 if (None != server):
156 client.stop ()
157 cleanup ()
158 sys.exit(success)
159
160def run ():
161 global success
162 global test
163 global server
164 global client
165
166 success = False
167 server = None
168 client = None
169
170 for sig in [signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGQUIT]:
171 signal.signal(sig, SigHandler)
172
173
174 test = Test ('test_integration_disconnect', verbose)
175 cleanup ()
176 server = Peer(test, './confs/c_bootstrap_server.conf');
177 server.start();
178
179 client = Peer(test, './confs/c_no_nat_client.conf');
180 client.start();
181
182
183 if (True != server.start()):
184 print 'Failed to start server'
185 if (None != server):
186 server.stop ()
187 if (None != server):
188 client.stop ()
189 cleanup ()
190 sys.exit(success)
191 if (True != client.start()):
192 print 'Failed to start client'
193 if (None != server):
194 server.stop ()
195 if (None != server):
196 client.stop ()
197 cleanup ()
198 sys.exit(success)
199
200 check_connect ()
201
202 server.stop ()
203 client.stop ()
204 cleanup ()
205
206 if (success == False):
207 print ('Test failed')
208 return True
209 else:
210 return False
211
212
213try:
214 run ()
215except (KeyboardInterrupt, SystemExit):
216 print 'Test interrupted'
217 server.stop ()
218 client.stop ()
219 cleanup ()
220if (success == False):
221 sys.exit(1)
222else:
223 sys.exit(0)
224
225 \ No newline at end of file