Esempio n. 1
0
    def monitor_start(self, monitor):
        '''When the monitor starts load all test classes into the queue'''
        # Create a datastore for this test suite
        if not self.cfg.task_backend:
            server = PulsarDS(bind='127.0.0.1:0',
                              workers=0,
                              key_value_save=[],
                              name='%s_store' % self.name)
            yield server()
            address = 'pulsar://%s:%s' % server.cfg.addresses[0]
        else:
            address = self.cfg.task_backend

        store = create_store(address, pool_size=2, loop=monitor._loop)
        self.get_backend(store)
        loader = self.loader
        tags = self.cfg.labels
        exclude_tags = self.cfg.exclude_labels
        if self.cfg.show_leaks:
            show = show_leaks if self.cfg.show_leaks == 1 else hide_leaks
            self.cfg.set('when_exit', show)
            arbiter = pulsar.arbiter()
            arbiter.cfg.set('when_exit', show)
        try:
            tests = []
            loader.runner.on_start()
            for tag, testcls in loader.testclasses(tags, exclude_tags):
                suite = loader.runner.loadTestsFromTestCase(testcls)
                if suite and suite._tests:
                    tests.append((tag, testcls))
            self._time_start = None
            if tests:
                self.logger.info('loading %s test classes', len(tests))
                monitor.cfg.set('workers', min(self.cfg.workers, len(tests)))
                self._time_start = default_timer()
                queued = []
                self._tests_done = set()
                self._tests_queued = None
                #
                # Bind to the task_done event
                self.backend.bind_event('task_done',
                                        partial(self._test_done, monitor))
                for tag, testcls in tests:
                    r = self.backend.queue_task('test',
                                                testcls=testcls,
                                                tag=tag)
                    queued.append(r)
                queued = yield multi_async(queued)
                self.logger.debug('loaded %s test classes', len(tests))
                self._tests_queued = set(queued)
                yield self._test_done(monitor)
            else:  # pragma    nocover
                raise ExitTest('Could not find any tests.')
        except ExitTest as e:  # pragma    nocover
            monitor.stream.writeln(str(e))
            monitor._loop.stop()
        except Exception:  # pragma    nocover
            monitor.logger.critical('Error occurred while starting tests',
                                    exc_info=True)
            monitor._loop.call_soon(self._exit, 3)
Esempio n. 2
0
 def create_pulsar_store(cls):
     server = PulsarDS(name=cls.__name__.lower(),
                       bind='127.0.0.1:0',
                       concurrency=cls.cfg.concurrency,
                       redis_py_parser=cls.redis_py_parser)
     cls.pulsar_app_cfg = yield pulsar.send('arbiter', 'run', server)
     cls.pulsards_uri = 'pulsar://%s:%s' % cls.pulsar_app_cfg.addresses[0]
     cls.store = cls.create_store('%s/9' % cls.pulsards_uri)
Esempio n. 3
0
 async def setUpClass(cls):
     server = PulsarDS(name=cls.__name__.lower(),
                       bind='127.0.0.1:0',
                       redis_py_parser=cls.redis_py_parser)
     cls.app_cfg = await pulsar.send('arbiter', 'run', server)
     cls.pulsards_uri = 'pulsar://%s:%s' % cls.app_cfg.addresses[0]
     cls.store = cls.create_store('%s/9' % cls.pulsards_uri)
     cls.client = cls.store.client()
Esempio n. 4
0
async def start_pulsar_ds(arbiter, host, workers=0):
    lock = getattr(arbiter, 'lock', None)
    if lock is None:
        arbiter.lock = lock = asyncio.Lock()
    await lock.acquire()
    try:
        app = await get_application('pulsards')
        if not app:
            app = PulsarDS(bind=host, workers=workers, load_config=False)
            cfg = await app(arbiter)
        else:
            cfg = app.cfg
        return cfg
    finally:
        lock.release()
Esempio n. 5
0
 def start_pulsar_ds(arbiter, host, workers=0):
     lock = getattr(arbiter, 'lock', None)
     if lock is None:
         arbiter.lock = lock = asyncio.Lock()
     yield lock.acquire()
     try:
         app = yield get_application('pulsards')
         if not app:
             app = PulsarDS(bind=host, workers=workers)
             cfg = yield app(arbiter)
         else:
             cfg = app.cfg
         coroutine_return(cfg)
     finally:
         lock.release()
Esempio n. 6
0
'''\
Pulsar key-value store server. To run the server type::

    python manage.py

Open a new shell and launch python and type::

    >>> from pulsar.apps.data import create_store
    >>> store = create_store('pulsar://localhost:6410')
    >>> client = store.client()
    >>> client.ping()
    True
    >>> client.echo('Hello!')
    b'Hello!'
    >>> client.set('bla', 'foo')
    True
    >>> client.get('bla')
    b'foo'
    >>> client.dbsize()
    1

'''
from pulsar.apps.ds import PulsarDS

if __name__ == '__main__':  # pragma nocover
    PulsarDS().start()