+ added more tests
* fixed chdir home bug * fixed some tests creating normal data dir
This commit is contained in:
		
							parent
							
								
									665cb0c732
								
							
						
					
					
						commit
						60d2ebfaed
					
				
					 20 changed files with 139 additions and 55 deletions
				
			
		|  | @ -1,9 +1,17 @@ | |||
| ''' | ||||
|     Onionr - Private P2P Communication | ||||
| """Onionr - Private P2P Communication. | ||||
| 
 | ||||
|     Cleanup old Onionr blocks and forward secrecy keys using the communicator. Ran from a timer usually | ||||
| ''' | ||||
| ''' | ||||
| Cleanup old Onionr blocks and forward secrecy keys using the communicator. | ||||
| Ran from a communicator timer usually | ||||
| """ | ||||
| import sqlite3 | ||||
| import logger | ||||
| from onionrusers import onionrusers | ||||
| from onionrutils import epoch | ||||
| from coredb import blockmetadb, dbfiles | ||||
| import onionrstorage | ||||
| from onionrstorage import removeblock | ||||
| from onionrblocks import onionrblacklist | ||||
| """ | ||||
|     This program is free software: you can redistribute it and/or modify | ||||
|     it under the terms of the GNU General Public License as published by | ||||
|     the Free Software Foundation, either version 3 of the License, or | ||||
|  | @ -16,15 +24,8 @@ | |||
| 
 | ||||
|     You should have received a copy of the GNU General Public License | ||||
|     along with this program.  If not, see <https://www.gnu.org/licenses/>. | ||||
| ''' | ||||
| import sqlite3 | ||||
| import logger | ||||
| from onionrusers import onionrusers | ||||
| from onionrutils import epoch | ||||
| from coredb import blockmetadb, dbfiles | ||||
| import onionrstorage | ||||
| from onionrstorage import removeblock | ||||
| from onionrblocks import onionrblacklist | ||||
| """ | ||||
| 
 | ||||
| 
 | ||||
| def __remove_from_upload(comm_inst, block_hash: str): | ||||
|     try: | ||||
|  | @ -32,8 +33,9 @@ def __remove_from_upload(comm_inst, block_hash: str): | |||
|     except ValueError: | ||||
|         pass | ||||
| 
 | ||||
| 
 | ||||
| def clean_old_blocks(comm_inst): | ||||
|     '''Delete old blocks if our disk allocation is full/near full, and also expired blocks''' | ||||
|     """Delete expired blocks + old blocks if disk allocation is near full""" | ||||
|     blacklist = onionrblacklist.OnionrBlackList() | ||||
|     # Delete expired blocks | ||||
|     for bHash in blockmetadb.expiredblocks.get_expired_blocks(): | ||||
|  | @ -56,8 +58,9 @@ def clean_old_blocks(comm_inst): | |||
| 
 | ||||
|     comm_inst.decrementThreadCount('clean_old_blocks') | ||||
| 
 | ||||
| 
 | ||||
| def clean_keys(comm_inst): | ||||
|     '''Delete expired forward secrecy keys''' | ||||
|     """Delete expired forward secrecy keys""" | ||||
|     conn = sqlite3.connect(dbfiles.user_id_info_db, timeout=10) | ||||
|     c = conn.cursor() | ||||
|     time = epoch.get_epoch() | ||||
|  | @ -75,4 +78,4 @@ def clean_keys(comm_inst): | |||
| 
 | ||||
|     onionrusers.deleteExpiredKeys() | ||||
| 
 | ||||
|     comm_inst.decrementThreadCount('clean_keys') | ||||
|     comm_inst.decrementThreadCount('clean_keys') | ||||
|  |  | |||
|  | @ -33,7 +33,7 @@ def add_to_block_DB(newHash, selfInsert=False, dataSaved=False): | |||
|     """ | ||||
| 
 | ||||
|     if blockmetadata.has_block(newHash): | ||||
|         raise | ||||
|         raise BlockMetaEntryExists | ||||
|     conn = sqlite3.connect(dbfiles.block_meta_db, timeout=onionrvalues.DATABASE_LOCK_TIMEOUT) | ||||
|     c = conn.cursor() | ||||
|     currentTime = epoch.get_epoch() + secrets.randbelow(301) | ||||
|  |  | |||
|  | @ -17,7 +17,7 @@ announce_cache = home + 'announcecache.dat' | |||
| export_location = home + 'block-export/' | ||||
| upload_list = home + 'upload-list.json' | ||||
| config_file = home + 'config.json' | ||||
| daemon_mark_file = app_root + '/daemon-true.txt' | ||||
| daemon_mark_file = home + '/daemon-true.txt' | ||||
| lock_file = home + 'onionr.lock' | ||||
| 
 | ||||
