Skip to content

Commit

Permalink
Fix and test bootstrapper hash cache reload from db
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcutme committed Jul 17, 2019
1 parent de82868 commit 866346b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion plugins/disabled-Bootstrapper/BootstrapperDb.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def cleanup(self):

def updateHashCache(self):
res = self.execute("SELECT * FROM hash")
self.hash_ids = {str(row["hash"]): row["hash_id"] for row in res}
self.hash_ids = {row["hash"]: row["hash_id"] for row in res}
self.log.debug("Loaded %s hash_ids" % len(self.hash_ids))

def checkTables(self):
Expand Down
22 changes: 22 additions & 0 deletions plugins/disabled-Bootstrapper/Test/TestBootstrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,28 @@ def cleanup():

@pytest.mark.usefixtures("resetSettings")
class TestBootstrapper:
def testHashCache(self, file_server, bootstrapper_db):
ip_type = helper.getIpType(file_server.ip)
peer = Peer(file_server.ip, 1544, connection_server=file_server)
hash1 = hashlib.sha256(b"site1").digest()
hash2 = hashlib.sha256(b"site2").digest()
hash3 = hashlib.sha256(b"site3").digest()

# Verify empty result
res = peer.request("announce", {
"hashes": [hash1, hash2],
"port": 15441, "need_types": [ip_type], "need_num": 10, "add": [ip_type]
})

assert len(res["peers"][0][ip_type]) == 0 # Empty result

hash_ids_before = bootstrapper_db.hash_ids.copy()

bootstrapper_db.updateHashCache()

assert hash_ids_before == bootstrapper_db.hash_ids


def testBootstrapperDb(self, file_server, bootstrapper_db):
ip_type = helper.getIpType(file_server.ip)
peer = Peer(file_server.ip, 1544, connection_server=file_server)
Expand Down

0 comments on commit 866346b

Please sign in to comment.