MCPcopy Index your code
hub / github.com/python/cpython / test_timeout

Method test_timeout

Lib/test/lock_tests.py:230–255  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

228 pass
229
230 def test_timeout(self):
231 lock = self.locktype()
232 # Can't set timeout if not blocking
233 self.assertRaises(ValueError, lock.acquire, False, 1)
234 # Invalid timeout values
235 self.assertRaises(ValueError, lock.acquire, timeout=-100)
236 self.assertRaises(OverflowError, lock.acquire, timeout=1e100)
237 self.assertRaises(OverflowError, lock.acquire, timeout=TIMEOUT_MAX + 1)
238 # TIMEOUT_MAX is ok
239 lock.acquire(timeout=TIMEOUT_MAX)
240 lock.release()
241 t1 = time.monotonic()
242 self.assertTrue(lock.acquire(timeout=5))
243 t2 = time.monotonic()
244 # Just a sanity test that it didn't actually wait for the timeout.
245 self.assertLess(t2 - t1, 5)
246 results = []
247 def f():
248 t1 = time.monotonic()
249 results.append(lock.acquire(timeout=0.5))
250 t2 = time.monotonic()
251 results.append(t2 - t1)
252 with Bunch(f, 1):
253 pass
254 self.assertFalse(results[0])
255 self.assertTimeout(results[1], 0.5)
256
257 def test_weakref_exists(self):
258 lock = self.locktype()

Callers

nothing calls this directly

Calls 8

assertTrueMethod · 0.80
assertFalseMethod · 0.80
assertTimeoutMethod · 0.80
BunchClass · 0.70
assertRaisesMethod · 0.45
acquireMethod · 0.45
releaseMethod · 0.45
assertLessMethod · 0.45

Tested by

no test coverage detected