[geary/wip/781488-aliyun-greeting-error: 3/7] Assorted async test case fixes.



commit 019499619b3ab6cd4cc3b0d733a9413552093cf5
Author: Michael James Gratton <mike vee net>
Date:   Mon Oct 30 11:53:18 2017 +1100

    Assorted async test case fixes.
    
    * test/testcase.vala (TestCase): Make the test case's main loop
      accessible to subclasses so they are using the same one we are.
      (TestCase::async_result): Use GLib main context rather than GTK+ main
      loop so that test cases with async methods work even when GTK+ not
      present.
      (TestCase::async_complete): Ensure the main loop is woken when an async
      test completes so the test case doesn't block if it loses the race with
      async_result();

 test/testcase.vala |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
---
diff --git a/test/testcase.vala b/test/testcase.vala
index 291ead9..bb94df4 100644
--- a/test/testcase.vala
+++ b/test/testcase.vala
@@ -24,6 +24,8 @@
 
 public abstract class Gee.TestCase : Object {
 
+    protected MainContext main_loop = MainContext.default();
+
        private GLib.TestSuite suite;
        private Adaptor[] adaptors = new Adaptor[0];
     private AsyncQueue<AsyncResult> async_results = new AsyncQueue<AsyncResult>();
@@ -56,12 +58,15 @@ public abstract class Gee.TestCase : Object {
 
     protected void async_complete(AsyncResult result) {
         this.async_results.push(result);
+        // notify the loop so that if async_result() has already been
+        // called, that method won't block
+        this.main_loop.wakeup();
     }
 
     protected AsyncResult async_result() {
         AsyncResult? result = null;
         while (result == null) {
-            Gtk.main_iteration();
+            this.main_loop.iteration(true);
             result = this.async_results.try_pop();
         }
         return result;


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