- debug
[oweals/gnunet.git] / src / integration-tests / test_integration_disconnect.py.in
index 0397fafd231fc2e4ae6a4de9a276042b27f8f30c..2a863f8b2773a3f5b6aa863c959aaa6fda12b41f 100755 (executable)
@@ -24,7 +24,6 @@ import subprocess
 import re
 import shutil
 import time
-import pexpect
 from gnunet_testing import Peer
 from gnunet_testing import Test
 from gnunet_testing import Check
@@ -43,17 +42,17 @@ from gnunet_testing import *
 #definitions
 
 testname = "test_integration_disconnect"
-verbose = False
-check_timeout = 30
+verbose = True
+check_timeout = 180
 
+if os.name == "nt":
+  tmp = os.getenv ("TEMP")
+else:
+  tmp = "/tmp"
 
 def cleanup ():
-       if os.name == "nt":
-           shutil.rmtree (os.path.join (os.getenv ("TEMP"), "gnunet-test-fs-py-ns"), True)
-           shutil.rmtree (os.path.join (os.getenv ("TEMP"), "c_no_nat_client"), True)
-       else:
-           shutil.rmtree ("/tmp/c_bootstrap_server/", True)
-           shutil.rmtree ("/tmp/c_no_nat_client/", True)    
+    shutil.rmtree (os.path.join (tmp, "c_bootstrap_server"), True)
+    shutil.rmtree (os.path.join (tmp, "c_no_nat_client"), True)
 
 
 def success_disconnect_cont (check):
@@ -64,7 +63,7 @@ def success_disconnect_cont (check):
 def fail_disconnect_cont (check):    
     global success 
     success = False;
-    check.eval(True)   
+    check.evaluate(True)   
   
 
 def check_disconnect ():
@@ -73,7 +72,7 @@ def check_disconnect ():
   check = Check (test)
   check.add (StatisticsCondition (client, 'transport', '# peers connected',0))
   check.add (StatisticsCondition (client, 'core', '# neighbour entries allocated',0))  
-  check.add (StatisticsCondition (client, 'core', '# entries in session map',0))
+  check.add (StatisticsCondition (client, 'core', '# peers connected',0))
   check.add (StatisticsCondition (client, 'topology', '# peers connected',0))
   check.add (StatisticsCondition (client, 'fs', '# peers connected',0))
   check.run_blocking (check_timeout, success_disconnect_cont, fail_disconnect_cont)
@@ -86,54 +85,71 @@ def success_connect_cont (check):
 def fail_connect_cont (check):    
     global success 
     success= False;
-    check.eval(True)
+    check.evaluate(True)
 
 
 def check_connect ():
   check = Check (test)
   check.add (StatisticsCondition (client, 'transport', '# peers connected',1))
   check.add (StatisticsCondition (client, 'core', '# neighbour entries allocated',1))  
-  check.add (StatisticsCondition (client, 'core', '# entries in session map',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', '# neighbour entries allocated',1))  
-  check.add (StatisticsCondition (server, 'core', '# entries in session map',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 (10, success_connect_cont, fail_connect_cont)
-
-# 
-# Test execution
-# 
+  check.run_blocking (check_timeout, success_connect_cont, fail_connect_cont)
 
 # 
 # Test execution
 # 
-success = False
-
-test = Test ('test_integration_disconnect', verbose)
-
-server = Peer(test, './confs/c_bootstrap_server.conf');
-server.start();
-
-client = Peer(test, './confs/c_no_nat_client.conf');
-client.start();
-
 
-if ((client.started == True) and (server.started == True)):
-    test.p ('Peers started, running check')
-    check_connect ()
+def run ():
+       global success
+       global test
+       global server
+       global client
        
-server.stop ()    
-client.stop ()
-
-cleanup ()
+       success = False
+       
+       test = Test ('test_integration_disconnect', verbose)
+       
+       server = Peer(test, './confs/c_bootstrap_server.conf');
+       server.start();
+       
+       client = Peer(test, './confs/c_no_nat_client.conf');
+       client.start();
+       
+       
+       if ((client.started == True) and (server.started == True)):
+           test.p ('Peers started, running check')
+           check_connect ()
+               
+       server.stop ()    
+       client.stop ()
+       
+       cleanup ()
+       
+       if (success == False):
+               print ('Test failed')
+               return True
+       else:
+               return False
 
+       
+try:
+    run ()
+except (KeyboardInterrupt, SystemExit):    
+    print 'Test interrupted'
+    server.stop ()
+    client.stop ()
+    cleanup ()
 if (success == False):
-       print ('Test failed')
-       exit (1)
+       sys.exit(1)   
 else:
-       exit (0)
+       sys.exit(0)    
+       
\ No newline at end of file