Example #1
0
def test_multi_start(queue):
    queue.enqueue({})
    handlers = []
    start_evt = threading.Event()

    def _test():
        start_evt.wait(30)
        handler = queue.start()
        if handler is not None:
            handlers.append(handler)

    monitor = ThreadMonitor()

    for i in range(5):
        start_evt.clear()
        threads = [
            threading.Thread(target=monitor.wrap(_test)) for i in range(10)
        ]
        [t.start() for t in threads]
        start_evt.set()
        [t.join() for t in threads]

    monitor.check()

    assert len(handlers) == 1
    assert handlers[0].valid()
Example #2
0
def test_start_block(queue):
    data = {'hello': 'world'}

    def _test():
        handler = queue.start(block=True, timeout=5)
        assert handler is not None
        assert handler.data == data

    monitor = ThreadMonitor()
    _t = threading.Thread(target=monitor.wrap(_test))
    _t.start()

    time.sleep(0.2)
    queue.enqueue(data)

    _t.join()
    monitor.check()
def test_threading(manager):
    arr = []
    monitor = ThreadMonitor()

    def _test():
        with manager.acquire('test', block=True) as l:
            assert l.valid()
            arr.append(1)
            time.sleep(0.1)
            assert len(arr) == 1
            arr.pop()

    threads = [threading.Thread(target=monitor.wrap(_test)) for i in range(10)]
    [t.start() for t in threads]
    [t.join() for t in threads]

    monitor.check()
def test_start_block(queue):
    data = { 'hello': 'world' }

    def _test():
        handler = queue.start(block=True, timeout=5)
        assert handler is not None
        assert handler.data == data

    monitor = ThreadMonitor()
    _t = threading.Thread(target=monitor.wrap(_test))
    _t.start()

    time.sleep(0.2)
    queue.enqueue(data)

    _t.join()
    monitor.check()
Example #5
0
def test_threading(manager):
    arr = []
    monitor = ThreadMonitor()

    def _test():
        with manager.acquire('test', block=True) as l:
            assert l.valid()
            arr.append(1)
            time.sleep(0.1)
            assert len(arr) == 1
            arr.pop()

    threads = [threading.Thread(target=monitor.wrap(_test)) for i in range(10)]
    [t.start() for t in threads]
    [t.join() for t in threads]

    monitor.check()
def test_multi_start(queue):
    queue.enqueue({})
    handlers = []
    start_evt = threading.Event()

    def _test():
        start_evt.wait(30)
        handler = queue.start()
        if handler is not None:
            handlers.append(handler)

    monitor = ThreadMonitor()

    for i in range(5):
        start_evt.clear()
        threads = [threading.Thread(target=monitor.wrap(_test)) for i in range(10)]
        [t.start() for t in threads]
        start_evt.set()
        [t.join() for t in threads]

    monitor.check()

    assert len(handlers) == 1
    assert handlers[0].valid()