summaryrefslogtreecommitdiff
path: root/tests/semaphore_test.py
diff options
context:
space:
mode:
authorShaun Stanworth <shaun.stanworth@onefinestay.com>2014-11-09 16:35:25 +0000
committerSergey Shepelev <temotor@gmail.com>2015-02-21 14:46:45 +0300
commitbab11168093d63db8cd11b47321264b3ae91411c (patch)
tree6842737a63b136fa551221787c107983e7144f20 /tests/semaphore_test.py
parenta6ce444265d36fb23361809d40da73caf4864487 (diff)
downloadeventlet-tm.tar.gz
semaphore: Don't hog a semaphore if someone else is waiting for ittm
https://github.com/eventlet/eventlet/issues/136 https://github.com/eventlet/eventlet/pull/163 (comment by Sergey Shepelev) _waiters is now deque, watch out for O(N) acquire()
Diffstat (limited to 'tests/semaphore_test.py')
-rw-r--r--tests/semaphore_test.py21
1 files changed, 20 insertions, 1 deletions
diff --git a/tests/semaphore_test.py b/tests/semaphore_test.py
index 1316330..ced9136 100644
--- a/tests/semaphore_test.py
+++ b/tests/semaphore_test.py
@@ -45,5 +45,24 @@ class TestSemaphore(LimitedTestCase):
self.assertRaises(ValueError, sem.acquire, blocking=False, timeout=1)
+def test_semaphore_contention():
+ g_mutex = semaphore.Semaphore()
+ counts = [0, 0]
+
+ def worker(no):
+ while min(counts) < 200:
+ with g_mutex:
+ counts[no - 1] += 1
+ eventlet.sleep(0.001)
+
+ t1 = eventlet.spawn(worker, no=1)
+ t2 = eventlet.spawn(worker, no=2)
+ eventlet.sleep(0.5)
+ t1.kill()
+ t2.kill()
+
+ assert abs(counts[0] - counts[1]) < int(min(counts) * 0.1), counts
+
+
if __name__ == '__main__':
- unittest.main()
+ unittest.main() \ No newline at end of file