diff options
Diffstat (limited to 'src/integration-tests/test_integration_disconnect.py.in')
-rwxr-xr-x | src/integration-tests/test_integration_disconnect.py.in | 295 |
1 files changed, 69 insertions, 226 deletions
diff --git a/src/integration-tests/test_integration_disconnect.py.in b/src/integration-tests/test_integration_disconnect.py.in index 3ded5dd7a..0397fafd2 100755 --- a/src/integration-tests/test_integration_disconnect.py.in +++ b/src/integration-tests/test_integration_disconnect.py.in | |||
@@ -25,6 +25,12 @@ import re | |||
25 | import shutil | 25 | import shutil |
26 | import time | 26 | import time |
27 | import pexpect | 27 | import pexpect |
28 | from gnunet_testing import Peer | ||
29 | from gnunet_testing import Test | ||
30 | from gnunet_testing import Check | ||
31 | from gnunet_testing import Condition | ||
32 | from gnunet_testing import * | ||
33 | |||
28 | 34 | ||
29 | # | 35 | # |
30 | # 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,61 +44,7 @@ import pexpect | |||
38 | 44 | ||
39 | testname = "test_integration_disconnect" | 45 | testname = "test_integration_disconnect" |
40 | verbose = False | 46 | verbose = False |
41 | gnunetarm = "" | 47 | check_timeout = 30 |
42 | gnunetstatistics = "" | ||
43 | success = False | ||
44 | timeout = 100 | ||
45 | |||
46 | #test conditions | ||
47 | |||
48 | |||
49 | def vprintf (msg): | ||
50 | if verbose == True: | ||
51 | print msg | ||
52 | |||
53 | def setup (): | ||
54 | srcdir = "../.." | ||
55 | gnunet_pyexpect_dir = os.path.join (srcdir, "contrib") | ||
56 | if gnunet_pyexpect_dir not in sys.path: | ||
57 | sys.path.append (gnunet_pyexpect_dir) | ||
58 | from gnunet_pyexpect import pexpect | ||
59 | global gnunetarm | ||
60 | global gnunetstatistics | ||
61 | if os.name == 'posix': | ||
62 | gnunetarm = 'gnunet-arm' | ||
63 | gnunetstatistics = 'gnunet-statistics' | ||
64 | elif os.name == 'nt': | ||
65 | gnunetarm = 'gnunet-arm.exe' | ||
66 | gnunetstatistics = 'gnunet-statistics.exe' | ||
67 | if os.name == "nt": | ||
68 | shutil.rmtree (os.path.join (os.getenv ("TEMP"), testname), True) | ||
69 | else: | ||
70 | shutil.rmtree ("/tmp/" + testname, True) | ||
71 | |||
72 | def start (): | ||
73 | vprintf ("Starting bootstrap server & client") | ||
74 | try: | ||
75 | server = subprocess.Popen ([gnunetarm, '-sq', '-c', './confs/c_bootstrap_server.conf']) | ||
76 | server.communicate () | ||
77 | except OSError: | ||
78 | print "Can not start bootstrap server, exiting..." | ||
79 | exit (1) | ||
80 | try: | ||
81 | client = subprocess.Popen ([gnunetarm, '-sq', '-c', 'confs/c_no_nat_client.conf']) | ||
82 | client.communicate () | ||
83 | except OSError: | ||
84 | print "Can not start bootstrap client, exiting..." | ||
85 | exit (1) | ||
86 | vprintf ("Bootstrap server & client started") | ||
87 | |||
88 | def stop (): | ||
89 | try: | ||
90 | client = subprocess.Popen ([gnunetarm, '-eq', '-c', 'confs/c_no_nat_client.conf']) | ||
91 | client.communicate () | ||
92 | except OSError: | ||
93 | print "Can not stop bootstrap client, exiting..." | ||
94 | exit (1) | ||
95 | vprintf ("Bootstrap client stopped") | ||
96 | 48 | ||
97 | 49 | ||
98 | def cleanup (): | 50 | def cleanup (): |
@@ -101,188 +53,82 @@ def cleanup (): | |||
101 | shutil.rmtree (os.path.join (os.getenv ("TEMP"), "c_no_nat_client"), True) | 53 | shutil.rmtree (os.path.join (os.getenv ("TEMP"), "c_no_nat_client"), True) |
102 | else: | 54 | else: |
103 | shutil.rmtree ("/tmp/c_bootstrap_server/", True) | 55 | shutil.rmtree ("/tmp/c_bootstrap_server/", True) |
104 | shutil.rmtree ("/tmp/c_no_nat_client/", True) | 56 | shutil.rmtree ("/tmp/c_no_nat_client/", True) |
105 | 57 | ||
106 | def check_statistics (conf, subsystem, name, value): | ||
107 | from gnunet_pyexpect import pexpect | ||
108 | server = pexpect () | ||
109 | server.spawn (None, [gnunetstatistics, '-c', conf ,'-q','-n', name, '-s', subsystem ], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | ||
110 | #server.expect ("stdout", re.compile (r"")) | ||
111 | test = server.read("stdout", 10240) | ||
112 | if (test.find(str(value)) == -1): | ||
113 | return False | ||
114 | else: | ||
115 | return True | ||
116 | |||
117 | |||
118 | 58 | ||
119 | def check_connect (): | 59 | def success_disconnect_cont (check): |
120 | server_transport_connected = False | 60 | global success |
121 | server_topology_connected = False | 61 | success = True; |
122 | server_core_connected = False | ||
123 | server_core_session_map = False | ||
124 | server_fs_connected = False | ||
125 | client_transport_connected = False | ||
126 | client_topology_connected = False | ||
127 | client_core_connected = False | ||
128 | client_core_session_map = False | ||
129 | client_fs_connected = False | ||
130 | |||
131 | connected = False | ||
132 | count = 1 | ||
133 | while ((connected == False) and (count <= timeout)): | ||
134 | # Perform checks | ||
135 | if ((False == server_transport_connected) and (True == check_statistics ('./confs/c_bootstrap_server.conf', 'transport', '# peers connected',1))): | ||
136 | server_transport_connected = True | ||
137 | vprintf ('Server transport services is connected') | ||
138 | |||
139 | if ((False == client_transport_connected) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'transport', '# peers connected',1))): | ||
140 | client_transport_connected = True | ||
141 | vprintf ('Client transport services is connected') | ||
142 | 62 | ||
143 | if ((False == server_core_connected) and (True == check_statistics ('./confs/c_bootstrap_server.conf', 'core', '# neighbour entries allocated',1))): | ||
144 | server_core_connected = True | ||
145 | vprintf ('Server core services is connected') | ||
146 | |||
147 | if ((False == client_core_connected) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'core', '# neighbour entries allocated',1))): | ||
148 | client_core_connected = True | ||
149 | vprintf ('Client core services is connected') | ||
150 | |||
151 | if ((False == client_core_session_map) and (True == check_statistics ('./confs/c_bootstrap_server.conf', 'core', '# entries in session map',1))): | ||
152 | client_core_session_map = True | ||
153 | vprintf ('Server core services is connected') | ||
154 | |||
155 | if ((False == server_core_session_map) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'core', '# entries in session map',1))): | ||
156 | server_core_session_map = True | ||
157 | vprintf ('Client core notifies about connected') | ||
158 | 63 | ||
159 | if ((False == server_topology_connected) and (True == check_statistics ('./confs/c_bootstrap_server.conf', 'topology', '# peers connected',1))): | 64 | def fail_disconnect_cont (check): |
160 | server_topology_connected = True | 65 | global success |
161 | vprintf ('Server topology services is connected') | 66 | success = False; |
162 | 67 | check.eval(True) | |
163 | if ((False == client_topology_connected) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'topology', '# peers connected',1))): | 68 | |
164 | client_topology_connected = True | ||
165 | vprintf ('Client topology services is connected') | ||
166 | |||
167 | if ((False == client_fs_connected) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'fs', '# peers connected',1))): | ||
168 | client_fs_connected = True | ||
169 | vprintf ('Client fs services is connected') | ||
170 | if ((False == server_fs_connected) and (True == check_statistics ('./confs/c_bootstrap_server.conf', 'fs', '# peers connected',1))): | ||
171 | server_fs_connected = True | ||
172 | vprintf ('Server fs services is connected') | ||
173 | |||
174 | # Check if conditions fulfilled | ||
175 | if ((True == client_transport_connected) and (True == server_transport_connected) and | ||
176 | (True == client_topology_connected) and (True == server_topology_connected) and | ||
177 | (True == client_core_connected) and (True == server_core_connected) and | ||
178 | (True == client_core_session_map) and (True == server_core_session_map) and | ||
179 | (True == client_fs_connected) and (True == server_fs_connected)): | ||
180 | connected = True | ||
181 | break | ||
182 | print '.', | ||
183 | time.sleep(1) | ||
184 | count += 1 | ||
185 | if (connected == False): | ||
186 | print '' | ||
187 | if (client_transport_connected == False): | ||
188 | print ('Client transport was NOT connected') | ||
189 | if (server_transport_connected == False): | ||
190 | print ('Server transport was NOT connected') | ||
191 | if (client_topology_connected == False): | ||
192 | print ('Client topology was NOT connected') | ||
193 | if (server_topology_connected == False): | ||
194 | print ('Server topology was NOT connected') | ||
195 | if (client_core_connected == False): | ||
196 | print ('Client core was NOT connected') | ||
197 | if (server_core_connected == False): | ||
198 | print ('Server core was NOT connected') | ||
199 | if (client_core_session_map == False): | ||
200 | print ('Client core sessions did NOT increase') | ||
201 | if (server_core_session_map == False): | ||
202 | print ('Server core sessions did NOT increase') | ||
203 | return False | ||
204 | else: | ||
205 | return True | ||
206 | 69 | ||
207 | def check_disconnect (): | 70 | def check_disconnect (): |
208 | vprintf ("Shutting down bootstrap server") | 71 | test.p ('Shutting down bootstrap server') |
209 | try: | 72 | server.stop () |
210 | server = subprocess.Popen ([gnunetarm, '-eq', '-c', './confs/c_bootstrap_server.conf']) | 73 | check = Check (test) |
211 | server.communicate () | 74 | check.add (StatisticsCondition (client, 'transport', '# peers connected',0)) |
212 | except OSError: | 75 | check.add (StatisticsCondition (client, 'core', '# neighbour entries allocated',0)) |
213 | print "Can not stop bootstrap server, exiting..." | 76 | check.add (StatisticsCondition (client, 'core', '# entries in session map',0)) |
214 | exit (1) | 77 | check.add (StatisticsCondition (client, 'topology', '# peers connected',0)) |
215 | 78 | check.add (StatisticsCondition (client, 'fs', '# peers connected',0)) | |
216 | client_transport_disconnected = False | 79 | check.run_blocking (check_timeout, success_disconnect_cont, fail_disconnect_cont) |
217 | client_topology_disconnected = False | 80 | |
218 | client_core_disconnected = False | 81 | |
219 | client_core_session_map = False | 82 | def success_connect_cont (check): |
220 | client_fs_disconnected = False | 83 | check_disconnect () |
221 | 84 | ||
222 | disconnected = False | 85 | |
223 | count = 1 | 86 | def fail_connect_cont (check): |
224 | while ((disconnected == False) and (count <= timeout)): | 87 | global success |
225 | if ((False == client_transport_disconnected) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'transport', '# peers connected',0))): | 88 | success= False; |
226 | client_transport_disconnected = True | 89 | check.eval(True) |
227 | vprintf ('Client transport services is disconnected') | 90 | |
228 | 91 | ||
229 | if ((False == client_core_disconnected) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'core', '# neighbour entries allocated',0))): | 92 | def check_connect (): |
230 | client_core_disconnected = True | 93 | check = Check (test) |
231 | vprintf ('Client core services is disconnected') | 94 | check.add (StatisticsCondition (client, 'transport', '# peers connected',1)) |
232 | 95 | check.add (StatisticsCondition (client, 'core', '# neighbour entries allocated',1)) | |
233 | if ((False == client_core_session_map) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'core', '# entries in session map',0))): | 96 | check.add (StatisticsCondition (client, 'core', '# entries in session map',1)) |
234 | client_core_session_map = True | 97 | check.add (StatisticsCondition (client, 'topology', '# peers connected',1)) |
235 | vprintf ('Client core notifies about disconnected') | 98 | check.add (StatisticsCondition (client, 'fs', '# peers connected',1)) |
236 | 99 | ||
237 | if ((False == client_topology_disconnected) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'topology', '# peers connected',0))): | 100 | check.add (StatisticsCondition (server, 'transport', '# peers connected',1)) |
238 | client_topology_disconnected = True | 101 | check.add (StatisticsCondition (server, 'core', '# neighbour entries allocated',1)) |
239 | vprintf ('Client topology services is disconnected') | 102 | check.add (StatisticsCondition (server, 'core', '# entries in session map',1)) |
240 | 103 | check.add (StatisticsCondition (server, 'topology', '# peers connected',1)) | |
241 | if ((False == client_fs_disconnected) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'fs', '# peers connected',0))): | 104 | check.add (StatisticsCondition (server, 'fs', '# peers connected',1)) |
242 | client_fs_disconnected = True | 105 | |
243 | vprintf ('Client fs services is disconnected') | 106 | check.run_blocking (10, success_connect_cont, fail_connect_cont) |
244 | 107 | ||
245 | # Check if conditions fulfilled | 108 | # |
246 | if ((True == client_transport_disconnected) and | 109 | # Test execution |
247 | (True == client_topology_disconnected) and | 110 | # |
248 | (True == client_core_disconnected) and | ||
249 | (True == client_core_session_map) and | ||
250 | (True == client_fs_disconnected)): | ||
251 | disconnected = True | ||
252 | break | ||
253 | print '.' | ||
254 | time.sleep(1) | ||
255 | count += 1 | ||
256 | if (disconnected == False): | ||
257 | print '' | ||
258 | if (client_transport_disconnected == False): | ||
259 | print ('Client transport was NOT disconnected') | ||
260 | if (client_topology_disconnected == False): | ||
261 | print ('Client topology was NOT disconnected') | ||
262 | if (client_core_disconnected == False): | ||
263 | print ('Client core was NOT disconnected') | ||
264 | if (client_core_session_map == False): | ||
265 | print ('Server core sessions did NOT decrease') | ||
266 | return False | ||
267 | else: | ||
268 | return True | ||
269 | 111 | ||
270 | # | 112 | # |
271 | # Test execution | 113 | # Test execution |
272 | # | 114 | # |
115 | success = False | ||
116 | |||
117 | test = Test ('test_integration_disconnect', verbose) | ||
273 | 118 | ||
274 | vprintf ("Running " + testname) | 119 | server = Peer(test, './confs/c_bootstrap_server.conf'); |
275 | setup () | 120 | server.start(); |
276 | start () | ||
277 | 121 | ||
278 | ret = check_connect () | 122 | client = Peer(test, './confs/c_no_nat_client.conf'); |
279 | if (ret == True): | 123 | client.start(); |
280 | vprintf ('Peers connected') | ||
281 | if (True == check_disconnect ()): | ||
282 | success = True | ||
283 | 124 | ||
284 | stop () | ||
285 | 125 | ||
126 | if ((client.started == True) and (server.started == True)): | ||
127 | test.p ('Peers started, running check') | ||
128 | check_connect () | ||
129 | |||
130 | server.stop () | ||
131 | client.stop () | ||
286 | 132 | ||
287 | cleanup () | 133 | cleanup () |
288 | 134 | ||
@@ -291,6 +137,3 @@ if (success == False): | |||
291 | exit (1) | 137 | exit (1) |
292 | else: | 138 | else: |
293 | exit (0) | 139 | exit (0) |
294 | |||
295 | |||
296 | |||