def test_eagain_on_buffer_size(self, *args): # get a connection that's already fully started c = self.test_successful_connection() # Testing with v3, minimum supported version header = six.b('\x03') + uint16_pack(0) + six.b('\x00\x00') + int32_pack(20000) responses = [ header + (six.b('a') * (4096 - len(header))), six.b('a') * 4096, socket_error(errno.EAGAIN), six.b('a') * 100, socket_error(errno.EAGAIN)] def side_effect(*args): response = responses.pop(0) if isinstance(response, socket_error): raise response else: return response c._socket.recv.side_effect = side_effect c.handle_read(None, 0) self.assertEqual(c._current_frame.end_pos, 20000 + len(header)) # the EAGAIN prevents it from reading the last 100 bytes c._iobuf.seek(0, os.SEEK_END) pos = c._iobuf.tell() self.assertEqual(pos, 4096 + 4096) # now tell it to read the last 100 bytes c.handle_read(None, 0) c._iobuf.seek(0, os.SEEK_END) pos = c._iobuf.tell() self.assertEqual(pos, 4096 + 4096 + 100)
def make_header_prefix(self, message_class, version=3, stream_id=0): header = list(map(uint8_pack, [ 0xff & (HEADER_DIRECTION_TO_CLIENT | version), stream_id, message_class.opcode # opcode ])) header.insert(1, uint16_pack(0)) # flags (compression) return six.binary_type().join(header)
def write_short(f, s): f.write(uint16_pack(s))
def test_comparison(self): tok = BytesToken.from_string(six.text_type('0123456789abcdef')) token_high_order = uint16_unpack(tok.value[0:2]) self.assertLess(BytesToken(uint16_pack(token_high_order - 1)), tok) self.assertGreater(BytesToken(uint16_pack(token_high_order + 1)), tok)