Beispiel #1
0
static void
test_read_and_write_complex_types (void)
{
  int status;
  pid_t pid;
  ThriftSocket *tsocket = NULL;
  ThriftTransport *transport = NULL;
  ThriftBinaryProtocol *tb = NULL;
  ThriftProtocol *protocol = NULL;
  int port = TEST_PORT;

  /* fork a server from the client */
  pid = fork ();
  assert (pid >= 0);

  if (pid == 0)
  {
    /* child listens */
    thrift_server_complex_types (port);
    exit (0);
  } else {
    /* parent.  wait a bit for the socket to be created. */
    sleep (1);

    /* create a ThriftSocket */
    tsocket = g_object_new (THRIFT_TYPE_SOCKET, "hostname", "localhost",
                            "port", port, NULL);
    transport = THRIFT_TRANSPORT (tsocket);
    thrift_transport_open (transport, NULL);
    assert (thrift_transport_is_open (transport));

    /* create a ThriftBinaryTransport */
    tb = g_object_new (THRIFT_TYPE_BINARY_PROTOCOL, "transport",
                       tsocket, NULL);
    protocol = THRIFT_PROTOCOL (tb);
    assert (protocol != NULL);

    /* test structures */
    assert (thrift_binary_protocol_write_struct_begin (protocol, 
                                                       NULL, NULL) == 0);
    assert (thrift_binary_protocol_write_struct_end (protocol, NULL) == 0);

    assert (thrift_binary_protocol_write_field_begin (protocol, "test", T_VOID,
                                                      1, NULL) > 0);
    assert (thrift_binary_protocol_write_field_end (protocol, NULL) == 0);

    /* test write error */
    transport_write_error = 1;
    assert (thrift_binary_protocol_write_field_begin (protocol, "test", T_VOID, 
                                                      1, NULL) == -1);
    transport_write_error = 0;

    /* test 2nd write error */
    transport_write_count = 0;
    transport_write_error_at = 1;
    assert (thrift_binary_protocol_write_field_begin (protocol, "test", T_VOID,
                                                      1, NULL) == -1);
    transport_write_error_at = -1;

    /* test 2nd read failure on a field */
    thrift_binary_protocol_write_byte (protocol, T_VOID, NULL);

    /* test write_field_stop */
    assert (thrift_binary_protocol_write_field_stop (protocol, NULL) > 0);

    /* write a map */
    assert (thrift_binary_protocol_write_map_begin (protocol, T_VOID, T_VOID,
                                                    1, NULL) > 0);
    assert (thrift_binary_protocol_write_map_end (protocol, NULL) == 0);

    /* test 2nd read failure on a map */
    thrift_binary_protocol_write_byte (protocol, T_VOID, NULL);

    /* test 3rd read failure on a map */
    thrift_binary_protocol_write_byte (protocol, T_VOID, NULL);
    thrift_binary_protocol_write_byte (protocol, T_VOID, NULL);

    /* test 1st write failure on a map */
    transport_write_error = 1;
    assert (thrift_binary_protocol_write_map_begin (protocol, T_VOID, T_VOID,
                                                    1, NULL) == -1);
    transport_write_error = 0;

    /* test 2nd write failure on a map */
    transport_write_count = 0;
    transport_write_error_at = 1;
    assert (thrift_binary_protocol_write_map_begin (protocol, T_VOID, T_VOID,
                                                    1, NULL) == -1);
    transport_write_error_at = -1;

    /* test 3rd write failure on a map */
    transport_write_count = 0;
    transport_write_error_at = 2;
    assert (thrift_binary_protocol_write_map_begin (protocol, T_VOID, T_VOID,
                                                    1, NULL) == -1);
    transport_write_error_at = -1;

    /* test negative map size */
    thrift_binary_protocol_write_byte (protocol, T_VOID, NULL);
    thrift_binary_protocol_write_byte (protocol, T_VOID, NULL);
    thrift_binary_protocol_write_i32 (protocol, -10, NULL);

    /* test list operations */
    assert (thrift_binary_protocol_write_list_begin (protocol, T_VOID,
                                                     1, NULL) > 0);
    assert (thrift_binary_protocol_write_list_end (protocol, NULL) == 0);

    /* test 2nd read failure on a list */
    thrift_binary_protocol_write_byte (protocol, T_VOID, NULL);

    /* test negative list size */
    thrift_binary_protocol_write_byte (protocol, T_VOID, NULL);
    thrift_binary_protocol_write_i32 (protocol, -10, NULL);

    /* test first write error on a list */
    transport_write_error = 1;
    assert (thrift_binary_protocol_write_list_begin (protocol, T_VOID,
                                                     1, NULL) == -1);
    transport_write_error = 0;

    /* test 2nd write error on a list */
    transport_write_count = 0;
    transport_write_error_at = 1;
    assert (thrift_binary_protocol_write_list_begin (protocol, T_VOID,
                                                     1, NULL) == -1);
    transport_write_error_at = -1;

    /* test set operation s*/
    assert (thrift_binary_protocol_write_set_begin (protocol, T_VOID,
                                                    1, NULL) > 0);
    assert (thrift_binary_protocol_write_set_end (protocol, NULL) == 0);

    /* invalid version */
    assert (thrift_binary_protocol_write_i32 (protocol, -1, NULL) > 0);

    /* sz > 0 for a message */
    assert (thrift_binary_protocol_write_i32 (protocol, 1, NULL) > 0);

    /* send a valid message */
    thrift_binary_protocol_write_i32 (protocol, 0x80010000, NULL);
    thrift_binary_protocol_write_string (protocol, "test", NULL);
    thrift_binary_protocol_write_i32 (protocol, 1, NULL);

    /* broken 2nd read */
    thrift_binary_protocol_write_i32 (protocol, 0x80010000, NULL);

    /* send a broken 3rd read */
    thrift_binary_protocol_write_i32 (protocol, 0x80010000, NULL);
    thrift_binary_protocol_write_string (protocol, "test", NULL);

    /* send a valid message */
    assert (thrift_binary_protocol_write_message_begin (protocol, "test",
                                                        T_CALL, 1, NULL) > 0);

    assert (thrift_binary_protocol_write_message_end (protocol, NULL) == 0);

    /* send broken writes */
    transport_write_error = 1;
    assert (thrift_binary_protocol_write_message_begin (protocol, "test",
                                                        T_CALL, 1, NULL) == -1);
    transport_write_error = 0;

    transport_write_count = 0;
    transport_write_error_at = 2;
    assert (thrift_binary_protocol_write_message_begin (protocol, "test",
                                                        T_CALL, 1, NULL) == -1);
    transport_write_error_at = -1;

    transport_write_count = 0;
    transport_write_error_at = 3;
    assert (thrift_binary_protocol_write_message_begin (protocol, "test",
                                                        T_CALL, 1, NULL) == -1);
    transport_write_error_at = -1;

    /* clean up */
    thrift_transport_close (transport, NULL);
    g_object_unref (tsocket);
    g_object_unref (protocol);
    assert (wait (&status) == pid);
    assert (status == 0);
  }
}
Beispiel #2
0
/* test reading from the transport after the peer has unexpectedly
   closed the connection */
