Exemplo n.º 1
0
 def test_registry(self):
     app = yield get_application(self.name())
     self.assertTrue(isinstance(app.backend.registry, dict))
     regular = app.backend.registry.regular()
     periodic = app.backend.registry.periodic()
     self.assertTrue(regular)
     self.assertTrue(periodic)
Exemplo n.º 2
0
 def testRegistry(self):
     app = get_application(self.name_tq())
     self.assertTrue(isinstance(app.registry, dict))
     regular = app.registry.regular()
     periodic = app.registry.periodic()
     self.assertTrue(regular)
     self.assertTrue(periodic)
Exemplo n.º 3
0
 def test_run_new_task_asynchronous_wait_on_test(self):
     app = yield get_application(self.name())
     r = yield self.proxy.run_new_task(jobname='asynchronous', lag=3)
     r = yield app.backend.wait_for_task(r)
     self.assertEqual(r.status, tasks.SUCCESS)
     self.assertTrue(r.result['loops'])
     self.assertTrue(r.result['time'] > 3)
Exemplo n.º 4
0
 def test_id_not_overlap(self):
     '''Check `generate_task_ids` when `can_overlap` attribute is set to
     False.'''
     app = yield get_application(self.name())
     job = app.backend.registry['notoverlap']
     self.assertEqual(job.type, 'regular')
     self.assertFalse(job.can_overlap)
     #
     id1, oid1 = job.generate_task_ids((), {})
     self.assertTrue(oid1)
     id2, oid2 = job.generate_task_ids((), {})
     self.assertTrue(oid2)
     self.assertNotEqual(id2, id1)
     self.assertEqual(oid2, oid1)
     #
     id3, oid3 = job.generate_task_ids((10, 'bla'), {'p': 45})
     self.assertTrue(oid3)
     self.assertNotEqual(id3, id2)
     self.assertNotEqual(oid3, oid2)
     id4, oid4 = job.generate_task_ids((10, 'bla'), {'p': 45})
     self.assertNotEqual(id4, id3)
     self.assertEqual(oid4, oid3)
     #
     id5, oid5 = job.generate_task_ids((), {'p': 45, 'c': 'bla'})
     self.assertTrue(oid5)
     id6, oid6 = job.generate_task_ids((), {'p': 45, 'c': 'bla'})
     id7, oid7 = job.generate_task_ids((), {'p': 45, 'd': 'bla'})
     id8, oid8 = job.generate_task_ids((), {'p': 45, 'c': 'blas'})
     #
     self.assertEqual(oid5, oid6)
     self.assertNotEqual(oid5, oid7)
     self.assertNotEqual(oid5, oid8)
Exemplo n.º 5
0
 def test_testsuite(self):
     app = yield from get_application('test')
     self.assertTrue(app.cfg.script)
     # self.assertEqual(app.script, sys.argv[0])
     self.assertEqual(os.path.dirname(app.cfg.script), app.root_dir)
     self.assertEqual(app.cfg.modules, ('tests', ('examples', 'tests'),
                                        ('examples', 'test_*')))
Exemplo n.º 6
0
 def test_sorted_tags(self):
     app = yield from get_application('test')
     loader = TestLoader(app.root_dir, app.cfg.modules, app.runner)
     modules = list(loader.testmodules())
     self.assertTrue(modules)
     tags = [m[0] for m in modules]
     self.assertEqual(tags, sorted(tags))
Exemplo n.º 7
0
 def testMeta(self):
     app = yield get_application(self.name())
     self.assertEqual(app.name, self.name())
     monitor = get_actor().get_actor(app.name)
     self.assertTrue(monitor.is_running())
     self.assertEqual(app, monitor.app)
     self.assertEqual(str(app), app.name)
     self.assertEqual(app.cfg.bind, '127.0.0.1:0')
Exemplo n.º 8
0
 def test_run_new_task_asynchronous_from_test(self):
     app = yield get_application(self.name())
     r = yield app.backend.run('asynchronous', lag=3)
     r = yield self.proxy.wait_for_task(r)
     self.assertEqual(r['status'], tasks.SUCCESS)
     result = r['result']
     self.assertTrue(result['loops'])
     self.assertTrue(result['time'] > 3)
Exemplo n.º 9
0
 def testMeta(self):
     app = yield get_application(self.name())
     self.assertEqual(app.name, self.name())
     monitor = get_actor().get_actor(app.name)
     self.assertTrue(monitor.is_running())
     self.assertEqual(app, monitor.app)
     self.assertEqual(str(app), app.name)
     self.assertEqual(app.cfg.bind, '127.0.0.1:0')
