diff options
Diffstat (limited to 'src/integration-tests/test_integration_disconnect.py.in')
-rwxr-xr-x | src/integration-tests/test_integration_disconnect.py.in | 300 |
1 files changed, 155 insertions, 145 deletions
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) |