static void
test_read_after_peer_close(void)
{
  int status;
  pid_t pid;
  int port = 51199;
  GError *err = NULL;

  pid = fork ();
  g_assert (pid >= 0);

  if (pid == 0)
    {
      ThriftServerTransport *server_transport = NULL;
      ThriftTransport *client_transport = NULL;

      /* child listens */
      server_transport = g_object_new (THRIFT_TYPE_SERVER_SOCKET,
				       "port", port,
				       NULL);
      g_assert (server_transport != NULL);

      thrift_server_transport_listen (server_transport, &err);
      g_assert (err == NULL);

      /* wrap the client transport in a ThriftFramedTransport */
      client_transport = g_object_new
	  (THRIFT_TYPE_FRAMED_TRANSPORT,
	   "transport",  thrift_server_transport_accept (server_transport, &err),
	   "r_buf_size", 0,
	   NULL);
      g_assert (err == NULL);
      g_assert (client_transport != NULL);

      /* close the connection immediately after the client connects */
      thrift_transport_close (client_transport, NULL);

      g_object_unref (client_transport);
      g_object_unref (server_transport);

      exit (0);
    } else {
	ThriftSocket *tsocket = NULL;
	ThriftTransport *transport = NULL;
	guchar buf[10]; /* a buffer */

	/* parent connects, wait a bit for the socket to be created */
	sleep (1);

	tsocket = g_object_new (THRIFT_TYPE_SOCKET,
				"hostname", "localhost",
				"port",     port,
				NULL);
	transport = g_object_new (THRIFT_TYPE_FRAMED_TRANSPORT,
				  "transport",  THRIFT_TRANSPORT (tsocket),
				  "w_buf_size", 0,
				  NULL);

	g_assert (thrift_transport_open (transport, NULL) == TRUE);
	g_assert (thrift_transport_is_open (transport));

	/* attempting to read from the transport after the peer has closed
       the connection fails gracefully without generating a critical
       warning or segmentation fault */
	thrift_transport_read (transport, buf, 10, &err);
	g_assert (err != NULL);

	g_error_free (err);
	err = NULL;

	thrift_transport_read_end (transport, &err);
	g_assert (err == NULL);

	thrift_transport_close (transport, &err);
	g_assert (err == NULL);

	g_object_unref (transport);
	g_object_unref (tsocket);

	g_assert (wait (&status) == pid);
	g_assert (status == 0);
    }
}
Beispiel #3
0
static void
test_read_and_write_primitives(void)
{
  int status;
  pid_t pid;
  ThriftSocket *tsocket = NULL;
  ThriftTransport *transport = NULL;
  ThriftBinaryProtocol *tb = NULL;
  ThriftProtocol *protocol = NULL;
  gpointer binary = (gpointer *) TEST_STRING;
  guint32 len = strlen (TEST_STRING);
  int port = TEST_PORT;

  /* fork a server from the client */
  pid = fork ();
  assert (pid >= 0);

  if (pid == 0)
  {
    /* child listens */
    thrift_server_primitives (port);
    exit (0);
  } else {
    /* parent.  wait a bit for the socket to be created. */
    sleep (1);

    /* create a ThriftSocket */
    tsocket = g_object_new (THRIFT_TYPE_SOCKET, "hostname", "localhost",
                            "port", port, NULL);
    transport = THRIFT_TRANSPORT (tsocket);
    thrift_transport_open (transport, NULL);
    assert (thrift_transport_is_open (transport));

    /* create a ThriftBinaryTransport */
    tb = g_object_new (THRIFT_TYPE_BINARY_PROTOCOL, "transport",
                       tsocket, NULL);
    protocol = THRIFT_PROTOCOL (tb);
    assert (protocol != NULL);

    /* write a bunch of primitives */
    assert (thrift_binary_protocol_write_bool (protocol, TEST_BOOL, NULL) > 0);
    assert (thrift_binary_protocol_write_byte (protocol, TEST_BYTE, NULL) > 0);
    assert (thrift_binary_protocol_write_i16 (protocol, TEST_I16, NULL) > 0);
    assert (thrift_binary_protocol_write_i32 (protocol, TEST_I32, NULL) > 0);
    assert (thrift_binary_protocol_write_i64 (protocol, TEST_I64, NULL) > 0);
    assert (thrift_binary_protocol_write_double (protocol, 
                                                 TEST_DOUBLE, NULL) > 0);
    assert (thrift_binary_protocol_write_string (protocol,
                                                 TEST_STRING, NULL) > 0);
    assert (thrift_binary_protocol_write_binary (protocol, binary, 
                                                 len, NULL) > 0);
    assert (thrift_binary_protocol_write_binary (protocol, NULL, 0, NULL) > 0);
    assert (thrift_binary_protocol_write_binary (protocol, binary,
                                                 len, NULL) > 0);

    /* test write errors */
    transport_write_error = 1;
    assert (thrift_binary_protocol_write_byte (protocol, TEST_BYTE, 
                                               NULL) == -1);
    assert (thrift_binary_protocol_write_i16 (protocol, TEST_I16, NULL) == -1);
    assert (thrift_binary_protocol_write_i32 (protocol, TEST_I32, NULL) == -1);
    assert (thrift_binary_protocol_write_i64 (protocol, TEST_I64, NULL) == -1);
    assert (thrift_binary_protocol_write_double (protocol, TEST_DOUBLE,
                                                 NULL) == -1);
    assert (thrift_binary_protocol_write_binary (protocol, binary, len,
                                                 NULL) == -1);
    transport_write_error = 0;

    /* test binary partial failure */
    transport_write_count = 0;
    transport_write_error_at = 1;
    assert (thrift_binary_protocol_write_binary (protocol, binary,
                                                 len, NULL) == -1);
    transport_write_error_at = -1;

    /* clean up */
    thrift_transport_close (transport, NULL);
    g_object_unref (tsocket);
    g_object_unref (protocol);
    assert (wait (&status) == pid);
    assert (status == 0);
  }
}
Beispiel #4
0
static void
test_read_and_write_complex_types (void)
{
  int status;
  pid_t pid;
  ThriftSocket *tsocket = NULL;
  ThriftTransport *transport = NULL;
  ThriftCompactProtocol *tc = NULL;
  ThriftProtocol *protocol = NULL;
  int port = TEST_PORT;

  /* fork a server from the client */
  pid = fork ();
  assert (pid >= 0);

  if (pid == 0)
  {
    /* child listens */
    thrift_server_complex_types (port);
    exit (0);
  } else {
    /* parent.  wait a bit for the socket to be created. */
    sleep (1);

    /* create a ThriftSocket */
    tsocket = g_object_new (THRIFT_TYPE_SOCKET, "hostname", "localhost",
                            "port", port, NULL);
    transport = THRIFT_TRANSPORT (tsocket);
    thrift_transport_open (transport, NULL);
    assert (thrift_transport_is_open (transport));

    /* create a ThriftCompactTransport */
    tc = g_object_new (THRIFT_TYPE_COMPACT_PROTOCOL, "transport",
                       tsocket, NULL);
    protocol = THRIFT_PROTOCOL (tc);
    assert (protocol != NULL);

    /* test structures */
    assert (thrift_compact_protocol_write_struct_begin (protocol,
                                                       NULL, NULL) == 0);
    assert (thrift_compact_protocol_write_struct_end (protocol, NULL) == 0);

    /* test field state w.r.t. deltas */

    assert (thrift_compact_protocol_write_field_begin (protocol, "test",
                                                       T_DOUBLE, 1, NULL) == 1);
    assert (thrift_compact_protocol_write_field_begin (protocol, "test",
                                                       T_DOUBLE,
                                                       16, NULL) == 1);
    assert (thrift_compact_protocol_write_field_begin (protocol, "test",
                                                       T_DOUBLE,
                                                       17, NULL) == 1);
    assert (thrift_compact_protocol_write_field_begin (protocol, "test",
                                                       T_DOUBLE,
                                                       15, NULL) > 1);
    assert (thrift_compact_protocol_write_field_begin (protocol, "test",
                                                       T_DOUBLE,
                                                       30, NULL) == 1);
    assert (thrift_compact_protocol_write_field_begin (protocol, "test",
                                                       T_DOUBLE,
                                                       46, NULL) > 1);
    assert (thrift_compact_protocol_write_field_begin (protocol, "test",
                                                       T_DOUBLE,
                                                       47, NULL) == 1);

    /* test fields */
    assert (thrift_compact_protocol_write_field_begin (protocol, "test",
                                                       T_DOUBLE,
                                                       1, NULL) > 1);
    assert (thrift_compact_protocol_write_field_end (protocol, NULL) == 0);

    /* test field state w.r.t. structs */

    assert (thrift_compact_protocol_write_field_begin (protocol, "test",
                                                       T_DOUBLE,
                                                       1, NULL) > 1);
    assert (thrift_compact_protocol_write_field_end (protocol, NULL) == 0);
    assert (thrift_compact_protocol_write_field_begin (protocol, "test",
                                                       T_DOUBLE,
                                                       16, NULL) == 1);
    assert (thrift_compact_protocol_write_field_end (protocol, NULL) == 0);

    assert (thrift_compact_protocol_write_struct_begin (protocol,
                                                       NULL, NULL) == 0);
    assert (thrift_compact_protocol_write_field_begin (protocol, "test",
                                                       T_DOUBLE,
                                                       17, NULL) > 1);
    assert (thrift_compact_protocol_write_field_end (protocol, NULL) == 0);

    assert (thrift_compact_protocol_write_struct_begin (protocol,
                                                       NULL, NULL) == 0);
    assert (thrift_compact_protocol_write_field_begin (protocol, "test",
                                                       T_DOUBLE,
                                                       18, NULL) > 1);
    assert (thrift_compact_protocol_write_field_end (protocol, NULL) == 0);
    assert (thrift_compact_protocol_write_field_begin (protocol, "test",
                                                       T_DOUBLE,
                                                       19, NULL) == 1);
    assert (thrift_compact_protocol_write_field_end (protocol, NULL) == 0);
    assert (thrift_compact_protocol_write_struct_end (protocol, NULL) == 0);

    assert (thrift_compact_protocol_write_field_begin (protocol, "test",
                                                       T_DOUBLE,
                                                       18, NULL) == 1);
    assert (thrift_compact_protocol_write_field_end (protocol, NULL) == 0);
    assert (thrift_compact_protocol_write_field_begin (protocol, "test",
                                                       T_DOUBLE,
                                                       25, NULL) == 1);
    assert (thrift_compact_protocol_write_field_end (protocol, NULL) == 0);
    assert (thrift_compact_protocol_write_struct_end (protocol, NULL) == 0);

    assert (thrift_compact_protocol_write_field_begin (protocol, "test",
                                                       T_DOUBLE,
                                                       17, NULL) == 1);
    assert (thrift_compact_protocol_write_field_end (protocol, NULL) == 0);

    /* test field state w.r.t. bools */

    /* deltas */
    /* non-bool field -> bool field -> non-bool field */
    assert (thrift_compact_protocol_write_field_begin (protocol, "test",
                                                       T_DOUBLE,
                                                       18, NULL) == 1);
    assert (thrift_compact_protocol_write_field_end (protocol, NULL) == 0);
    assert (thrift_compact_protocol_write_field_begin (protocol, "test", T_BOOL,
                                                       19, NULL) == 0);
    assert (thrift_compact_protocol_write_bool (protocol, TEST_BOOL,
                                                NULL) == 1);
    assert (thrift_compact_protocol_write_field_end (protocol, NULL) == 0);
    assert (thrift_compact_protocol_write_field_begin (protocol, "test",
                                                       T_DOUBLE,
                                                       20, NULL) == 1);
    assert (thrift_compact_protocol_write_field_end (protocol, NULL) == 0);
    /* bool -> bool field -> bool */
    assert (thrift_compact_protocol_write_bool (protocol, TEST_BOOL, NULL) > 0);
    assert (thrift_compact_protocol_write_field_begin (protocol, "test", T_BOOL,
                                                       21, NULL) == 0);
    assert (thrift_compact_protocol_write_bool (protocol, TEST_BOOL,
                                                NULL) == 1);
    assert (thrift_compact_protocol_write_field_end (protocol, NULL) == 0);
    assert (thrift_compact_protocol_write_bool (protocol, TEST_BOOL, NULL) > 0);

    /* no deltas */
    /* non-bool field -> bool field -> non-bool field */
    assert (thrift_compact_protocol_write_field_begin (protocol, "test",
                                                       T_DOUBLE,
                                                       1, NULL) > 1);
    assert (thrift_compact_protocol_write_field_end (protocol, NULL) == 0);
    assert (thrift_compact_protocol_write_field_begin (protocol, "test", T_BOOL,
                                                      1, NULL) == 0);
    assert (thrift_compact_protocol_write_bool (protocol, TEST_BOOL, NULL) > 1);
    assert (thrift_compact_protocol_write_field_end (protocol, NULL) == 0);
    assert (thrift_compact_protocol_write_field_begin (protocol, "test",
                                                       T_DOUBLE,
                                                       1, NULL) > 1);
    assert (thrift_compact_protocol_write_field_end (protocol, NULL) == 0);
    /* bool -> bool field -> bool */
    assert (thrift_compact_protocol_write_bool (protocol, TEST_BOOL, NULL) > 0);
    assert (thrift_compact_protocol_write_field_begin (protocol, "test", T_BOOL,
                                                      1, NULL) == 0);
    assert (thrift_compact_protocol_write_bool (protocol, TEST_BOOL, NULL) > 1);
    assert (thrift_compact_protocol_write_field_end (protocol, NULL) == 0);
    assert (thrift_compact_protocol_write_bool (protocol, TEST_BOOL, NULL) > 0);

    /* test write error */
    transport_write_error = 1;
    assert (thrift_compact_protocol_write_field_begin (protocol, "test",
                                                       T_DOUBLE,
                                                       1, NULL) == -1);
    transport_write_error = 0;

    /* test 2nd write error */
    transport_write_count = 0;
    transport_write_error_at = 1;
    assert (thrift_compact_protocol_write_field_begin (protocol, "test",
                                                       T_DOUBLE,
                                                       1, NULL) == -1);
    transport_write_error_at = -1;

    /* test 2nd read failure on a field */
    thrift_compact_protocol_write_byte (protocol, T_DOUBLE, NULL);

    /* test write_field_stop */
    assert (thrift_compact_protocol_write_field_stop (protocol, NULL) > 0);

    /* write a map */
    assert (thrift_compact_protocol_write_map_begin (protocol, T_DOUBLE,
                                                     T_DOUBLE,
                                                     1, NULL) > 0);
    assert (thrift_compact_protocol_write_map_end (protocol, NULL) == 0);

    /* test 1st read failure on map---nothing to do on our side */

    /* test 2nd read failure on a map */
    thrift_compact_protocol_write_byte (protocol, T_DOUBLE, NULL);

    /* test 1st write failure on a map */
    transport_write_error = 1;
    assert (thrift_compact_protocol_write_map_begin (protocol, T_DOUBLE,
                                                     T_DOUBLE,
                                                     1, NULL) == -1);
    transport_write_error = 0;

    /* test 2nd write failure on a map */
    transport_write_count = 0;
    transport_write_error_at = 1;
    assert (thrift_compact_protocol_write_map_begin (protocol, T_DOUBLE,
                                                     T_DOUBLE,
                                                     1, NULL) == -1);
    transport_write_error_at = -1;

    /* test negative map size */
    thrift_compact_protocol_write_varint32 (tc, -10, NULL);
    thrift_compact_protocol_write_byte (protocol, T_DOUBLE, NULL);

    /* test list operations */
    assert (thrift_compact_protocol_write_list_begin (protocol, T_DOUBLE,
                                                     15, NULL) > 0);
    assert (thrift_compact_protocol_write_list_end (protocol, NULL) == 0);

    /* test 1st read failure on a small list---nothing to do on our end */

    /* test 1st read failure on a big list---nothing to do on our end */

    /* test 2nd read failure on a big list */
    thrift_compact_protocol_write_byte (protocol, (gint8) 0xf0, NULL);

    /* test negative list size */
    thrift_compact_protocol_write_byte (protocol, (gint8) 0xf0, NULL);
    thrift_compact_protocol_write_varint32 (tc, -10, NULL);

    /* test first write error on a small list */
    transport_write_error = 1;
    assert (thrift_compact_protocol_write_list_begin (protocol, T_DOUBLE,
                                                     14, NULL) == -1);
    transport_write_error = 0;

    /* test first write error on a big list */
    transport_write_error = 1;
    assert (thrift_compact_protocol_write_list_begin (protocol, T_DOUBLE,
                                                     15, NULL) == -1);
    transport_write_error = 0;

    /* test 2nd write error on a big list */
    transport_write_count = 0;
    transport_write_error_at = 1;
    assert (thrift_compact_protocol_write_list_begin (protocol, T_DOUBLE,
                                                     15, NULL) == -1);
    transport_write_error_at = -1;

    /* test set operation s*/
    assert (thrift_compact_protocol_write_set_begin (protocol, T_DOUBLE,
                                                    1, NULL) > 0);
    assert (thrift_compact_protocol_write_set_end (protocol, NULL) == 0);

    /* invalid protocol */
    assert (thrift_compact_protocol_write_byte (protocol, 0, NULL) > 0);

    /* invalid version */
    assert (thrift_compact_protocol_write_byte (protocol, (gint8) 0x82u,
                                                NULL) > 0);
    assert (thrift_compact_protocol_write_byte (protocol, 0, NULL) > 0);

    /* send a valid message */
    assert (thrift_compact_protocol_write_byte (protocol, (gint8) 0x82u,
                                                NULL) > 0);
    assert (thrift_compact_protocol_write_byte (protocol, 0x01u, NULL) > 0);
    thrift_compact_protocol_write_varint32 (tc, 1, NULL);
    thrift_compact_protocol_write_string (protocol, "test", NULL);

    /* broken 2nd read */
    thrift_compact_protocol_write_byte (protocol, (gint8) 0x82u, NULL);

    /* send a broken 3rd read */
    thrift_compact_protocol_write_byte (protocol, (gint8) 0x82u, NULL);
    thrift_compact_protocol_write_byte (protocol, 0x01u, NULL);

    /* send a broken 4th read */
    thrift_compact_protocol_write_byte (protocol, (gint8) 0x82u, NULL);
    thrift_compact_protocol_write_byte (protocol, 0x01u, NULL);
    thrift_compact_protocol_write_varint32 (tc, 1, NULL);

    /* send a valid message */
    assert (thrift_compact_protocol_write_message_begin (protocol, "test",
                                                        T_CALL, 1, NULL) > 0);

    assert (thrift_compact_protocol_write_message_end (protocol, NULL) == 0);

    /* send broken writes */
    transport_write_error = 1;
    assert (thrift_compact_protocol_write_message_begin (protocol, "test",
                                                        T_CALL, 1, NULL) == -1);
    transport_write_error = 0;

    transport_write_count = 0;
    transport_write_error_at = 1;
    assert (thrift_compact_protocol_write_message_begin (protocol, "test",
                                                        T_CALL, 1, NULL) == -1);
    transport_write_error_at = -1;

    transport_write_count = 0;
    transport_write_error_at = 2;
    assert (thrift_compact_protocol_write_message_begin (protocol, "test",
                                                        T_CALL, 1, NULL) == -1);
    transport_write_error_at = -1;

    transport_write_count = 0;
    transport_write_error_at = 3;
    assert (thrift_compact_protocol_write_message_begin (protocol, "test",
                                                        T_CALL, 1, NULL) == -1);
    transport_write_error_at = -1;

    /* clean up */
    thrift_transport_close (transport, NULL);
    g_object_unref (tsocket);
    g_object_unref (protocol);
    assert (wait (&status) == pid);
    assert (status == 0);
  }
}