def test_import_start_worker(tmpworkdir, redis_conn, loop): actor = ActorTest(loop=loop) loop.run_until_complete(actor.foo(1, 2)) assert loop.run_until_complete(redis_conn.exists(b'arq:q:dft')) dft_queue = loop.run_until_complete(redis_conn.lrange(b'arq:q:dft', 0, -1)) assert len(dft_queue) == 1 tmpworkdir.join('test.py').write(EXAMPLE_FILE) start_worker('test.py', 'Worker', True, loop=loop) assert tmpworkdir.join('foo').read() == '3' loop.run_until_complete(actor.close())
def test_run_sigint_twice(tmpworkdir, redis_conn, loop, caplog): caplog.set_level(logging.DEBUG) actor = ActorTest(loop=loop) loop.run_until_complete(actor.foo(1)) loop.run_until_complete(actor.foo(1)) loop.run_until_complete(actor.foo(1)) loop.run_until_complete(actor.close()) tmpworkdir.join('test.py').write(EXAMPLE_FILE) with pytest.raises(BaseException): start_worker('test.py', 'WorkerSignalTwiceQuit', False, loop=loop) assert tmpworkdir.join('foo').exists() assert tmpworkdir.join('foo').read() == '1' assert 'Worker exiting after an unhandled error: ImmediateExit' in caplog
def test_run_sigint(tmpworkdir, redis_conn, loop, caplog): caplog.set_level(logging.DEBUG) actor = ActorTest(loop=loop) loop.run_until_complete(actor.foo(1)) loop.run_until_complete(actor.foo(1)) loop.run_until_complete(actor.foo(1)) loop.run_until_complete(actor.close()) tmpworkdir.join('test.py').write(EXAMPLE_FILE) assert not tmpworkdir.join('foo').exists() start_worker('test.py', 'WorkerSignalQuit', False, loop=loop) assert tmpworkdir.join('foo').exists() assert tmpworkdir.join('foo').read() == '1' assert 'got signal: SIGINT, stopping...' in caplog
def test_repeat_worker_close(tmpworkdir, redis_conn, caplog): tmpworkdir.join('test.py').write(EXAMPLE_FILE) loop = asyncio.new_event_loop() async def enqueue_jobs(_loop): actor = ActorTest(loop=_loop) for i in range(1, 6): await actor.foo(0, i) await actor.close() loop.run_until_complete(enqueue_jobs(loop)) Process(target=kill_parent).start() start_worker('test.py', 'Worker', False, loop=loop) assert tmpworkdir.join('foo').exists() assert tmpworkdir.join( 'foo').read() == '5' # because WorkerSignalQuit quit assert caplog.log.count('shutting down worker after') == 1