예제 #1
0
파일: stack_network.py 프로젝트: sah/tricle
def test_client():
    addr = '127.0.0.1'
    port = 5555
    with network_server_running(addr, port):
        yield sleep(0.1)
        with network_client() as client:
            msg = 'ok'
            yield client.connect(addr, port)
            yield client.write(msg + EOL)
            result = yield client.read_until(EOL)
            result = result.decode('utf-8')
            assert result == 'you said: ' + msg + EOL
    yield sleep(0.1)
예제 #2
0
파일: tb.py 프로젝트: ChrisWren/monocle
def first_evlp():
  try:
    yield sleep(1)
    yield req()
    yield launch(second)
  finally:
    eventloop.halt()
예제 #3
0
def first_evlp():
    try:
        yield sleep(1)
        yield req()
        yield launch(second)
    finally:
        eventloop.halt()
예제 #4
0
파일: callback.py 프로젝트: sah/tricle
def test_add():
    cb = Callback()
    calls = []
    assert cb.future._callbacks == []
    cb.add(calls.append)
    assert len(cb.future._callbacks) == 1
    pytest.raises(TypeError, cb.add, False)
    assert len(cb.future._callbacks) == 1
    assert calls == []
    cb('ok')
    yield sleep(0)
    assert calls == ['ok']
    cb.add(calls.append)
    yield sleep(0)
    assert calls == ['ok', 'ok']
    pytest.raises(TypeError, cb.add, False)
예제 #5
0
파일: callback.py 프로젝트: sah/tricle
def test_defer():
    cb = defer('ok')
    assert isinstance(cb, Callback)
    assert cb.result == 'ok'
    calls = []
    cb.add(calls.append)
    yield sleep(0)
    assert calls == ['ok']
예제 #6
0
def test_client():
    addr = '127.0.0.1'
    port = 5556
    with http_server_running(port):
        yield sleep(0.1)
        with http_client() as client:
            yield client.connect(addr, port)
            r = yield client.request('/')
            assert r.code == '200', r.code  # should this be an int?
예제 #7
0
 def test_read_some_delay(self):
     data = 'ok'
     self.conn.timeout = 0.2
     def populate():
         self.buffer = data
         self.stack_conn.read_cb(None)
     eventloop.queue_task(0.1, populate)
     r = yield self.conn.read_some()
     self.assertEqual(r, data)
     self.assertEqual(self.stack_conn.resume_called, 1)
     yield sleep(0.2)  # ensure timeout has expired
예제 #8
0
 def test_read_delay(self):
     data = 'ok'
     self.buffer = 'o'
     self.conn.timeout = 0.2
     def populate():
         self.buffer += 'k'
         self.stack_conn.read_cb(None)
     eventloop.queue_task(0.1, populate)
     r = yield self.conn.read(2)
     assert r == data
     assert self.stack_conn.resume_called == 1
     yield sleep(0.2)  # ensure timeout has expired
예제 #9
0
def _subproc_wrapper(port, target, *args, **kwargs):
    try:
        client = Client()
        while True:
            try:
                yield client.connect('127.0.0.1', port)
                break
            except Exception, e:
                print "failed to connect to monocle multiprocess parent on port", port, type(e), str(e)
                yield sleep(1)
        chan = SocketChannel(client)
        yield target(chan, *args, **kwargs)
예제 #10
0
def _subproc_wrapper(port, target, *args, **kwargs):
    try:
        client = Client()
        while True:
            try:
                yield client.connect('127.0.0.1', port)
                break
            except Exception, e:
                print type(e), str(e)
                yield sleep(1)
        chan = SocketChannel(client)
        yield target(chan, *args, **kwargs)
예제 #11
0
    def test_read_some_delay(self):
        data = 'ok'
        self.conn.timeout = 0.2

        def populate():
            self.buffer = data
            self.stack_conn.read_cb(None)

        eventloop.queue_task(0.1, populate)
        r = yield self.conn.read_some()
        self.assertEqual(r, data)
        self.assertEqual(self.stack_conn.resume_called, 1)
        yield sleep(0.2)  # ensure timeout has expired
예제 #12
0
def _subproc_wrapper(port, target, *args, **kwargs):
    try:
        client = Client()
        while True:
            try:
                yield client.connect('127.0.0.1', port)
                break
            except Exception, e:
                print "failed to connect to monocle multiprocess parent on port", port, type(
                    e), str(e)
                yield sleep(1)
        chan = SocketChannel(client)
        yield target(chan, *args, **kwargs)
