MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_timeout

Method test_timeout

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

Source from the content-addressed store, hash-verified

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