| site_cache = home + 'onionr-sites.txt' | ||||
|  |  | |||
|  | @ -5,6 +5,12 @@ This module loads in the Onionr arguments and their help messages | |||
| import sys | ||||
| import os | ||||
| 
 | ||||
| try: | ||||
|     if sys.argv[1] not in ('start', 'details', 'show-details'): | ||||
|         os.chdir(os.environ['ORIG_ONIONR_RUN_DIR']) | ||||
| except (KeyError, IndexError) as _: | ||||
|     pass | ||||
| 
 | ||||
| import logger | ||||
| import onionrexceptions | ||||
| import onionrplugins | ||||
|  | @ -74,19 +80,14 @@ def register(): | |||
|     try: | ||||
|         cmd = sys.argv[1] | ||||
|     except IndexError: | ||||
|         logger.debug("Detected Onionr run with no commands specified") | ||||
|         return | ||||
|         logger.info('Run with --help to see available commands', terminal=True) | ||||
|         sys.exit(10) | ||||
| 
 | ||||
|     is_help_cmd = False | ||||
|     if cmd.replace('--', '').lower() == 'help': | ||||
|         is_help_cmd = True | ||||
| 
 | ||||
|     try: | ||||
|         try: | ||||
|             if cmd not in ('start', 'details', 'show-details'): | ||||
|                 os.chdir(os.environ['ORIG_ONIONR_RUN_DIR']) | ||||
|         except KeyError: | ||||
|             pass | ||||
|         try: | ||||
|             arguments.get_func(cmd)() | ||||
|         except KeyboardInterrupt: | ||||
|  |  | |||
|  | @ -12,6 +12,7 @@ from . import ownnode | |||
| from .webpasstest import webpass_test | ||||
| from .osver import test_os_ver_endpoint | ||||
| from .clearnettor import test_clearnet_tor_request | ||||
| from .housekeeping import test_inserted_housekeeping | ||||
| """ | ||||
|     This program is free software: you can redistribute it and/or modify | ||||
|     it under the terms of the GNU General Public License as published by | ||||
|  | @ -34,7 +35,8 @@ RUN_TESTS = [uicheck.check_ui, | |||
|              stresstest.stress_test_block_insert, | ||||
|              webpass_test, | ||||
|              test_os_ver_endpoint, | ||||
|              test_clearnet_tor_request | ||||
|              test_clearnet_tor_request, | ||||
|              test_inserted_housekeeping | ||||
|              ] | ||||
| 
 | ||||
| SUCCESS_FILE = os.path.dirname(os.path.realpath(__file__)) + '/../../tests/runtime-result.txt' | ||||
|  |  | |||
							
								
								
									
										25
									
								
								src/runtests/housekeeping.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								src/runtests/housekeeping.py
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,25 @@ | |||
| import os | ||||
| 
 | ||||
| from gevent import sleep | ||||
| 
 | ||||
| from onionrblocks import insert | ||||
| import logger | ||||
| from coredb.blockmetadb import get_block_list | ||||
| from onionrutils import epoch | ||||
| 
 | ||||
| 
 | ||||
| def test_inserted_housekeeping(testmanager): | ||||
|     """Tests that inserted blocks are proprely deleted""" | ||||
|     bl = insert('testdata', expire=12) | ||||
|     wait_seconds = 132  # Wait two minutes plus expire time | ||||
|     count = 0 | ||||
|     if bl in get_block_list(): | ||||
|         while count < wait_seconds: | ||||
|             if bl in get_block_list(): | ||||
|                 sleep(1) | ||||
|                 count += 1 | ||||
|             else: | ||||
|                 return | ||||
|         raise ValueError('Inserted block with expiry not erased') | ||||
|     else: | ||||
|         raise ValueError('Inserted block in expiry test not present in list') | ||||
|  | @ -29,10 +29,6 @@ def identify_home() -> str: | |||
|     path = os.environ.get('ONIONR_HOME', None) | ||||
| 
 | ||||
| 
 | ||||
|     if path is not None and not os.getcwd().endswith('src') \ | ||||
|             and 'test' not in path: | ||||
|         path = 'src/' + path | ||||
| 
 | ||||
|     if path is None: | ||||
|         system = platform.system() | ||||
|         if system == 'Linux': | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue