Commit ba45542e authored by Julien Muchembled's avatar Julien Muchembled

tests: minor improvements/cleanup/fixes to threaded.__init__

parent 09782dd8
...@@ -182,6 +182,11 @@ class ServerNode(Node): ...@@ -182,6 +182,11 @@ class ServerNode(Node):
LOCAL_IP[:-1] + chr(2 + len(cls._server_class_dict))) LOCAL_IP[:-1] + chr(2 + len(cls._server_class_dict)))
cls._server_class_dict[cls._virtual_ip] = cls cls._server_class_dict[cls._virtual_ip] = cls
@staticmethod
def resetPorts():
for cls in ServerNode._server_class_dict.itervalues():
del cls._node_list[:]
@classmethod @classmethod
def newAddress(cls): def newAddress(cls):
address = cls._virtual_ip, len(cls._node_list) address = cls._virtual_ip, len(cls._node_list)
...@@ -242,6 +247,13 @@ class ServerNode(Node): ...@@ -242,6 +247,13 @@ class ServerNode(Node):
except AttributeError: except AttributeError:
pass pass
def stop(self):
try:
Serialized.release(stop=(self,))
self.join()
finally:
Serialized.acquire()
def getListeningAddress(self): def getListeningAddress(self):
try: try:
return self.listening_conn.getAddress() return self.listening_conn.getAddress()
...@@ -469,8 +481,9 @@ class NEOCluster(object): ...@@ -469,8 +481,9 @@ class NEOCluster(object):
self._resource_dict[result] = self self._resource_dict[result] = self
return result[1] return result[1]
def _patch(cluster): @staticmethod
cls = cluster.__class__ def _patch():
cls = NEOCluster
cls._patch_count += 1 cls._patch_count += 1
if cls._patch_count > 1: if cls._patch_count > 1:
return return
...@@ -496,8 +509,9 @@ class NEOCluster(object): ...@@ -496,8 +509,9 @@ class NEOCluster(object):
Storage.setupLog = lambda *args, **kw: None Storage.setupLog = lambda *args, **kw: None
Serialized.init() Serialized.init()
@classmethod @staticmethod
def _unpatch(cls): def _unpatch():
cls = NEOCluster
assert cls._patch_count > 0 assert cls._patch_count > 0
cls._patch_count -= 1 cls._patch_count -= 1
if cls._patch_count: if cls._patch_count:
...@@ -632,7 +646,9 @@ class NEOCluster(object): ...@@ -632,7 +646,9 @@ class NEOCluster(object):
Serialized.acquire() Serialized.acquire()
self._unpatch() self._unpatch()
def tic(self, force=False): @staticmethod
def tic(force=False):
# XXX: Should we automatically switch client in slave mode if it isn't ?
if force: if force:
Serialized.tic() Serialized.tic()
while Serialized.pending: while Serialized.pending:
...@@ -655,14 +671,14 @@ class NEOCluster(object): ...@@ -655,14 +671,14 @@ class NEOCluster(object):
self.client.setPoll(True) self.client.setPoll(True)
return Storage.Storage(None, self.name, _app=self.client, **kw) return Storage.Storage(None, self.name, _app=self.client, **kw)
def populate(self, dummy_zodb=None): def populate(self, dummy_zodb=None, random=random):
if dummy_zodb is None: if dummy_zodb is None:
from ..stat_zodb import PROD1 from ..stat_zodb import PROD1
dummy_zodb = PROD1() dummy_zodb = PROD1(random)
importFrom = self.getZODBStorage().importFrom
preindex = {} preindex = {}
as_storage = dummy_zodb.as_storage as_storage = dummy_zodb.as_storage
return lambda count: importFrom(as_storage(count), preindex=preindex) return lambda count: self.getZODBStorage().importFrom(
as_storage(count), preindex=preindex)
def getTransaction(self): def getTransaction(self):
txn = transaction.TransactionManager() txn = transaction.TransactionManager()
...@@ -690,6 +706,10 @@ class NEOThreadedTest(NeoTestBase): ...@@ -690,6 +706,10 @@ class NEOThreadedTest(NeoTestBase):
log_file = os.path.join(getTempDirectory(), self.id() + '.log') log_file = os.path.join(getTempDirectory(), self.id() + '.log')
setupLog(LoggerThreadName(), log_file, True) setupLog(LoggerThreadName(), log_file, True)
def tearDown(self):
super(NEOThreadedTest, self).tearDown()
ServerNode.resetPorts()
def getUnpickler(self, conn): def getUnpickler(self, conn):
reader = conn._reader reader = conn._reader
def unpickler(data, compression=False): def unpickler(data, compression=False):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment