def f(x): with Lock("x") as lock: client = get_client() assert client.get_metadata("locked") is False client.set_metadata("locked", True) sleep(0.05) assert client.get_metadata("locked") is True client.set_metadata("locked", False)
def f(x): with Lock('x') as lock: client = get_client() assert client.get_metadata('locked') is False client.set_metadata('locked', True) sleep(0.05) assert client.get_metadata('locked') is True client.set_metadata('locked', False)
def f(_): client = get_client() with MultiLock(names=["x"]): assert client.get_metadata("locked") is False client.set_metadata("locked", True) sleep(0.05) assert client.get_metadata("locked") is True client.set_metadata("locked", False)
def f(x): with Lock('x') as lock: client = get_client() assert client.get_metadata('locked') is False client.set_metadata('locked', True) sleep(0.05) assert client.get_metadata('locked') is True client.set_metadata('locked', False)
def test_lock_sync(client): def f(x): with Lock('x') as lock: client = get_client() assert client.get_metadata('locked') is False client.set_metadata('locked', True) sleep(0.05) assert client.get_metadata('locked') is True client.set_metadata('locked', False) client.set_metadata('locked', False) futures = client.map(f, range(10)) client.gather(futures)
def test_lock_sync(client): def f(x): with Lock('x') as lock: client = get_client() assert client.get_metadata('locked') is False client.set_metadata('locked', True) sleep(0.05) assert client.get_metadata('locked') is True client.set_metadata('locked', False) client.set_metadata('locked', False) futures = client.map(f, range(10)) client.gather(futures)
def observe_state(sem): """ This function is 100% artificial and acts as an observer to verify our assumptions. The function will wait until both payload tasks are executing, i.e. we're in an oversubscription scenario. It will then try to acquire and hopefully fail showing that the semaphore is protected if the oversubscription is recognized. """ sem.refresh_callback.stop() # We wait until we're in an oversubscribed state, i.e. both tasks # are executed although there should only be one allowed while not sem.get_value() > 1: sleep(0.2) # Once we're in an oversubscribed state, we must not be able to # acquire a lease. assert not sem.acquire(timeout=0) client = get_client() client.set_metadata("release", True)