check_memory: fix race condition for startup of in-process server nodes

This commit is contained in:
Brian Warner
2007-09-20 15:33:58 -07:00
parent 60573a2917
commit 3774ce59ea
3 changed files with 28 additions and 20 deletions

View File

@ -17,9 +17,9 @@ from allmydata.download import Downloader
from allmydata.control import ControlServer from allmydata.control import ControlServer
from allmydata.introducer import IntroducerClient from allmydata.introducer import IntroducerClient
from allmydata.vdrive import VirtualDrive from allmydata.vdrive import VirtualDrive
from allmydata.util import hashutil, idlib from allmydata.util import hashutil, idlib, testutil
class Client(node.Node, Referenceable): class Client(node.Node, Referenceable, testutil.PollMixin):
implements(RIClient) implements(RIClient)
PORTNUMFILE = "client.port" PORTNUMFILE = "client.port"
STOREDIR = 'storage' STOREDIR = 'storage'
@ -189,3 +189,16 @@ class Client(node.Node, Referenceable):
def get_cancel_secret(self): def get_cancel_secret(self):
return hashutil.my_cancel_secret_hash(self._secret) return hashutil.my_cancel_secret_hash(self._secret)
def debug_wait_for_client_connections(self, num_clients):
"""Return a Deferred that fires (with None) when we have connections
to the given number of peers. Useful for tests that set up a
temporary test network and need to know when it is safe to proceed
with an upload or download."""
def _check():
current_clients = list(self.get_all_peerids())
return len(current_clients) >= num_clients
d = self.poll(_check, 0.5)
d.addCallback(lambda res: None)
return d

View File

@ -33,12 +33,7 @@ class ControlServer(Referenceable, service.Service, testutil.PollMixin):
implements(RIControlClient) implements(RIControlClient)
def remote_wait_for_client_connections(self, num_clients): def remote_wait_for_client_connections(self, num_clients):
def _check(): return self.parent.debug_wait_for_client_connections(num_clients)
current_clients = list(self.parent.get_all_peerids())
return len(current_clients) >= num_clients
d = self.poll(_check, 0.5)
d.addCallback(lambda res: None)
return d
def remote_upload_from_file_to_uri(self, filename): def remote_upload_from_file_to_uri(self, filename):
uploader = self.parent.getServiceNamed("uploader") uploader = self.parent.getServiceNamed("uploader")
@ -52,9 +47,6 @@ class ControlServer(Referenceable, service.Service, testutil.PollMixin):
return d return d
def remote_upload_speed_test(self, size): def remote_upload_speed_test(self, size):
"""Write a tempfile to disk of the given size. Measure how long
it takes to upload it to the servers.
"""
assert size > 8 assert size > 8
fn = os.path.join(self.parent.basedir, idlib.b2a(os.urandom(8))) fn = os.path.join(self.parent.basedir, idlib.b2a(os.urandom(8)))
f = open(fn, "w") f = open(fn, "w")

View File

@ -377,18 +377,21 @@ this file are ignored.
data = "a" * size data = "a" * size
url = "/vdrive/global" url = "/vdrive/global"
d = self.POST(url, t="upload", file=("%d.data" % size, data)) d = self.POST(url, t="upload", file=("%d.data" % size, data))
elif self.mode in ("receive",): elif self.mode in ("receive",
# upload the data from a local peer, so that the "download", "download-GET", "download-GET-slow"):
# mode=receive: upload the data from a local peer, so that the
# client-under-test receives and stores the shares # client-under-test receives and stores the shares
#
# mode=download*: upload the data from a local peer, then have
# the client-under-test download it.
#
# we need to wait until the uploading node has connected to all
# peers, since the wait_for_client_connections() above doesn't
# pay attention to our self.nodes[] and their connections.
files[name] = self.create_data(name, size) files[name] = self.create_data(name, size)
u = self.nodes[0].getServiceNamed("uploader") u = self.nodes[0].getServiceNamed("uploader")
d = u.upload_filename(files[name]) d = self.nodes[0].debug_wait_for_client_connections(self.numnodes+1)
elif self.mode in ("download", "download-GET", "download-GET-slow"): d.addCallback(lambda res: u.upload_filename(files[name]))
# upload the data from a local peer, then have the
# client-under-test download it.
files[name] = self.create_data(name, size)
u = self.nodes[0].getServiceNamed("uploader")
d = u.upload_filename(files[name])
else: else:
raise RuntimeError("unknown mode=%s" % self.mode) raise RuntimeError("unknown mode=%s" % self.mode)
def _complete(uri): def _complete(uri):