Пример #1
0
def test_async():
    io_loop = IOLoop.instance()
    client = AsyncClient('localhost', 9999, timeout=1)
    assert client.closed
    _response = ['']

    def callback(response):
        _response[0] = response
        io_loop.stop()
    print 'call long'
    client.call('long', callback)
    io_loop.start()
    response = _response[0]
    _response = ['']
    try:
        response.rethrow()
    except STPTimeoutError as e:
        print e
        time.sleep(2)
    print 'call ping'
    client.call('ping', callback)
    io_loop.start()
    response = _response[0]
    _response = ['']
    response.rethrow()
Пример #2
0
    def test_not_timeout(self):
        from stpclient import AsyncClient
        client = AsyncClient('localhost', 9999, timeout=1)
        assert client.closed

        def callback(response):
            self._response = response
            self.io_loop.stop()
        client.call('ping', callback)
        self.io_loop.start()
        response = self._response
        self._response = None
        response.rethrow()
Пример #3
0
    def test_timeout_state(self):
        import time
        from stpclient import AsyncClient
        client = AsyncClient('localhost', 9999, timeout=1)
        assert client.closed

        def callback(response):
            self._response = response
            self.io_loop.stop()
        client.call('long', callback)
        self.io_loop.start()
        response = self._response
        self._response = None
        try:
            response.rethrow()
        except STPTimeoutError:
            time.sleep(2)
        client.call('ping', callback)
        self.io_loop.start()
        response = self._response
        self._response = None
        response.rethrow()