Exemplo n.º 10
0
 def test_load_exclude(self):
     app = yield from get_application('test')
     modules = dict(app.loader.test_files(
         exclude=('stores', 'apps.pubsub')))
     self.assertFalse('stores.lock' in modules)
     self.assertFalse('stores.parser' in modules)
     self.assertFalse('apps.pubsub' in modules)
     self.assertTrue('apps.greenio' in modules)
Exemplo n.º 11
0
 def testRpcMeta(self):
     app = get_application(self.name_rpc())
     self.assertTrue(app)
     self.assertEqual(app.name, self.name_rpc())
     rpc = app.callable
     root = rpc.handler
     tq = root.taskqueue
     self.assertEqual(tq, self.name_tq())
Exemplo n.º 12
0
 def test_testsuite(self):
     app = yield from get_application('test')
     self.assertTrue(app.cfg.script)
     # self.assertEqual(app.script, sys.argv[0])
     self.assertEqual(os.path.dirname(app.cfg.script), app.root_dir)
     self.assertEqual(app.cfg.modules, ('tests',
                                        ('examples', 'tests'),
                                        ('examples', 'test_*')))
Exemplo n.º 13
0
 def test_load_exclude(self):
     app = yield from get_application('test')
     loader = TestLoader(app.root_dir, app.cfg.modules, app.runner)
     modules = dict(loader.testmodules(
         exclude_tags=('taskqueue', 'apps.pubsub')))
     self.assertTrue(modules)
     for module in modules:
         self.assertTrue('taskqueue' not in module)
         self.assertTrue('apps.pubsub' not in module)
Exemplo n.º 14
0
 def test_pubsub(self):
     '''Tests meta attributes of taskqueue'''
     app = yield get_application(self.name())
     self.assertFalse(app.backend.local.pubsub)
     pubsub = app.backend.pubsub
     self.assertEqual(app.backend.local.pubsub, pubsub)
     # the pubsub name is the same as the task queue application
     self.assertEqual(app.backend.name, app.name)
     self.assertEqual(pubsub.name, app.name)
     self.pubsub_test(app)
Exemplo n.º 15
0
 def __test_delete_task(self):
     #ISSUE #56
     app = yield get_application(self.name())
     id = yield app.backend.run('addition', 1, 4)
     r1 = yield app.backend.wait_for_task(id)
     self.assertEqual(r1.result, 5)
     deleted = yield app.backend.delete_tasks([r1.id, 'kjhbkjb'])
     self.assertEqual(len(deleted), 1)
     r1 = yield app.backend.get_task(r1.id)
     self.assertFalse(r1)
Exemplo n.º 16
0
 def test_load_pulsar_tests(self):
     app = yield from get_application('test')
     modules = dict(app.loader.test_files())
     self.assertTrue(modules)
     self.assertFalse('httpbin' in modules)
     self.assertTrue('echo' in modules)
     self.assertFalse('djchat' in modules)
     self.assertTrue('djchat.app' in modules)
     self.assertTrue('djchat.pulse' in modules)
     self.assertFalse('async' in modules)
     self.assertTrue('async.actor' in modules)
Exemplo n.º 17
0
 def test_not_overlap(self):
     sec = 2 + random()
     app = yield get_application(self.name())
     self.assertEqual(app.name, app.backend.name)
     self.assertTrue('notoverlap' in app.backend.registry)
     r1 = yield app.backend.run('notoverlap', sec)
     self.assertTrue(r1)
     r2 = yield app.backend.run('notoverlap', sec)
     self.assertFalse(r2)
     # We need to make sure the first task is completed
     r1 = yield app.backend.wait_for_task(r1)
     self.assertEqual(r1.status, tasks.SUCCESS)
     self.assertTrue(r1.result > sec)
Exemplo n.º 18
0
 def testDeleteTask(self):
     app = get_application(self.name_tq())
     r1 = app.scheduler.queue_task(app.monitor, 'addition', (1,4), {})
     id = r1.id
     get_task = app.scheduler.get_task
     while get_task(id).status in tasks.UNREADY_STATES:
         yield NOT_DONE
     r2 = get_task(id)
     self.assertEqual(r1.id, r2.id)
     r2 = get_task(id, remove=True)
     self.assertEqual(get_task(id), None)
     self.assertEqual(get_task(r1), r1)
     app.scheduler.delete_tasks()
