当前位置: 首页>>代码示例>>Python>>正文


Python ThreadedClock.assert_not_waiting方法代码示例

本文整理汇总了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
开发者ID:EricCen,项目名称:commons,代码行数:43,代码来源:test_clock.py

示例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)
开发者ID:EricCen,项目名称:commons,代码行数:25,代码来源:test_clock.py


注:本文中的twitter.common.testing.clock.ThreadedClock.assert_not_waiting方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。