Exemplo n.º 1
0
    def test_receive_single_packet(self, monkeypatch):
        monkeypatch.setattr(hyper.http20.bufsocket.select, 'select',
                            dummy_select)
        s = DummySocket()
        b = BufferedSocket(s)
        s.inbound_packets.append(b'test data')

        d = b.recv(100).tobytes()
        assert d == b'test data'
Exemplo n.º 2
0
    def test_can_send_on_buffered_socket(self, monkeypatch):
        monkeypatch.setattr(hyper.http20.bufsocket.select, 'select',
                            dummy_select)
        s = DummySocket()
        b = BufferedSocket(s)
        b.send(b'test data')

        assert len(s.outbound_packets) == 1
        assert s.outbound_packets[0] == b'test data'
Exemplo n.º 3
0
    def test_oversized_read(self, monkeypatch):
        monkeypatch.setattr(hyper.http20.bufsocket.select, 'select',
                            dummy_select)
        s = DummySocket()
        b = BufferedSocket(s)
        s.inbound_packets.append(b'a' * 600)

        d = b.recv(1200).tobytes()
        assert d == b'a' * 600
Exemplo n.º 4
0
    def test_receive_single_packet(self, monkeypatch):
        monkeypatch.setattr(
            hyper.http20.bufsocket.select, 'select', dummy_select
        )
        s = DummySocket()
        b = BufferedSocket(s)
        s.inbound_packets.append(b'test data')

        d = b.recv(100).tobytes()
        assert d == b'test data'
Exemplo n.º 5
0
    def test_can_send_on_buffered_socket(self, monkeypatch):
        monkeypatch.setattr(
            hyper.http20.bufsocket.select, 'select', dummy_select
        )
        s = DummySocket()
        b = BufferedSocket(s)
        b.send(b'test data')

        assert len(s.outbound_packets) == 1
        assert s.outbound_packets[0] == b'test data'
Exemplo n.º 6
0
    def test_oversized_read(self, monkeypatch):
        monkeypatch.setattr(
            hyper.http20.bufsocket.select, 'select', dummy_select
        )
        s = DummySocket()
        b = BufferedSocket(s)
        s.inbound_packets.append(b'a' * 600)

        d = b.recv(1200).tobytes()
        assert d == b'a' * 600
Exemplo n.º 7
0
    def test_receive_small_packets(self, monkeypatch):
        monkeypatch.setattr(hyper.http20.bufsocket.select, 'select',
                            dummy_select)
        s = DummySocket()
        b = BufferedSocket(s)
        s.inbound_packets = [b'Here', b'begins', b'the', b'test', b'data']

        d = b''
        for _ in range(5):
            d += b.recv(100).tobytes()

        assert d == b'Herebeginsthetestdata'
Exemplo n.º 8
0
    def test_receive_empty_packet(self, monkeypatch):
        monkeypatch.setattr(
            hyper.http20.bufsocket.select, 'select', dummy_select
        )
        s = DummySocket()
        b = BufferedSocket(s)
        s.inbound_packets = [b'Here', b'begins', b'', b'the', b'', b'test', b'data']

        d = b''
        for _ in range(7):
            d += b.recv(100).tobytes()

        assert d == b'Herebeginsthetestdata'
Exemplo n.º 9
0
    def test_receive_multiple_packets_at_once(self, monkeypatch):
        monkeypatch.setattr(
            hyper.http20.bufsocket.select, 'select', dummy_select
        )
        s = DummySocket()
        b = BufferedSocket(s)
        s.inbound_packets = [b'Here', b'begins', b'the', b'test', b'data', b'!']
        s.read_count = 3

        d = b''
        for _ in range(22):
            d += b.recv(1).tobytes()

        assert d == b'Herebeginsthetestdata!'
Exemplo n.º 10
0
    def test_filling_the_buffer(self, monkeypatch):
        monkeypatch.setattr(hyper.http20.bufsocket.select, 'select',
                            dummy_select)
        s = DummySocket()
        b = BufferedSocket(s)
        s.inbound_packets = [
            b'a' * 1000,
            b'a' * 800,
        ]

        d = b''
        for _ in range(2):
            d += b.recv(900).tobytes()

        assert d == (b'a' * 1800)
Exemplo n.º 11
0
    def test_receive_multiple_packets_at_once(self, monkeypatch):
        monkeypatch.setattr(hyper.http20.bufsocket.select, 'select',
                            dummy_select)
        s = DummySocket()
        b = BufferedSocket(s)
        s.inbound_packets = [
            b'Here', b'begins', b'the', b'test', b'data', b'!'
        ]
        s.read_count = 3

        d = b''
        for _ in range(22):
            d += b.recv(1).tobytes()

        assert d == b'Herebeginsthetestdata!'
Exemplo n.º 12
0
    def test_filling_the_buffer(self, monkeypatch):
        monkeypatch.setattr(
            hyper.http20.bufsocket.select, 'select', dummy_select
        )
        s = DummySocket()
        b = BufferedSocket(s)
        s.inbound_packets = [
            b'a' * 1000,
            b'a' * 800,
        ]

        d = b''
        for _ in range(2):
            d += b.recv(900).tobytes()

        assert d == (b'a' * 1800)
Exemplo n.º 13
0
    def test_can_create_buffered_sockets(self, monkeypatch):
        monkeypatch.setattr(hyper.http20.bufsocket.select, 'select',
                            dummy_select)
        s = DummySocket()
        b = BufferedSocket(s)

        assert b is not None
        assert b._buffer_size == 1000