Skip to content

Commit

Permalink
More tests of Semaphore, timeout, and with-statement.
Browse files Browse the repository at this point in the history
  • Loading branch information
ajdavis committed Feb 25, 2015
1 parent 897ef08 commit bc1cb63
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tornado/test/locks_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,23 @@ def test_context_manager_exception(self):

@gen_test
def test_context_manager_timeout(self):
sem = locks.Semaphore()
with (yield sem.acquire(timedelta(seconds=0.01))):
pass

# Semaphore was released and can be acquired again.
self.assertTrue(sem.acquire().done())

@gen_test
def test_context_manager_timeout_error(self):
sem = locks.Semaphore(value=0)
with self.assertRaises(gen.TimeoutError):
with (yield sem.acquire(timedelta(seconds=0.01))):
pass

# Counter is still 0.
self.assertFalse(sem.acquire().done())

@gen_test
def test_context_manager_contended(self):
sem = locks.Semaphore()
Expand Down

0 comments on commit bc1cb63

Please sign in to comment.