Skip to content

Commit 226a5cf

Browse files
committed
Add test for Lock.locked()
1 parent 879a65a commit 226a5cf

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

tests/test_recipes.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,26 @@ def test_averager(cache):
2828
assert nums.pop() == 9.5
2929

3030

31+
def test_lock(cache):
32+
state = {'num': 0}
33+
lock = dc.Lock(cache, 'demo')
34+
35+
def worker():
36+
state['num'] += 1
37+
with lock:
38+
assert lock.locked()
39+
state['num'] += 1
40+
time.sleep(0.1)
41+
42+
with lock:
43+
thread = threading.Thread(target=worker)
44+
thread.start()
45+
time.sleep(0.1)
46+
assert state['num'] == 1
47+
thread.join()
48+
assert state['num'] == 2
49+
50+
3151
def test_rlock(cache):
3252
state = {'num': 0}
3353
rlock = dc.RLock(cache, 'demo')

0 commit comments

Comments
 (0)