示例#1
0
def test_socket_queue_basics(codec, threading_model):
    s1, s2 = _socketpair(threading_model)
    sq1 = SocketQueue(s1, codec, threading_model)
    sq2 = SocketQueue(s2, codec, threading_model)
    sq1.put(msg2)
    sq1.put(msg1)
    sq2.put(msg2)
    assert sq2.get() == msg2
    assert sq2.get() == msg1
    assert sq1.get() == msg2
    sq1.close()
    assert sq2.get() is None
    assert sq1.get() is None
    assert sq1.is_closed
    assert sq2.is_closed
    sq1.join()
    sq2.join()
示例#2
0
def test_socket_queue_garbage(codec, threading_model):
    s1, s2 = _socketpair(threading_model)
    sq = SocketQueue(s2, codec, threading_model)
    s1.sendall(b'\xfa\xff\xff\xff\xde\xadabracadabra bobby jenkins\x05\x04')
    assert isinstance(sq.get(), FramingError)
    # All but DecodingError's are considered irrecoverable -> socket is closed.
    sq.join(timeout=1.0)
    assert sq.is_closed