from redis import StrictRedis from redis_lock import Lock from conf import TIMEOUT from conf import UDS_PATH if __name__ == '__main__': logging.basicConfig( level=logging.DEBUG, format= '%(process)d %(asctime)s,%(msecs)05d %(name)s %(levelname)s %(message)s', datefmt="%x~%X") test_name = sys.argv[1] setup_coverage() if test_name == 'test_simple': conn = StrictRedis(unix_socket_path=UDS_PATH) with Lock(conn, "foobar"): time.sleep(0.1) elif test_name == 'test_no_block': conn = StrictRedis(unix_socket_path=UDS_PATH) lock = Lock(conn, "foobar") res = lock.acquire(blocking=False) logging.info("acquire=>%s", res) elif test_name == 'test_timeout': conn = StrictRedis(unix_socket_path=UDS_PATH) with Lock(conn, "foobar"): time.sleep(1) elif test_name == 'test_expire':
elif test_name == 'test_timeout': logging.critical('test_timeout STARTED') time.sleep(2) logging.critical('test_timeout FAIL') elif test_name == 'test_bad_client': logging.critical('JOB %s EXECUTED', workspace_name) time.sleep(0.1) else: raise RuntimeError('Invalid test spec %r.' % test_name) if __name__ == '__main__': logging.basicConfig( level=logging.DEBUG, format='[pid=%(process)d - %(asctime)s]: %(name)s - %(levelname)s - %(message)s', ) if len(sys.argv) > 1 and sys.argv[1] == 'daemon': setup_coverage() from stampede import StampedeWorker class MockedStampedeWorker(StampedeWorker): do_work = work_dispatch socket_name = UDS_PATH alarm_time = 1 daemon = MockedStampedeWorker() daemon.run() logging.info("DONE.") else: unittest.main()