Пример #1
0
def test_2_jobs_concurrently():
    values_1 = {'number': 0}
    values_2 = {'number': 0}
    job1 = Scheduler.get_job(callback=callback, interval=0.05, callback_params={'param_dict': values_1})
    job2 = Scheduler.get_job(callback=callback, interval=0.10, callback_params={'param_dict': values_2})
    job1.cancel()
    job1.start()
    job1.start()
    job2.start()
    MolerTest.sleep(seconds=0.23)
    job1.cancel()
    job1.cancel()
    job2.cancel()
    assert (2 == values_2['number'])
    assert (4 == values_1['number'])
Пример #2
0
def test_long_job():
    values = {'number': 0}
    job = Scheduler.get_job(callback=callback_long, interval=0.1, callback_params={'param_dict': values}, cancel_on_exception=True)
    job.start()
    MolerTest.sleep(seconds=0.45)
    job.cancel()
    assert(2 == values['number'])
Пример #3
0
def test_exception_in_job_not_canceled():
    values = {'number': 0}
    job = Scheduler.get_job(callback=callback_exception, interval=0.1, callback_params={'param_dict': values}, cancel_on_exception=False)
    job.start()
    MolerTest.sleep(seconds=0.32)
    job.cancel()
    assert(3 == values['number'])
Пример #4
0
def test_job():
    values = {'number': 0}
    job = Scheduler.get_job(callback=callback, interval=0.1, callback_params={'param_dict': values})
    job.start()
    MolerTest.sleep(seconds=0.22)
    job.cancel()
    assert(2 == values['number'])
Пример #5
0
def test_thread_test_job():
    Scheduler.change_kind("thread")
    values = {'number': 0}
    job = Scheduler.get_job(callback=callback, interval=0.1, callback_params={'param_dict': values})
    job.start()
    time.sleep(0.38)
    job.cancel()
    Scheduler.change_kind()  # Set the default
    assert (3 == values['number'])
Пример #6
0
def test_job_callback_as_method():
    values = {'number': 0}
    obj = CallbackTest()
    job = Scheduler.get_job(callback=obj.callback_method, interval=0.1, callback_params={'param_dict': values})
    job.start()
    MolerTest.sleep(seconds=0.22)
    job.cancel()
    assert(2 == values['number'])
    assert(6 == obj.counter)
Пример #7
0
def test_asyncio_test_job():
    loop = asyncio.get_event_loop()
    Scheduler.change_kind("asyncio")
    values = {'number': 0}
    job = Scheduler.get_job(callback=callback, interval=0.1, callback_params={'param_dict': values})
    job.start()
    loop.run_until_complete(asyncio.sleep(0.23))
    job.cancel()
    loop.stop()
    Scheduler.change_kind()  # Set the default
    assert (2 == values['number'])