Exemplo n.º 19
0
 def testMeta(self):
     '''Tests meta attributes of taskqueue'''
     app = get_application(self.name_tq())
     self.assertTrue(app)
     self.assertEqual(app.name, self.name_tq())
     self.assertTrue(app.registry)
     scheduler = app.scheduler
     self.assertTrue(scheduler.entries)
     job = app.registry['runpycode']
     self.assertEqual(job.type,'regular')
     self.assertTrue(job.can_overlap)
     id = job.make_task_id((),{})
     self.assertTrue(id)
     self.assertNotEqual(id,job.make_task_id((),{}))
Exemplo n.º 20
0
 def test_rpc_meta(self):
     app = yield get_application(self.rpc_name())
     self.assertTrue(app)
     self.assertEqual(app.name, self.rpc_name())
     self.assertEqual(app.cfg.address, ('127.0.0.1', 0))
     self.assertNotEqual(app.cfg.address, app.address)
     self.assertEqual(app.cfg.concurrency, self.concurrency)
     wsgi_handler = app.callable.handler
     self.assertEqual(len(wsgi_handler.middleware), 1)
     router = wsgi_handler.middleware[0]
     self.assertTrue(router.post)
     root = router.post
     tq = root.taskqueue
     self.assertEqual(tq, self.name())
Exemplo n.º 21
0
def start_pulsar_ds(arbiter, host, workers=0):
    lock = getattr(arbiter, 'lock', None)
    if lock is None:
        arbiter.lock = lock = asyncio.Lock()
    yield from lock.acquire()
    try:
        app = yield from get_application('pulsards')
        if not app:
            app = PulsarDS(bind=host, workers=workers, load_config=False)
            cfg = yield from app(arbiter)
        else:
            cfg = app.cfg
        return cfg
    finally:
        lock.release()
Exemplo n.º 22
0
def start_pulsar_ds(arbiter, host, workers=0):
    lock = getattr(arbiter, 'lock', None)
    if lock is None:
        arbiter.lock = lock = asyncio.Lock()
    yield from lock.acquire()
    try:
        app = yield from get_application('pulsards')
        if not app:
            app = PulsarDS(bind=host, workers=workers, load_config=False)
            cfg = yield from app(arbiter)
        else:
            cfg = app.cfg
        return cfg
    finally:
        lock.release()
Exemplo n.º 23
0
 def testNotOverlap(self):
     app = get_application(self.name_tq())
     self.assertTrue('notoverlap' in app.registry)
     r1 = app.scheduler.queue_task(app.monitor, 'notoverlap', (1,), {})
     self.assertEqual(str(r1), 'notoverlap(%s)' % r1.id)
     self.assertTrue(r1._queued)
     r2 = app.scheduler.queue_task(app.monitor, 'notoverlap', (1,), {})
     self.assertFalse(r2._queued)
     id = r1.id
     self.assertEqual(id, r2.id)
     # We need to make sure the first task is completed
     get_task = app.scheduler.get_task
     while get_task(id).status in tasks.UNREADY_STATES:
         yield NOT_DONE
     self.assertEqual(get_task(id).status, tasks.SUCCESS)
Exemplo n.º 24
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()
Exemplo n.º 25
0
 def test_load_pulsar_tests(self):
     app = yield from get_application('test')
     loader = TestLoader(app.root_dir, app.cfg.modules, app.runner)
     self.assertEqual(loader.modules, [('tests', None, None),
                                       ('examples', 'tests', None),
                                       ('examples', 'test_*', None)])
     modules = dict(loader.testmodules())
     self.assertTrue(modules)
     self.assertFalse('httpbin' in modules)
     self.assertTrue('echo' in modules)
     self.assertTrue('djchat' in modules)
     self.assertTrue('djchat.app' in modules)
     self.assertTrue('djchat.pulse' in modules)
     self.assertTrue('async' in modules)
     self.assertTrue('suite.single' in modules)
Exemplo n.º 26
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()
Exemplo n.º 27
0
 def testIdNotOverlap(self):
     '''Check `make_task_id` when `can_overlap` attribute is set to False.'''
     app = get_application(self.name_tq())
     job = app.registry['notoverlap']
     self.assertEqual(job.type, 'regular')
     self.assertFalse(job.can_overlap)
     #
     id = job.make_task_id((),{})
     self.assertTrue(id)
     self.assertEqual(id, job.make_task_id((),{}))
     #
     id = job.make_task_id((10,'bla'),{'p':45})
     self.assertTrue(id)
     self.assertEqual(id,job.make_task_id((10,'bla'),{'p':45}))
     #
     id = job.make_task_id((),{'p':45,'c':'bla'})
     self.assertTrue(id)
     self.assertEqual(id,job.make_task_id((),{'p':45,'c':'bla'}))
     self.assertNotEqual(id,job.make_task_id((),{'p':45,'d':'bla'}))
     self.assertNotEqual(id,job.make_task_id((),{'p':45,'c':'blas'}))
