[banshee] MediaEngineTests: bring assertion exceptions to main thread



commit fa0d60ad36043cb14842e8eedb1fbf1bec994c1c
Author: Andrés G. Aragoneses <knocte gmail com>
Date:   Sun Jan 19 23:53:02 2014 +0100

    MediaEngineTests: bring assertion exceptions to main thread
    
    The AssertTransition() method in the tests was connecting a
    PlayerEventHandler to the PlayerEngineService being tested
    but it didn't have any try-catch around it, which means that
    any generated AssertionException caused by a test not passing
    would really be ignored (just printing a warning on the
    terminal instead of making the NUnit test fail).
    
    A new guarded_handler is now created, which calls the old one,
    and which has a try-catch, which would set any exception caught
    to a variable of the method, which would then later be captured.
    
    The change of the type of the 'handler' variable is not really
    a required change here, but doing it allows us to have the
    compiler complain to us if we try to disconnect the old handler
    instead of the new one called 'guarded_hanlder'.

 .../Banshee.Services/Banshee.MediaEngine/Tests.cs  |   17 ++++++++++++++---
 1 files changed, 14 insertions(+), 3 deletions(-)
---
diff --git a/src/Core/Banshee.Services/Banshee.MediaEngine/Tests.cs 
b/src/Core/Banshee.Services/Banshee.MediaEngine/Tests.cs
index 90b1b83..7f299da 100644
--- a/src/Core/Banshee.Services/Banshee.MediaEngine/Tests.cs
+++ b/src/Core/Banshee.Services/Banshee.MediaEngine/Tests.cs
@@ -169,7 +169,7 @@ namespace Banshee.MediaEngine
             Log.DebugFormat ("AssertTransition: {0}", String.Join (", ", states.Select (s => s.ToString 
()).ToArray ()));
             int result_count = 0;
             var reset_event = new ManualResetEvent (false);
-            var handler = new PlayerEventHandler (a => {
+            var handler = new Action<PlayerEventArgs> (a => {
                 lock (states) {
                     if (result_count < states.Length) {
                         var sca = a as PlayerEventStateChangeArgs;
@@ -201,7 +201,15 @@ namespace Banshee.MediaEngine
                 reset_event.Set ();
             });
 
-            service.ConnectEvent (handler);
+            AssertionException exception = null;
+            var guarded_handler = new PlayerEventHandler (args => {
+                try {
+                    handler (args);
+                } catch (AssertionException ae) {
+                    exception = ae;
+                }
+            });
+            service.ConnectEvent (guarded_handler);
 
             if (action != null) action ();
 
@@ -212,9 +220,12 @@ namespace Banshee.MediaEngine
                     Assert.Fail (String.Format ("Waited {0}s for state/event, didn't happen", seconds));
                     break;
                 }
+                if (exception != null) {
+                    throw exception;
+                }
             }
 
-            service.DisconnectEvent (handler);
+            service.DisconnectEvent (guarded_handler);
         }
 
         //[Test]


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