don't depend on .called and .result (use Deferred callbacks properly)

This commit is contained in:
meejah 2018-09-07 09:41:39 -06:00
parent 054ed30757
commit 8a6a477ef7

View File

@ -286,9 +286,10 @@ class NoNetworkGrid(service.MultiService):
self.rebuild_serverlist() self.rebuild_serverlist()
for i in range(num_clients): for i in range(num_clients):
c = self.make_client(i) d = self.make_client(i)
self.clients.append(c) d.addCallback(lambda c: self.clients.append(c))
@defer.inlineCallbacks
def make_client(self, i, write_config=True): def make_client(self, i, write_config=True):
clientid = hashutil.tagged_hash("clientid", str(i))[:20] clientid = hashutil.tagged_hash("clientid", str(i))[:20]
clientdir = os.path.join(self.basedir, "clients", clientdir = os.path.join(self.basedir, "clients",
@ -314,16 +315,14 @@ class NoNetworkGrid(service.MultiService):
c = self.client_config_hooks[i](clientdir) c = self.client_config_hooks[i](clientdir)
if not c: if not c:
d0 = create_no_network_client(clientdir) c = yield create_no_network_client(clientdir)
assert d0.called
c = d0.result
c.set_default_mutable_keysize(TEST_RSA_KEY_SIZE) c.set_default_mutable_keysize(TEST_RSA_KEY_SIZE)
c.nodeid = clientid c.nodeid = clientid
c.short_nodeid = b32encode(clientid).lower()[:8] c.short_nodeid = b32encode(clientid).lower()[:8]
c._servers = self.all_servers # can be updated later c._servers = self.all_servers # can be updated later
c.setServiceParent(self) c.setServiceParent(self)
return c defer.returnValue(c)
def make_server(self, i, readonly=False): def make_server(self, i, readonly=False):
serverid = hashutil.tagged_hash("serverid", str(i))[:20] serverid = hashutil.tagged_hash("serverid", str(i))[:20]
@ -439,8 +438,10 @@ class GridTestMixin:
client = self.g.clients[i] client = self.g.clients[i]
d = defer.succeed(None) d = defer.succeed(None)
d.addCallback(lambda ign: self.g.removeService(client)) d.addCallback(lambda ign: self.g.removeService(client))
@defer.inlineCallbacks
def _make_client(ign): def _make_client(ign):
c = self.g.make_client(i, write_config=False) c = yield self.g.make_client(i, write_config=False)
self.g.clients[i] = c self.g.clients[i] = c
self._record_webports_and_baseurls() self._record_webports_and_baseurls()
d.addCallback(_make_client) d.addCallback(_make_client)