server/test/unittest_repository.py
branchstable
changeset 8874 522bdba66690
parent 8821 c4aa23af0baa
child 8945 ba9e3fbfa5a5
equal deleted inserted replaced
8873:280c32415059 8874:522bdba66690
    39 from cubicweb.devtools.repotest import tuplify
    39 from cubicweb.devtools.repotest import tuplify
    40 from cubicweb.server import repository, hook
    40 from cubicweb.server import repository, hook
    41 from cubicweb.server.sqlutils import SQL_PREFIX
    41 from cubicweb.server.sqlutils import SQL_PREFIX
    42 from cubicweb.server.hook import Hook
    42 from cubicweb.server.hook import Hook
    43 from cubicweb.server.sources import native
    43 from cubicweb.server.sources import native
    44 
       
    45 # start name server anyway, process will fail if already running
       
    46 os.system('pyro-ns >/dev/null 2>/dev/null &')
       
    47 
    44 
    48 
    45 
    49 class RepositoryTC(CubicWebTC):
    46 class RepositoryTC(CubicWebTC):
    50     """ singleton providing access to a persistent storage for entities
    47     """ singleton providing access to a persistent storage for entities
    51     and relation
    48     and relation
   348 
   345 
   349     def test_pyro(self):
   346     def test_pyro(self):
   350         import Pyro
   347         import Pyro
   351         Pyro.config.PYRO_MULTITHREADED = 0
   348         Pyro.config.PYRO_MULTITHREADED = 0
   352         done = []
   349         done = []
   353         # the client part has to be in the thread due to sqlite limitations
   350         self.repo.config.global_set_option('pyro-ns-host', 'NO_PYRONS')
   354         t = threading.Thread(target=self._pyro_client, args=(done,))
   351         daemon = self.repo.pyro_register()
   355         try:
   352         try:
   356             daemon = self.repo.pyro_register()
   353             uri = self.repo.pyro_uri.replace('PYRO', 'pyroloc')
       
   354             # the client part has to be in the thread due to sqlite limitations
       
   355             t = threading.Thread(target=self._pyro_client, args=(uri, done))
   357             t.start()
   356             t.start()
   358             while not done:
   357             while not done:
   359                 daemon.handleRequests(1.0)
   358                 daemon.handleRequests(1.0)
   360             t.join(1)
   359             t.join(1)
   361             if t.isAlive():
   360             if t.isAlive():
   364             repository.pyro_unregister(self.repo.config)
   363             repository.pyro_unregister(self.repo.config)
   365             from logilab.common import pyro_ext
   364             from logilab.common import pyro_ext
   366             pyro_ext._DAEMONS.clear()
   365             pyro_ext._DAEMONS.clear()
   367 
   366 
   368 
   367 
   369     def _pyro_client(self, done):
   368     def _pyro_client(self, uri, done):
   370         cnx = connect('pyro:///'+self.repo.config.appid,
   369         cnx = connect(uri,
   371                       u'admin', password='gingkow',
   370                       u'admin', password='gingkow',
   372                       initlog=False) # don't reset logging configuration
   371                       initlog=False) # don't reset logging configuration
   373         try:
   372         try:
   374             cnx.load_appobjects(subpath=('entities',))
   373             cnx.load_appobjects(subpath=('entities',))
   375             # check we can get the schema
   374             # check we can get the schema