예제 #13
0
    def test_read_delay(self):
        data = 'ok'
        self.buffer = 'o'
        self.conn.timeout = 0.2

        def populate():
            self.buffer += 'k'
            self.stack_conn.read_cb(None)

        eventloop.queue_task(0.1, populate)
        r = yield self.conn.read(2)
        assert r == data
        assert self.stack_conn.resume_called == 1
        yield sleep(0.2)  # ensure timeout has expired
예제 #14
0
def test_lots_of_messages():
    add_service(Service(handle_echo, port=8000))
    try:
        client = Client()
        yield client.connect('localhost', 8000)
        t = time.time()
        for x in range(1000):
            msg = "hello, world #%s!" % x
            yield client.write(msg + '\r\n')
            echo_result = yield client.read_until("\r\n")
            echo_result = echo_result.decode('utf-8')
            assert echo_result.strip() == "you said: %s" % msg, echo_result
        print('10000 loops in %.2fs' % (time.time() - t))
    finally:
        client.close()
        yield sleep(0.1)
예제 #15
0
def test_large_requests():
    addr = '127.0.0.1'
    port = 5557
    recv_body = []

    @_o
    def _handler(conn):
        recv_body.append(conn.body)
        data = 'Hello, World!'
        headers = http.HttpHeaders()
        headers.add('Content-Length', len(data))
        headers.add('Content-Type', 'text/plain')
        headers.add('Connection', 'close')
        yield Return(200, headers, data)

    with http_server_running(port, handler=_handler):
        yield sleep(0.1)
        with http_client() as client:
            yield client.connect(addr, port)
            send_body = 'x' * payload_multiplier
            r = yield client.request('/',
                                     method='POST',
                                     body='x' * payload_multiplier)
            assert recv_body and recv_body[0] == send_body
예제 #16
0
def get_conn(cb, conn):
    cb(conn)
    while not conn.is_closed():
        yield sleep(1)
예제 #17
0
파일: tb.py 프로젝트: saucelabs/monocle
def req():
    yield sleep(1)
예제 #18
0
def print_every_two_seconds():
    for i in xrange(5):
        print("2")
        yield sleep(2)
예제 #19
0
def print_every_second():
    for i in xrange(5):
        print("1")
        yield sleep(1)
예제 #20
0
def foo(x, z=1):
    yield sleep(1)
    print x
예제 #21
0
def fail():
    raise Exception("whoo")
    yield sleep(1)
예제 #22
0
def get_conn(cb, conn):
    cb(conn)
    while not conn.is_closed():
        yield sleep(1)
예제 #23
0
def yielding_oroutine(x, z=1):
    yield sleep(1)
    print(x)
예제 #24
0
파일: tb.py 프로젝트: saucelabs/monocle
def first_evlp():
    yield sleep(1)
    yield req()
    yield launch(second)  # won't crash
예제 #25
0
 def test_simple(self):
     t = time.time()
     yield util.sleep(0.01)
     dt = time.time() - t
     self.assertTrue(dt > 0.005 and dt < 0.015)
예제 #26
0
def test_sleep():
    t = time.time()
    yield util.sleep(0.01)
    dt = time.time() - t
    assert 0.005 < dt < 0.015
예제 #27
0
 def test_simple(self):
     t = time.time()
     yield util.sleep(0.01)
     dt = time.time() - t
     self.assertTrue(dt > 0.005 and dt < 0.015)
예제 #28
0
def req():
    yield sleep(1)
예제 #29
0
def foo(x, z=1):
    yield sleep(1)
    print x
예제 #30
0
def print_every_two_seconds():
    for i in xrange(5):
        print "2"
        yield sleep(2)
    eventloop.halt()
예제 #31
0
def fail():
    raise Exception("whoo")
    yield sleep(1)
예제 #32
0
def first_evlp():
    yield sleep(1)
    yield req()
    yield launch(second)  # won't crash
예제 #33
0
def yielding_oroutine(x, z=1):
    yield sleep(1)
    print x
예제 #34
0
파일: eventloop.py 프로젝트: sah/tricle
def fail():
    raise Exception("whoo")
    # make this a generator function, to demonstrate exceptions work properly in this context
    yield sleep(1)