Beispiel #1
0
    def test_async_job_scheduler(self):
        async def test1():
            result.async_js1 += 1

        async def test2():
            result.async_js2 += 1

        task_supervisor.create_aloop('jobs')
        task_supervisor.create_async_job_scheduler('default',
                                                   aloop='jobs',
                                                   default=True)
        j1 = task_supervisor.create_async_job(target=test1, interval=0.01)
        j2 = task_supervisor.create_async_job(target=test2, interval=0.01)

        time.sleep(0.1)

        j2.cancel()

        r1 = result.async_js1
        r2 = result.async_js2

        self.assertGreater(r1, 9)
        self.assertGreater(r2, 9)

        time.sleep(0.1)

        j1.cancel()

        self.assertLess(r1, result.async_js1)
        self.assertEqual(r2, result.async_js2)
Beispiel #2
0
    def test_aloop(self):
        @background_worker(interval=0.02)
        async def t(**kwargs):
            result.test_aloop = threading.current_thread().getName()

        task_supervisor.create_aloop('test1', default=True)
        t.start()
        wait()
        t.stop()
        self.assertEqual(result.test_aloop, 'supervisor_default_aloop_test1')
Beispiel #3
0
def start_supervisor():
    task_supervisor.set_thread_pool(min_size=config.pool_min_size,
                                    max_size=config.pool_max_size)
    task_supervisor.timeout_critical_func = critical
    task_supervisor.poll_delay = config.polldelay
    task_supervisor.start()
    task_supervisor.create_aloop('default', default=True)
    task_supervisor.create_aloop('cleaners')
    task_supervisor.create_async_job_scheduler('default', default=True)
    task_supervisor.create_async_job_scheduler('cleaners', aloop='cleaners')
Beispiel #4
0
        j2.cancel()

        r1 = result.async_js1
        r2 = result.async_js2

        self.assertGreater(r1, 9)
        self.assertGreater(r2, 9)

        time.sleep(0.1)

        j1.cancel()

        self.assertLess(r1, result.async_js1)
        self.assertEqual(r2, result.async_js2)


if __name__ == '__main__':
    try:
        if sys.argv[1] == 'debug':
            logging.basicConfig(level=logging.DEBUG)
            set_debug()
    except:
        pass
    task_supervisor.start()
    task_supervisor.create_aloop('default', default=True)
    task_supervisor.poll_delay = 0.01
    test_suite = unittest.TestLoader().loadTestsFromTestCase(Test)
    test_result = unittest.TextTestRunner().run(test_suite)
    task_supervisor.stop(wait=3)
    sys.exit(not test_result.wasSuccessful())