本文整理匯總了Python中twitter.common.testing.clock.ThreadedClock.assert_not_waiting方法的典型用法代碼示例。如果您正苦於以下問題:Python ThreadedClock.assert_not_waiting方法的具體用法?Python ThreadedClock.assert_not_waiting怎麽用?Python ThreadedClock.assert_not_waiting使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類twitter.common.testing.clock.ThreadedClock
的用法示例。
在下文中一共展示了ThreadedClock.assert_not_waiting方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_with_events
# 需要導入模塊: from twitter.common.testing.clock import ThreadedClock [as 別名]
# 或者: from twitter.common.testing.clock.ThreadedClock import assert_not_waiting [as 別名]
def test_with_events(num_threads):
event = threading.Event()
hits = []
hits_before, hits_after = 0, 0
clock = ThreadedClock(0)
def hit_me():
clock.sleep(0.1)
hits.append(True)
threads = []
for _ in range(num_threads):
th = threading.Thread(target=hit_me)
th.daemon = True
th.start()
threads.append(th)
clock.converge(threads=threads)
for th in threads:
clock.assert_waiting(th, 0.1)
clock.tick(0.05)
clock.converge(threads=threads)
hits_before += len(hits)
with pytest.raises(AssertionError):
clock.assert_waiting(threads[0], 234)
clock.tick(0.05)
clock.converge(threads=threads)
hits_after += len(hits)
for th in threads:
clock.assert_not_waiting(th)
with pytest.raises(AssertionError):
clock.assert_waiting(th, 0.1)
assert hits_before == 0
assert hits_after == num_threads
示例2: test_not_converged
# 需要導入模塊: from twitter.common.testing.clock import ThreadedClock [as 別名]
# 或者: from twitter.common.testing.clock.ThreadedClock import assert_not_waiting [as 別名]
def test_not_converged():
clock1 = ThreadedClock(0)
clock2 = ThreadedClock(0)
def run():
clock1.sleep(1)
clock2.sleep(1)
th = threading.Thread(target=run)
th.daemon = True
th.start()
assert clock1.converge(threads=[th])
clock1.assert_waiting(th, 1)
assert clock2.converge(threads=[th], timeout=0.1) is False
clock2.assert_not_waiting(th)
clock1.tick(1)
clock2.tick(2)
clock1.converge(threads=[th])
clock2.converge(threads=[th])
clock1.assert_not_waiting(th)
clock2.assert_not_waiting(th)