From: robk-tahoe Date: Fri, 4 Apr 2008 01:43:46 +0000 (-0700) Subject: key_generator: fix timing, make tests more robust X-Git-Url: https://git.rkrishnan.org/components/com_hotproperty/COPYING.TGPPL.html?a=commitdiff_plain;h=30eaaa78623487dc9234dd44c7fa4bbe82fbb6a5;p=tahoe-lafs%2Ftahoe-lafs.git key_generator: fix timing, make tests more robust previously there was an edge case in the timing of expected behaviour of the key_generator (w.r.t. the refresh delay and twisted/foolscap delivery). if it took >6s for a key to be generated, then it was possible for the pool refresh delay to transpire _during_ the synchronous creation of a key in remote_get_rsa_key_pair. this could lead to the timer elapsing during key creation and hence the pool being refilled before control returned to the client. this change ensures that the time window from a get key request until the key gen reactor blocks to refill the pool is the time since a request was answered, not since a request was asked. this causes the behaviour to match expectations, as embodied in test_keygen, even if the delay window is dropped to 0.1s --- diff --git a/src/allmydata/key_generator.py b/src/allmydata/key_generator.py index 964b2b38..61fa9b2e 100644 --- a/src/allmydata/key_generator.py +++ b/src/allmydata/key_generator.py @@ -65,8 +65,9 @@ class KeyGenerator(service.MultiService, foolscap.Referenceable): def remote_get_rsa_key_pair(self, key_size): self.vlog('%s remote_get_key' % (self,)) if key_size != self.DEFAULT_KEY_SIZE or not self.keypool: + key = self.gen_key(key_size) self.reset_timer() - return self.gen_key(key_size) + return key else: self.reset_timer() return self.keypool.pop()