[glib/wip/rishi/gtask-return-cancellation-test] gio/tests/task: Run the worker indefinitely until it's cancelled



commit 70eb6b13d3bba5c348321413a1055316ba86320e
Author: Debarshi Ray <debarshir gnome org>
Date:   Sun Feb 10 20:11:22 2019 +0100

    gio/tests/task: Run the worker indefinitely until it's cancelled
    
    Currently, the actual asynchronous work, represented by
    asynchronous_cancellation_run_task, was over before the GCancellable
    could be triggered. While that doesn't invalidate the purpose of the
    test, since it's fundamentally about cancellation, it would be
    nicer if the cancellation actually served some purpose instead of
    being a mere formality.
    
    https://gitlab.gnome.org/GNOME/glib/issues/1608

 gio/tests/task.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
---
diff --git a/gio/tests/task.c b/gio/tests/task.c
index bff775886..ddaaee85e 100644
--- a/gio/tests/task.c
+++ b/gio/tests/task.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2012 Red Hat, Inc.
+ * Copyright 2012-2019 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -665,6 +665,7 @@ asynchronous_cancellation_callback (GObject      *object,
                                     gpointer      user_data)
 {
   GError *error = NULL;
+  guint run_task_id;
 
   g_assert_null (object);
   g_assert_true (g_task_is_valid (result, object));
@@ -672,6 +673,9 @@ asynchronous_cancellation_callback (GObject      *object,
   g_assert_true (g_task_had_error (G_TASK (result)));
   g_assert_false (g_task_get_completed (G_TASK (result)));
 
+  run_task_id = GPOINTER_TO_UINT (g_task_get_task_data (G_TASK (result)));
+  g_assert_cmpuint (run_task_id, ==, 0);
+
   g_task_propagate_boolean (G_TASK (result), &error);
   g_assert_error (error, G_IO_ERROR, G_IO_ERROR_CANCELLED);
   g_clear_error (&error);
@@ -706,8 +710,10 @@ asynchronous_cancellation_cancelled (GCancellable *cancellable,
   g_assert_true (cancellable == g_task_get_cancellable (task));
 
   run_task_id = GPOINTER_TO_UINT (g_task_get_task_data (task));
-  if (run_task_id != 0)
-    g_source_remove (run_task_id);
+  g_assert_cmpuint (run_task_id, !=, 0);
+
+  g_source_remove (run_task_id);
+  g_task_set_task_data (task, GUINT_TO_POINTER (0), NULL);
 
   g_task_return_boolean (task, FALSE);
   g_assert_false (g_task_get_completed (task));
@@ -723,8 +729,7 @@ asynchronous_cancellation_run_task (gpointer user_data)
   g_assert_true (G_IS_CANCELLABLE (cancellable));
   g_assert_false (g_cancellable_is_cancelled (cancellable));
 
-  g_task_set_task_data (task, GUINT_TO_POINTER (0), NULL);
-  return G_SOURCE_REMOVE;
+  return G_SOURCE_CONTINUE;
 }
 
 /* Test that cancellation is always asynchronous. The completion callback for


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