Bläddra i källkod

Always run stopping strategy

Fixes #82
Lucas Trzesniewski 6 år sedan
förälder
incheckning
26fbf5d02e
2 ändrade filer med 30 tillägg och 4 borttagningar
  1. 12 0
      src/Abc.Zebus.Tests/Core/BusTests.Core.cs
  2. 18 4
      src/Abc.Zebus/Core/Bus.cs

+ 12 - 0
src/Abc.Zebus.Tests/Core/BusTests.Core.cs

@@ -102,6 +102,18 @@ namespace Abc.Zebus.Tests.Core
                 _messageDispatcherMock.Verify(x => x.Stop());
             }
 
+            [Test]
+            public void should_stop_message_dispatcher_when_directory_unsubscription_fails()
+            {
+                _directoryMock.Setup(i => i.UnregisterAsync(It.IsAny<IBus>()))
+                              .Returns(Task.FromException(new InvalidOperationException()));
+
+                _bus.Start();
+                _bus.Stop();
+
+                _messageDispatcherMock.Verify(i => i.Stop());
+            }
+
             [Test]
             public void should_fail_when_starting_started_bus()
             {

+ 18 - 4
src/Abc.Zebus/Core/Bus.cs

@@ -179,7 +179,16 @@ namespace Abc.Zebus.Core
             Status = BusStatus.Stopping;
 
             if (unregister)
-                _directory.UnregisterAsync(this).Wait();
+            {
+                try
+                {
+                    _directory.UnregisterAsync(this).Wait();
+                }
+                catch (Exception ex)
+                {
+                    _logger.Error(ex);
+                }
+            }
 
             lock (_subscriptions)
             {
@@ -193,9 +202,14 @@ namespace Abc.Zebus.Core
                 }
             }
 
-            _stoppingStrategy.Stop(_transport, _messageDispatcher);
-
-            Status = BusStatus.Stopped;
+            try
+            {
+                _stoppingStrategy.Stop(_transport, _messageDispatcher);
+            }
+            finally
+            {
+                Status = BusStatus.Stopped;
+            }
 
             _messageIdToTaskCompletionSources.Clear();
         }