From: Cameron Dale Date: Wed, 9 Jan 2008 04:45:21 +0000 (-0800) Subject: Make the MultiDHT test_store work for large number of nodes. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=08e747941eaa12ddf466a49e4dadf292758d6cd2;p=quix0rs-apt-p2p.git Make the MultiDHT test_store work for large number of nodes. It generated errors before as all the requests for get/store were sent out simultaneously, and some got lost (probably due to network queue lengths). Instead, send each request and wait for it to complete. --- diff --git a/apt_dht_Khashmir/DHT.py b/apt_dht_Khashmir/DHT.py index cfe07f0..36d7231 100644 --- a/apt_dht_Khashmir/DHT.py +++ b/apt_dht_Khashmir/DHT.py @@ -296,37 +296,32 @@ class TestMultiDHT(unittest.TestCase): d.addCallback(self.node_join, 1) return self.lastDefer - def value_stored(self, result, value): - self.stored -= 1 - if self.stored == 0: + def store_values(self, result, i = 0, j = 0): + if j > i: + j -= i+1 + i += 1 + if i == len(self.l): self.get_values() - - def store_values(self, result): - self.stored = 0 - for i in range(len(self.l)): - for j in range(0, i+1): - self.stored += 1 - d = self.l[j].storeValue(sha.new(str(self.startport+i)).digest(), str((self.startport+i)*(j+1))) - d.addCallback(self.value_stored, self.startport+i) + else: + d = self.l[j].storeValue(sha.new(str(self.startport+i)).digest(), str((self.startport+i)*(j+1))) + d.addCallback(self.store_values, i, j+1) - def check_values(self, result, values): - self.checked -= 1 - self.failUnless(len(result) == len(values)) - for v in result: - self.failUnless(v in values) - if self.checked == 0: + def get_values(self, result = None, check = None, i = 0, j = 0): + if result is not None: + self.failUnless(len(result) == len(check)) + for v in result: + self.failUnless(v in check) + if j >= len(self.l): + j -= len(self.l) + i += 1 + if i == len(self.l): self.lastDefer.callback(1) - - def get_values(self): - self.checked = 0 - for i in range(len(self.l)): - for j in random.sample(xrange(len(self.l)), max(len(self.l), 4)): - self.checked += 1 - d = self.l[i].getValue(sha.new(str(self.startport+j)).digest()) - check = [] - for k in range(self.startport+j, (self.startport+j)*(j+1)+1, self.startport+j): - check.append(str(k)) - d.addCallback(self.check_values, check) + else: + d = self.l[i].getValue(sha.new(str(self.startport+j)).digest()) + check = [] + for k in range(self.startport+j, (self.startport+j)*(j+1)+1, self.startport+j): + check.append(str(k)) + d.addCallback(self.get_values, check, i, j + random.randrange(1, min(len(self.l), 10))) def store_join(self, result, next_node): d = self.l[next_node].join()