Exemplo n.º 28
0
 def test_meta(self):
     '''Tests meta attributes of taskqueue'''
     app = yield get_application(self.name())
     self.assertTrue(app)
     self.assertEqual(app.name, self.name())
     self.assertFalse(app.cfg.address)
     self.assertEqual(app.cfg.concurrent_tasks, self.concurrent_tasks)
     self.assertEqual(app.backend.backlog, self.concurrent_tasks)
     self.assertTrue(app.backend.registry)
     self.assertEqual(app.cfg.concurrency, self.concurrency)
     backend = app.backend
     self.assertFalse(backend.entries)
     job = app.backend.registry['runpycode']
     self.assertEqual(job.type, 'regular')
     self.assertTrue(job.can_overlap)
     id, oid = job.generate_task_ids((), {})
     self.assertTrue(id)
     self.assertFalse(oid)
     id1, oid = job.generate_task_ids((), {})
     self.assertNotEqual(id, id1)
     self.assertFalse(oid)
Exemplo n.º 29
0
 def test_server_on_arbiter(self):
     app = yield get_application(self.__class__.__name__.lower())
     cfg = app.cfg
     self.assertTrue(cfg.addresses)
     self.assertTrue(cfg.address)
     self.assertNotEqual(cfg.addresses[0], cfg.address)
Exemplo n.º 30
0
def start_server(actor, name, argv):
    manage.execute_from_command_line(argv)
    app = yield get_application(name)
    coroutine_return(app.cfg)
Exemplo n.º 31
0
def start_server(actor, name, argv):
    os.environ["DJANGO_SETTINGS_MODULE"] = "djchat.settings"
    execute_from_command_line(argv)
    app = yield get_application(name)
    coroutine_return(app.cfg)
Exemplo n.º 32
0
def start_server(actor, name, argv):
    server(argv)
    yield None
    app = yield from get_application(name)
    return app.cfg
Exemplo n.º 33
0
 def test_run_new_simple_task_from_test(self):
     app = yield get_application(self.name())
     r = yield app.backend.run('addition', a=1, b=2)
     r = yield self.proxy.wait_for_task(r)
     self.assertEqual(r['status'], tasks.SUCCESS)
     self.assertEqual(r['result'], 3)
Exemplo n.º 34
0
 def test_check_next_run(self):
     app = yield get_application(self.name())
     backend = app.backend
     backend.tick()
Exemplo n.º 35
0
def get_test(_):
    app = yield from get_application('test')
    return app.cfg
Exemplo n.º 36
0
 def test_load_tags1(self):
     app = yield from get_application('test')
     modules = dict(app.loader.test_files(('suite',)))
     self.assertEqual(len(modules), 4)
Exemplo n.º 37
0
 def test_sorted_tags(self):
     app = yield from get_application('test')
     modules = app.loader.test_files()
     self.assertTrue(modules)
     tags = [m[0] for m in modules]
     self.assertEqual(tags, sorted(tags))
Exemplo n.º 38
0
def start_server(actor, name, argv):
    # we need to make sure djangoapp is in the python path
    actor.params.django_pulsar_name = name
    manage.execute_from_command_line(argv)
    app = yield get_application(name)
    yield app.event('start')
Exemplo n.º 39
0
def start_server(actor, name, argv):
    manage.execute_from_command_line(argv)
    app = yield get_application(name)
    coroutine_return(app.cfg)
Exemplo n.º 40
0
 def test_load_tags1(self):
     app = yield from get_application('test')
     loader = TestLoader(app.root_dir, app.cfg.modules, app.runner)
     modules = dict(loader.testmodules(('suite',)))
     self.assertEqual(len(modules), 6)
Exemplo n.º 41
0
 def test_server(self):
     app = yield pulsar.get_application(self.__class__.__name__.lower())
     self.assertTrue(app.address)
     self.assertTrue(app.cfg.address)
     self.assertNotEqual(app.address, app.cfg.address)
Exemplo n.º 42
0
def start_server(actor, name, argv):
    app = manage.execute_from_command_line(argv)
    app = yield get_application(name)
    yield app.event('start')
Exemplo n.º 43
0
 def test_server_on_arbiter(self):
     app = yield get_application(self.__class__.__name__.lower())
     cfg = app.cfg
     self.assertTrue(cfg.addresses)
     self.assertTrue(cfg.address)
     self.assertNotEqual(cfg.addresses[0], cfg.address)