Fixes memory leak bug regarding test db

This commit is contained in:
Sergi Delgado Segura
2019-11-14 15:04:55 +00:00
parent f65e2af675
commit ca3f6ee1b1
2 changed files with 16 additions and 5 deletions

View File

@@ -80,8 +80,18 @@ def test_load_appointments_db(db_manager):
assert set(values) == set(local_appointments.values()) and (len(values) == len(local_appointments))
def test_get_last_known_block(db_manager):
def test_get_last_known_block():
db_path = "empty_db"
# First we check if the db exists, and if so we delete it
if os.path.isdir(db_path):
shutil.rmtree(db_path)
# Check that the db can be created if it does not exist
db_manager = open_create_db(db_path)
# Trying to get any last block for either the watcher or the responder should return None for an empty db
for key in [WATCHER_LAST_BLOCK_KEY, RESPONDER_LAST_BLOCK_KEY]:
assert db_manager.get_last_known_block(key) is None
@@ -91,6 +101,9 @@ def test_get_last_known_block(db_manager):
db_manager.db.put(key.encode("utf-8"), block_hash.encode("utf-8"))
assert db_manager.get_last_known_block(key) == block_hash
# Removing test db
shutil.rmtree(db_path)
def test_create_entry(db_manager):
key = get_random_value_hex(32)