From: A. Jesse Jiryu Davis Date: Wed, 25 Feb 2015 20:59:04 +0000 (-0500) Subject: More tests of Semaphore, timeout, and with-statement. X-Git-Tag: v4.2.0b1~93^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F1346%2Fhead;p=thirdparty%2Ftornado.git More tests of Semaphore, timeout, and with-statement. --- diff --git a/tornado/test/locks_test.py b/tornado/test/locks_test.py index 45db095ff..314530f56 100644 --- a/tornado/test/locks_test.py +++ b/tornado/test/locks_test.py @@ -296,11 +296,23 @@ class SemaphoreContextManagerTest(AsyncTestCase): @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()