[wing/wip/named-pipe-test-write] DROP IT: the shows a bug when reading and writing to the pipe



commit e9cebccfc8f300540e0a92822ebe4521d11d120a
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Thu Sep 1 13:02:18 2016 +0200

    DROP IT: the shows a bug when reading and writing to the pipe
    
    If the server does not read from the pipe and only writes,
    and the client reads and writes, for some reason strange things
    happen:
     - 1. we get a read on the client when the server did not write anything
       with an error
     - 2. we get the mainloop blocked forever

 tests/named-pipe.c |   40 ++++++++++++++++++++++++++--------------
 1 files changed, 26 insertions(+), 14 deletions(-)
---
diff --git a/tests/named-pipe.c b/tests/named-pipe.c
index 897515f..ba2f9be 100644
--- a/tests/named-pipe.c
+++ b/tests/named-pipe.c
@@ -413,6 +413,7 @@ typedef struct
 {
   gchar data[256];
   gboolean *read;
+  gboolean client;
 } ReadData;
 
 #define MAX_ITERATIONS 100
@@ -427,12 +428,24 @@ on_some_text_read (GObject      *source,
   gssize read;
   GError *error = NULL;
 
+  g_message ("read %s", data->client ? "CLIENT" : "SERVER");
+
   read = g_input_stream_read_finish (G_INPUT_STREAM (source), result, &error);
-  g_assert_no_error (error);
-  g_assert_cmpint (read, ==, strlen (some_text) + 1);
+  if (data->client)
+    {
+      g_assert_cmpint (read, ==, -1);
+      g_assert (error != NULL);
+    }
+  else
+    {
+      g_assert_no_error (error);
+      g_assert_cmpint (read, ==, strlen (some_text) + 1);
+    }
 
   *data->read = TRUE;
   g_free (data);
+
+  g_message ("read 2");
 }
 
 static void
@@ -444,11 +457,15 @@ on_some_text_written (GObject      *source,
   gssize read;
   GError *error = NULL;
 
+  g_message ("write");
+
   read = g_output_stream_write_finish (G_OUTPUT_STREAM (source), result, &error);
   g_assert_no_error (error);
   g_assert_cmpint (read, ==, strlen (some_text) + 1);
 
   *wrote = TRUE;
+
+  g_message ("write2");
 }
 
 static void
@@ -471,14 +488,6 @@ write_and_read (GIOStream *server_stream,
       out = g_io_stream_get_output_stream (server_stream);
       in = g_io_stream_get_input_stream (server_stream);
 
-      g_output_stream_write_async (out,
-                                   some_text,
-                                   strlen (some_text) + 1,
-                                   G_PRIORITY_DEFAULT,
-                                   NULL,
-                                   on_some_text_written,
-                                   &server_wrote);
-
       data = g_new0 (ReadData, 1);
       data->read = &server_read;
       g_input_stream_read_async (in,
@@ -503,6 +512,7 @@ write_and_read (GIOStream *server_stream,
 
       data = g_new0 (ReadData, 1);
       data->read = &client_read;
+      data->client = TRUE;
       g_input_stream_read_async (in,
                                  data->data,
                                  sizeof (data->data),
@@ -513,9 +523,11 @@ write_and_read (GIOStream *server_stream,
 
       do
         g_main_context_iteration (NULL, TRUE);
-      while (!server_wrote || !client_wrote ||
-             !server_read || !client_read);
+      while (!client_wrote ||
+             !server_read);
     }
+
+  g_message ("out of loop");
 }
 
 static void
@@ -679,7 +691,7 @@ main (int   argc,
 
   g_test_bug_base ("http://bugzilla.gnome.org/";);
 
-  g_test_add_func ("/named-pipes/add-named-pipe", test_add_named_pipe);
+  /*g_test_add_func ("/named-pipes/add-named-pipe", test_add_named_pipe);
   g_test_add_func ("/named-pipes/connect-basic", test_connect_basic);
   g_test_add_func ("/named-pipes/connect-before-accept", test_connect_before_accept);
   g_test_add_func ("/named-pipes/connect-sync", test_connect_sync);
@@ -687,7 +699,7 @@ main (int   argc,
   g_test_add_func ("/named-pipes/accept-cancel", test_accept_cancel);
   g_test_add_func ("/named-pipes/connect-accept-cancel", test_connect_accept_cancel);
   g_test_add_func ("/named-pipes/multi-client-basic", test_multi_client_basic);
-  g_test_add_func ("/named-pipes/client-default-timeout", test_client_default_timeout);
+  g_test_add_func ("/named-pipes/client-default-timeout", test_client_default_timeout);*/
   g_test_add_func ("/named-pipes/read-write-basic", test_read_write_basic);
   g_test_add_func ("/named-pipes/read-write-several-connections", test_read_write_several_connections);
   g_test_add_func ("/named-pipes/read-write-same-time-several-connections", 
test_read_write_same_time_several_connections);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]