Fix and test bootstrapper hash cache reload from db
This commit is contained in:
parent
de8286829a
commit
866346b059
2 changed files with 23 additions and 1 deletions
|
@ -26,7 +26,7 @@ class BootstrapperDb(Db.Db):
|
||||||
|
|
||||||
def updateHashCache(self):
|
def updateHashCache(self):
|
||||||
res = self.execute("SELECT * FROM hash")
|
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))
|
self.log.debug("Loaded %s hash_ids" % len(self.hash_ids))
|
||||||
|
|
||||||
def checkTables(self):
|
def checkTables(self):
|
||||||
|
|
|
@ -27,6 +27,28 @@ def bootstrapper_db(request):
|
||||||
|
|
||||||
@pytest.mark.usefixtures("resetSettings")
|
@pytest.mark.usefixtures("resetSettings")
|
||||||
class TestBootstrapper:
|
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):
|
def testBootstrapperDb(self, file_server, bootstrapper_db):
|
||||||
ip_type = helper.getIpType(file_server.ip)
|
ip_type = helper.getIpType(file_server.ip)
|
||||||
peer = Peer(file_server.ip, 1544, connection_server=file_server)
|
peer = Peer(file_server.ip, 1544, connection_server=file_server)
|
||||||
|
|
Loading…
Reference in a new issue