예제 #1
0
def test_can_put_onto_buffer():
    mk(('echo.sock', 'socket.send(socket.recv())'))
    buffer = Buffer(make_socket(), 'foo')
    expected = [FFFD+'4'+FFFD+'1:::']
    buffer.put(Message.from_bytes('1:::'))
    actual = list(buffer.flush())
    assert actual == expected, actual
예제 #2
0
def make_transport(content='', state=0):
    mk(('echo.sock', content))
    socket = make_socket()
    transport = XHRPollingTransport(socket)
    transport.timeout = 0.05 # for testing, could screw up the test
    if state == 1:
        transport.respond(Request(url='/echo.sock'))
    return transport
예제 #3
0
def test_channel_can_have_sockets_added_to_it():
    mk(('echo.sock', 'channel.send(channel.recv())'))
    socket = make_socket()
    channel = Channel('foo', ThreadedBuffer)
    channel.add(socket)

    expected = [socket]
    actual = list(channel)
    assert actual == expected, actual
예제 #4
0
def test_channel_passes_send_on_to_four_sockets():
    mk(('echo.sock', 'channel.send(channel.recv())'))
    channel = Channel('foo', ThreadedBuffer)
    sockets = [make_socket(channel=channel) for i in range(4)]
    channel.send('foo')

    for socket in sockets:
        expected = deque([Message.from_bytes('3::/echo.sock:foo')])
        actual = socket.outgoing.queue
        assert actual == expected, actual
예제 #5
0
def test_channel_passes_send_on_to_one_socket():
    mk(('echo.sock', ''))
    socket = make_socket()
    channel = Channel('foo', ThreadedBuffer)
    channel.add(socket)
    channel.send('foo')

    expected = deque([Message.from_bytes('3::/echo.sock:foo')])
    actual = socket.outgoing.queue
    assert actual == expected, actual
예제 #6
0
def test_buffer_is_instantiable():
    mk(('echo.sock', 'socket.send(socket.recv())'))
    expected = Buffer
    actual = Buffer(make_socket(), 'foo').__class__
    assert actual is expected, actual
예제 #7
0
def test_channel_raises_AssertionError_on_double_add():
    mk(('echo.sock', ''))
    socket = make_socket()
    channel = Channel('foo', ThreadedBuffer)
    channel.add(socket)
    assert_raises(AssertionError, channel.add, socket)