Fix and test bootstrapper hash cache reload from db

This commit is contained in:
shortcutme 2019-07-17 16:29:54 +02:00
parent de8286829a
commit 866346b059
No known key found for this signature in database
GPG key ID: 5B63BAE6CB9613AE
2 changed files with 23 additions and 1 deletions

View file

@ -26,7 +26,7 @@ class BootstrapperDb(Db.Db):
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):

View file

@ -27,6 +27,28 @@ def bootstrapper_db(request):
@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)