From ce46ced0f52614bada35ecd5e3473d244642eaaf Mon Sep 17 00:00:00 2001 From: Tiago Rodrigues <64850634+1Krypt0@users.noreply.github.com> Date: Tue, 27 Oct 2026 15:12:58 +0000 Subject: [PATCH 1/2] Fix "Collection was modified" in LocalEventBus when handlers subscribe during a publish Loop over a copy of each handler list taken under its lock, as EventBusBase.TriggerHandlersAsync does since #21786. Resolves #26342 --- .../Volo/Abp/EventBus/Local/LocalEventBus.cs | 6 +- .../Local/EventBus_Concurrency_Test.cs | 83 +++++++++++++++++++ 2 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 framework/test/Volo.Abp.EventBus.Tests/Volo/Abp/EventBus/Local/EventBus_Concurrency_Test.cs diff --git a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Local/LocalEventBus.cs b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Local/LocalEventBus.cs index 729afa2915..8411a50a0d 100644 --- a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Local/LocalEventBus.cs +++ b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Local/LocalEventBus.cs @@ -217,7 +217,7 @@ public class LocalEventBus : EventBusBase, ILocalEventBus, ISingletonDependency foreach (var handlerFactory in HandlerFactories.Where(hf => ShouldTriggerEventForHandler(eventType, hf.Key))) { - foreach (var factory in handlerFactory.Value) + foreach (var factory in handlerFactory.Value.Locking(factories => factories.ToArray())) { handlerFactoryList.Add(new Tuple( factory, @@ -228,7 +228,7 @@ public class LocalEventBus : EventBusBase, ILocalEventBus, ISingletonDependency foreach (var handlerFactory in DynamicEventHandlerFactories.Where(aehf => eventNames.Contains(aehf.Key))) { - foreach (var factory in handlerFactory.Value) + foreach (var factory in handlerFactory.Value.Locking(factories => factories.ToArray())) { handlerFactoryList.Add(new Tuple( factory, @@ -252,7 +252,7 @@ public class LocalEventBus : EventBusBase, ILocalEventBus, ISingletonDependency foreach (var handlerFactory in DynamicEventHandlerFactories.Where(aehf => aehf.Key == eventName)) { - foreach (var factory in handlerFactory.Value) + foreach (var factory in handlerFactory.Value.Locking(factories => factories.ToArray())) { using var handler = factory.GetHandler(); var handlerType = handler.EventHandler.GetType(); diff --git a/framework/test/Volo.Abp.EventBus.Tests/Volo/Abp/EventBus/Local/EventBus_Concurrency_Test.cs b/framework/test/Volo.Abp.EventBus.Tests/Volo/Abp/EventBus/Local/EventBus_Concurrency_Test.cs new file mode 100644 index 0000000000..62688199b5 --- /dev/null +++ b/framework/test/Volo.Abp.EventBus.Tests/Volo/Abp/EventBus/Local/EventBus_Concurrency_Test.cs @@ -0,0 +1,83 @@ +using System.Threading; +using System.Threading.Tasks; +using Xunit; + +namespace Volo.Abp.EventBus.Local; + +public class EventBus_Concurrency_Test : EventBusTestBase +{ + private const int PublishCount = 10_000; + + [Fact] + public async Task Should_Publish_While_Other_Handlers_Subscribe_And_Unsubscribe() + { + var handledCount = 0; + using var subscription = LocalEventBus.Subscribe(_ => + { + Interlocked.Increment(ref handledCount); + return Task.CompletedTask; + }); + + using var cts = new CancellationTokenSource(); + var churn = Task.Run(() => + { + while (!cts.IsCancellationRequested) + { + LocalEventBus.Subscribe(_ => Task.CompletedTask).Dispose(); + } + }); + + try + { + for (var i = 0; i < PublishCount; i++) + { + await LocalEventBus.PublishAsync(new MySimpleEventData(1), onUnitOfWorkComplete: false); + } + } + finally + { + cts.Cancel(); + await churn; + } + + Assert.Equal(PublishCount, handledCount); + } + + [Fact] + public async Task Should_Publish_Dynamic_Event_While_Other_Handlers_Subscribe_And_Unsubscribe() + { + const string eventName = "MyConcurrencyTestDynamicEvent"; + var handledCount = 0; + using var subscription = LocalEventBus.Subscribe(eventName, new SingleInstanceHandlerFactory( + new ActionEventHandler(_ => + { + Interlocked.Increment(ref handledCount); + return Task.CompletedTask; + }))); + + using var cts = new CancellationTokenSource(); + var churn = Task.Run(() => + { + while (!cts.IsCancellationRequested) + { + LocalEventBus.Subscribe(eventName, new SingleInstanceHandlerFactory( + new ActionEventHandler(_ => Task.CompletedTask))).Dispose(); + } + }); + + try + { + for (var i = 0; i < PublishCount; i++) + { + await LocalEventBus.PublishAsync(eventName, new { Value = 1 }, onUnitOfWorkComplete: false); + } + } + finally + { + cts.Cancel(); + await churn; + } + + Assert.Equal(PublishCount, handledCount); + } +} From 1321bfbb7339da5862a7b5539a22f3b1e3cd80f5 Mon Sep 17 00:00:00 2001 From: maliming Date: Wed, 28 Oct 2026 13:27:54 +0800 Subject: [PATCH 2/2] Lock handler lists in distributed event buses and harden concurrency tests --- .../Azure/AzureDistributedEventBus.cs | 36 +++++++--- .../EventBus/Dapr/DaprDistributedEventBus.cs | 17 +++-- .../Kafka/KafkaDistributedEventBus.cs | 36 +++++++--- .../RabbitMq/RabbitMqDistributedEventBus.cs | 38 ++++++++--- .../Rebus/RebusDistributedEventBus.cs | 36 +++++++--- .../Local/EventBus_Concurrency_Test.cs | 66 ++++++++++++------- 6 files changed, 165 insertions(+), 64 deletions(-) diff --git a/framework/src/Volo.Abp.EventBus.Azure/Volo/Abp/EventBus/Azure/AzureDistributedEventBus.cs b/framework/src/Volo.Abp.EventBus.Azure/Volo/Abp/EventBus/Azure/AzureDistributedEventBus.cs index 922ab95412..4344e3c72b 100644 --- a/framework/src/Volo.Abp.EventBus.Azure/Volo/Abp/EventBus/Azure/AzureDistributedEventBus.cs +++ b/framework/src/Volo.Abp.EventBus.Azure/Volo/Abp/EventBus/Azure/AzureDistributedEventBus.cs @@ -119,13 +119,22 @@ public class AzureDistributedEventBus : DistributedEventBusBase, ISingletonDepen { var handlerFactories = GetOrCreateHandlerFactories(eventType); - if (factory.IsInFactories(handlerFactories)) + var added = handlerFactories.Locking(factories => + { + if (factory.IsInFactories(factories)) + { + return false; + } + + factories.Add(factory); + return true; + }); + + if (!added) { return NullDisposable.Instance; } - handlerFactories.Add(factory); - return new EventHandlerFactoryUnregistrar(this, eventType, factory); } @@ -134,13 +143,22 @@ public class AzureDistributedEventBus : DistributedEventBusBase, ISingletonDepen { var handlerFactories = GetOrCreateDynamicHandlerFactories(eventName); - if (handler.IsInFactories(handlerFactories)) + var added = handlerFactories.Locking(factories => + { + if (handler.IsInFactories(factories)) + { + return false; + } + + factories.Add(handler); + return true; + }); + + if (!added) { return NullDisposable.Instance; } - handlerFactories.Add(handler); - return new DynamicEventHandlerFactoryUnregistrar(this, eventName, handler); } @@ -396,12 +414,12 @@ public class AzureDistributedEventBus : DistributedEventBusBase, ISingletonDepen foreach (var handlerFactory in HandlerFactories.Where(hf => ShouldTriggerEventForHandler(eventType, hf.Key))) { - handlerFactoryList.Add(new EventTypeWithEventHandlerFactories(handlerFactory.Key, handlerFactory.Value)); + handlerFactoryList.Add(new EventTypeWithEventHandlerFactories(handlerFactory.Key, handlerFactory.Value.Locking(factories => factories.ToList()))); } foreach (var handlerFactory in DynamicHandlerFactories.Where(aehf => eventNames.Contains(aehf.Key))) { - handlerFactoryList.Add(new EventTypeWithEventHandlerFactories(typeof(DynamicEventData), handlerFactory.Value)); + handlerFactoryList.Add(new EventTypeWithEventHandlerFactories(typeof(DynamicEventData), handlerFactory.Value.Locking(factories => factories.ToList()))); } return handlerFactoryList.ToArray(); @@ -452,7 +470,7 @@ public class AzureDistributedEventBus : DistributedEventBusBase, ISingletonDepen foreach (var handlerFactory in DynamicHandlerFactories.Where(hf => hf.Key == eventName)) { - result.Add(new EventTypeWithEventHandlerFactories(typeof(DynamicEventData), handlerFactory.Value)); + result.Add(new EventTypeWithEventHandlerFactories(typeof(DynamicEventData), handlerFactory.Value.Locking(factories => factories.ToList()))); } return result; diff --git a/framework/src/Volo.Abp.EventBus.Dapr/Volo/Abp/EventBus/Dapr/DaprDistributedEventBus.cs b/framework/src/Volo.Abp.EventBus.Dapr/Volo/Abp/EventBus/Dapr/DaprDistributedEventBus.cs index 5e89571554..37968ddd53 100644 --- a/framework/src/Volo.Abp.EventBus.Dapr/Volo/Abp/EventBus/Dapr/DaprDistributedEventBus.cs +++ b/framework/src/Volo.Abp.EventBus.Dapr/Volo/Abp/EventBus/Dapr/DaprDistributedEventBus.cs @@ -69,13 +69,22 @@ public class DaprDistributedEventBus : DistributedEventBusBase, ISingletonDepend { var handlerFactories = GetOrCreateHandlerFactories(eventType); - if (factory.IsInFactories(handlerFactories)) + var added = handlerFactories.Locking(factories => + { + if (factory.IsInFactories(factories)) + { + return false; + } + + factories.Add(factory); + return true; + }); + + if (!added) { return NullDisposable.Instance; } - handlerFactories.Add(factory); - return new EventHandlerFactoryUnregistrar(this, eventType, factory); } @@ -273,7 +282,7 @@ public class DaprDistributedEventBus : DistributedEventBusBase, ISingletonDepend foreach (var handlerFactory in HandlerFactories.Where(hf => ShouldTriggerEventForHandler(eventType, hf.Key))) { - handlerFactoryList.Add(new EventTypeWithEventHandlerFactories(handlerFactory.Key, handlerFactory.Value)); + handlerFactoryList.Add(new EventTypeWithEventHandlerFactories(handlerFactory.Key, handlerFactory.Value.Locking(factories => factories.ToList()))); } return handlerFactoryList.ToArray(); diff --git a/framework/src/Volo.Abp.EventBus.Kafka/Volo/Abp/EventBus/Kafka/KafkaDistributedEventBus.cs b/framework/src/Volo.Abp.EventBus.Kafka/Volo/Abp/EventBus/Kafka/KafkaDistributedEventBus.cs index 4ac6d4a805..017355a5e5 100644 --- a/framework/src/Volo.Abp.EventBus.Kafka/Volo/Abp/EventBus/Kafka/KafkaDistributedEventBus.cs +++ b/framework/src/Volo.Abp.EventBus.Kafka/Volo/Abp/EventBus/Kafka/KafkaDistributedEventBus.cs @@ -118,13 +118,22 @@ public class KafkaDistributedEventBus : DistributedEventBusBase, ISingletonDepen { var handlerFactories = GetOrCreateHandlerFactories(eventType); - if (factory.IsInFactories(handlerFactories)) + var added = handlerFactories.Locking(factories => + { + if (factory.IsInFactories(factories)) + { + return false; + } + + factories.Add(factory); + return true; + }); + + if (!added) { return NullDisposable.Instance; } - handlerFactories.Add(factory); - return new EventHandlerFactoryUnregistrar(this, eventType, factory); } @@ -133,13 +142,22 @@ public class KafkaDistributedEventBus : DistributedEventBusBase, ISingletonDepen { var handlerFactories = GetOrCreateDynamicHandlerFactories(eventName); - if (handler.IsInFactories(handlerFactories)) + var added = handlerFactories.Locking(factories => + { + if (handler.IsInFactories(factories)) + { + return false; + } + + factories.Add(handler); + return true; + }); + + if (!added) { return NullDisposable.Instance; } - handlerFactories.Add(handler); - return new DynamicEventHandlerFactoryUnregistrar(this, eventName, handler); } @@ -427,12 +445,12 @@ public class KafkaDistributedEventBus : DistributedEventBusBase, ISingletonDepen foreach (var handlerFactory in HandlerFactories.Where(hf => ShouldTriggerEventForHandler(eventType, hf.Key))) { - handlerFactoryList.Add(new EventTypeWithEventHandlerFactories(handlerFactory.Key, handlerFactory.Value)); + handlerFactoryList.Add(new EventTypeWithEventHandlerFactories(handlerFactory.Key, handlerFactory.Value.Locking(factories => factories.ToList()))); } foreach (var handlerFactory in DynamicHandlerFactories.Where(aehf => eventNames.Contains(aehf.Key))) { - handlerFactoryList.Add(new EventTypeWithEventHandlerFactories(typeof(DynamicEventData), handlerFactory.Value)); + handlerFactoryList.Add(new EventTypeWithEventHandlerFactories(typeof(DynamicEventData), handlerFactory.Value.Locking(factories => factories.ToList()))); } return handlerFactoryList.ToArray(); @@ -481,7 +499,7 @@ public class KafkaDistributedEventBus : DistributedEventBusBase, ISingletonDepen foreach (var handlerFactory in DynamicHandlerFactories.Where(hf => hf.Key == eventName)) { - result.Add(new EventTypeWithEventHandlerFactories(typeof(DynamicEventData), handlerFactory.Value)); + result.Add(new EventTypeWithEventHandlerFactories(typeof(DynamicEventData), handlerFactory.Value.Locking(factories => factories.ToList()))); } return result; diff --git a/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/RabbitMqDistributedEventBus.cs b/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/RabbitMqDistributedEventBus.cs index 529a16ddba..29f4d4d416 100644 --- a/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/RabbitMqDistributedEventBus.cs +++ b/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/RabbitMqDistributedEventBus.cs @@ -138,13 +138,22 @@ public class RabbitMqDistributedEventBus : DistributedEventBusBase, IRabbitMqDis { var handlerFactories = GetOrCreateHandlerFactories(eventType); - if (factory.IsInFactories(handlerFactories)) + var added = handlerFactories.Locking(factories => + { + if (factory.IsInFactories(factories)) + { + return false; + } + + factories.Add(factory); + return true; + }); + + if (!added) { return NullDisposable.Instance; } - handlerFactories.Add(factory); - if (handlerFactories.Count == 1) //TODO: Multi-threading! { Consumer.BindAsync(EventNameAttribute.GetNameOrDefault(eventType)); @@ -157,14 +166,23 @@ public class RabbitMqDistributedEventBus : DistributedEventBusBase, IRabbitMqDis public override IDisposable Subscribe(string eventName, IEventHandlerFactory handler) { var handlerFactories = GetOrCreateDynamicHandlerFactories(eventName); - - if (handler.IsInFactories(handlerFactories)) + + var added = handlerFactories.Locking(factories => + { + if (handler.IsInFactories(factories)) + { + return false; + } + + factories.Add(handler); + return true; + }); + + if (!added) { return NullDisposable.Instance; } - handlerFactories.Add(handler); - if (handlerFactories.Count == 1) //TODO: Multi-threading! { Consumer.BindAsync(eventName); @@ -494,12 +512,12 @@ public class RabbitMqDistributedEventBus : DistributedEventBusBase, IRabbitMqDis foreach (var handlerFactory in HandlerFactories.Where(hf => ShouldTriggerEventForHandler(eventType, hf.Key))) { - handlerFactoryList.Add(new EventTypeWithEventHandlerFactories(handlerFactory.Key, handlerFactory.Value)); + handlerFactoryList.Add(new EventTypeWithEventHandlerFactories(handlerFactory.Key, handlerFactory.Value.Locking(factories => factories.ToList()))); } foreach (var handlerFactory in DynamicHandlerFactories.Where(aehf => eventNames.Contains(aehf.Key))) { - handlerFactoryList.Add(new EventTypeWithEventHandlerFactories(typeof(DynamicEventData), handlerFactory.Value)); + handlerFactoryList.Add(new EventTypeWithEventHandlerFactories(typeof(DynamicEventData), handlerFactory.Value.Locking(factories => factories.ToList()))); } return handlerFactoryList.ToArray(); @@ -548,7 +566,7 @@ public class RabbitMqDistributedEventBus : DistributedEventBusBase, IRabbitMqDis foreach (var handlerFactory in DynamicHandlerFactories.Where(hf => hf.Key == eventName)) { - result.Add(new EventTypeWithEventHandlerFactories(typeof(DynamicEventData), handlerFactory.Value)); + result.Add(new EventTypeWithEventHandlerFactories(typeof(DynamicEventData), handlerFactory.Value.Locking(factories => factories.ToList()))); } return result; diff --git a/framework/src/Volo.Abp.EventBus.Rebus/Volo/Abp/EventBus/Rebus/RebusDistributedEventBus.cs b/framework/src/Volo.Abp.EventBus.Rebus/Volo/Abp/EventBus/Rebus/RebusDistributedEventBus.cs index b44b65bd4a..2304acaa4a 100644 --- a/framework/src/Volo.Abp.EventBus.Rebus/Volo/Abp/EventBus/Rebus/RebusDistributedEventBus.cs +++ b/framework/src/Volo.Abp.EventBus.Rebus/Volo/Abp/EventBus/Rebus/RebusDistributedEventBus.cs @@ -109,13 +109,22 @@ public class RebusDistributedEventBus : DistributedEventBusBase, ISingletonDepen { var handlerFactories = GetOrCreateHandlerFactories(eventType); - if (factory.IsInFactories(handlerFactories)) + var added = handlerFactories.Locking(factories => + { + if (factory.IsInFactories(factories)) + { + return false; + } + + factories.Add(factory); + return true; + }); + + if (!added) { return NullDisposable.Instance; } - handlerFactories.Add(factory); - if (handlerFactories.Count == 1) //TODO: Multi-threading! { Rebus.Subscribe(eventType); @@ -129,12 +138,21 @@ public class RebusDistributedEventBus : DistributedEventBusBase, ISingletonDepen { var handlerFactories = GetOrCreateDynamicHandlerFactories(eventName); - if (handler.IsInFactories(handlerFactories)) + var added = handlerFactories.Locking(factories => + { + if (handler.IsInFactories(factories)) + { + return false; + } + + factories.Add(handler); + return true; + }); + + if (!added) { return NullDisposable.Instance; } - - handlerFactories.Add(handler); if (DynamicHandlerFactories.Count == 1) //TODO: Multi-threading! { @@ -392,12 +410,12 @@ public class RebusDistributedEventBus : DistributedEventBusBase, ISingletonDepen foreach (var handlerFactory in HandlerFactories.Where(hf => ShouldTriggerEventForHandler(eventType, hf.Key))) { - handlerFactoryList.Add(new EventTypeWithEventHandlerFactories(handlerFactory.Key, handlerFactory.Value)); + handlerFactoryList.Add(new EventTypeWithEventHandlerFactories(handlerFactory.Key, handlerFactory.Value.Locking(factories => factories.ToList()))); } foreach (var handlerFactory in DynamicHandlerFactories.Where(aehf => eventNames.Contains(aehf.Key))) { - handlerFactoryList.Add(new EventTypeWithEventHandlerFactories(typeof(DynamicEventData), handlerFactory.Value)); + handlerFactoryList.Add(new EventTypeWithEventHandlerFactories(typeof(DynamicEventData), handlerFactory.Value.Locking(factories => factories.ToList()))); } return handlerFactoryList.ToArray(); @@ -446,7 +464,7 @@ public class RebusDistributedEventBus : DistributedEventBusBase, ISingletonDepen foreach (var handlerFactory in DynamicHandlerFactories.Where(hf => hf.Key == eventName)) { - result.Add(new EventTypeWithEventHandlerFactories(typeof(DynamicEventData), handlerFactory.Value)); + result.Add(new EventTypeWithEventHandlerFactories(typeof(DynamicEventData), handlerFactory.Value.Locking(factories => factories.ToList()))); } return result; diff --git a/framework/test/Volo.Abp.EventBus.Tests/Volo/Abp/EventBus/Local/EventBus_Concurrency_Test.cs b/framework/test/Volo.Abp.EventBus.Tests/Volo/Abp/EventBus/Local/EventBus_Concurrency_Test.cs index 62688199b5..0c285390da 100644 --- a/framework/test/Volo.Abp.EventBus.Tests/Volo/Abp/EventBus/Local/EventBus_Concurrency_Test.cs +++ b/framework/test/Volo.Abp.EventBus.Tests/Volo/Abp/EventBus/Local/EventBus_Concurrency_Test.cs @@ -1,5 +1,7 @@ +using System; using System.Threading; using System.Threading.Tasks; +using Shouldly; using Xunit; namespace Volo.Abp.EventBus.Local; @@ -18,29 +20,31 @@ public class EventBus_Concurrency_Test : EventBusTestBase return Task.CompletedTask; }); - using var cts = new CancellationTokenSource(); - var churn = Task.Run(() => + await PublishWhileChurningAsync( + () => LocalEventBus.Subscribe(_ => Task.CompletedTask).Dispose(), + () => LocalEventBus.PublishAsync(new MySimpleEventData(1), onUnitOfWorkComplete: false)); + + handledCount.ShouldBe(PublishCount); + } + + [Fact] + public async Task Should_Publish_While_Dynamic_Handlers_Of_The_Same_Event_Subscribe_And_Unsubscribe() + { + var handledCount = 0; + using var subscription = LocalEventBus.Subscribe(_ => { - while (!cts.IsCancellationRequested) - { - LocalEventBus.Subscribe(_ => Task.CompletedTask).Dispose(); - } + Interlocked.Increment(ref handledCount); + return Task.CompletedTask; }); - try - { - for (var i = 0; i < PublishCount; i++) - { - await LocalEventBus.PublishAsync(new MySimpleEventData(1), onUnitOfWorkComplete: false); - } - } - finally - { - cts.Cancel(); - await churn; - } + var eventName = EventNameAttribute.GetNameOrDefault(); + + await PublishWhileChurningAsync( + () => LocalEventBus.Subscribe(eventName, new SingleInstanceHandlerFactory( + new ActionEventHandler(_ => Task.CompletedTask))).Dispose(), + () => LocalEventBus.PublishAsync(new MySimpleEventData(1), onUnitOfWorkComplete: false)); - Assert.Equal(PublishCount, handledCount); + handledCount.ShouldBe(PublishCount); } [Fact] @@ -55,21 +59,37 @@ public class EventBus_Concurrency_Test : EventBusTestBase return Task.CompletedTask; }))); + await PublishWhileChurningAsync( + () => LocalEventBus.Subscribe(eventName, new SingleInstanceHandlerFactory( + new ActionEventHandler(_ => Task.CompletedTask))).Dispose(), + () => LocalEventBus.PublishAsync(eventName, new { Value = 1 }, onUnitOfWorkComplete: false)); + + handledCount.ShouldBe(PublishCount); + } + + private static async Task PublishWhileChurningAsync(Action subscribeAndUnsubscribe, Func publish) + { + var churnStarted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var churnCount = 0; + using var cts = new CancellationTokenSource(); var churn = Task.Run(() => { + churnStarted.TrySetResult(); while (!cts.IsCancellationRequested) { - LocalEventBus.Subscribe(eventName, new SingleInstanceHandlerFactory( - new ActionEventHandler(_ => Task.CompletedTask))).Dispose(); + subscribeAndUnsubscribe(); + Interlocked.Increment(ref churnCount); } }); try { + await churnStarted.Task.WaitAsync(TimeSpan.FromSeconds(10)); + for (var i = 0; i < PublishCount; i++) { - await LocalEventBus.PublishAsync(eventName, new { Value = 1 }, onUnitOfWorkComplete: false); + await publish(); } } finally @@ -78,6 +98,6 @@ public class EventBus_Concurrency_Test : EventBusTestBase await churn; } - Assert.Equal(PublishCount, handledCount); + churnCount.ShouldBeGreaterThan(0); } }