示例#1
0
def test_sync_in_event_loop():
    a = Stream()
    assert not a.asynchronous
    L = a.timed_window(0.01).sink_to_list()
    sleep(0.05)
    assert L
    assert a.loop
    assert a.loop is not IOLoop.current()
示例#2
0
def test_timed_window_backpressure():
    q = Queue(maxsize=1)

    source = Stream()
    source.timed_window(0.01).sink(q.put)

    @gen.coroutine
    def read_from_q():
        while True:
            yield q.get()
            yield gen.sleep(0.1)

    IOLoop.current().add_callback(read_from_q)

    start = time()
    for i in range(5):
        yield source.emit(i)
        yield gen.sleep(0.01)
    stop = time()

    assert stop - start > 0.2
示例#3
0
def test_timed_window_ref_counts():
    source = Stream(asynchronous=True)
    _ = source.timed_window(0.01)

    ref1 = RefCounter()
    assert str(ref1) == "<RefCounter count=0>"
    source.emit(1, metadata=[{'ref': ref1}])
    assert ref1.count == 1
    yield gen.sleep(0.05)

    ref2 = RefCounter()
    source.emit(2, metadata=[{'ref': ref2}])
    assert ref1.count == 0
    assert ref2.count == 1
示例#4
0
def test_timed_window():
    source = Stream()
    a = source.timed_window(0.01)

    L = a.sink_to_list()

    for i in range(10):
        yield source.emit(i)
        yield gen.sleep(0.004)

    yield gen.sleep(a.interval)
    assert L
    assert sum(L, []) == list(range(10))
    assert all(len(x) <= 3 for x in L)
    assert any(len(x) >= 2 for x in L)

    yield gen.sleep(0.1)
    assert not L[-1]
示例#5
0
def test_timed_window_metadata():
    source = Stream()
    L = metadata(source.timed_window(0.06)).sink_to_list()

    source.emit(0)
    source.emit(1, metadata=[{'v': 1}])
    yield gen.sleep(0.1)
    source.emit(2, metadata=[{'v': 2}])
    source.emit(3, metadata=[{'v': 3}])
    yield gen.sleep(0.1)
    assert L == [
        [{
            'v': 1
        }],  # first emit because 0 has no metadata
        [{
            'v': 2
        }, {
            'v': 3
        }]  # second emit
    ]
示例#6
0
def test_timed_window_str():
    source = Stream()
    s = source.timed_window(.05)
    assert str(s) == '<timed_window; interval=0.05>'
示例#7
0
def test_timed_window_timedelta(clean):  # noqa: F811
    pytest.importorskip('pandas')
    source = Stream(asynchronous=True)
    a = source.timed_window('10ms')
    assert a.interval == 0.010
示例#8
0
def test_share_common_ioloop(clean):  # noqa: F811
    a = Stream()
    b = Stream()
    aa = a.timed_window(0.01)
    bb = b.timed_window(0.01)
    assert aa.loop is bb.loop
示例#9
0
def test_percolate_loop_information(clean):  # noqa: F811
    source = Stream()
    assert not source.loop
    s = source.timed_window(0.5)
    assert source.loop is s.loop
示例#10
0
def test_timed_window_str(clean):  # noqa: F811
    source = Stream()
    s = source.timed_window(.05)
    assert str(s) == '<timed_window: 0.05>'
示例#11
0
def test_percolate_loop_information(loop, thread):
    source = Stream()
    assert not source.loop
    s = source.timed_window(0.5)
    assert source.loop is IOLoop.current()