diff --git a/src/Squidex.Infrastructure/CQRS/Events/Actors/EventConsumerActor.cs b/src/Squidex.Infrastructure/CQRS/Events/Actors/EventConsumerActor.cs index 1b1c3285b..c8f722b6f 100644 --- a/src/Squidex.Infrastructure/CQRS/Events/Actors/EventConsumerActor.cs +++ b/src/Squidex.Infrastructure/CQRS/Events/Actors/EventConsumerActor.cs @@ -19,7 +19,7 @@ namespace Squidex.Infrastructure.CQRS.Events.Actors private readonly EventDataFormatter formatter; private readonly IEventStore eventStore; private readonly ISemanticLog log; - private readonly TaskFactory taskFactory = new TaskFactory(new LimitedConcurrencyLevelTaskScheduler(1)); + private readonly SingleThreadedDispatcher dispatcher = new SingleThreadedDispatcher(1); private IEventSubscription currentSubscription; private IEventConsumer eventConsumer; diff --git a/src/Squidex.Infrastructure/States/StateFactory.cs b/src/Squidex.Infrastructure/States/StateFactory.cs index 8fda483af..e6d86bf9c 100644 --- a/src/Squidex.Infrastructure/States/StateFactory.cs +++ b/src/Squidex.Infrastructure/States/StateFactory.cs @@ -76,7 +76,7 @@ namespace Squidex.Infrastructure.States .SetAbsoluteExpiration(CacheDuration) .RegisterPostEvictionCallback((k, v, r, s) => { - taskFactory.StartNew(async () => + taskFactory.StartNew(() => { state.Dispose(); states.Remove(state); diff --git a/tests/Squidex.Infrastructure.Tests/InMemoryPubSubTests.cs b/tests/Squidex.Infrastructure.Tests/InMemoryPubSubTests.cs index 4d9c40d76..f17cce7bc 100644 --- a/tests/Squidex.Infrastructure.Tests/InMemoryPubSubTests.cs +++ b/tests/Squidex.Infrastructure.Tests/InMemoryPubSubTests.cs @@ -27,68 +27,68 @@ namespace Squidex.Infrastructure public string Text { get; set; } } - //[Fact] - //public void Should_publish_to_handlers() - //{ - // var channel1Events = new List(); - // var channel2Events = new List(); - - // sut.Subscribe(m => - // { - // channel1Events.Add(m.Text); - // }); - - // sut.Subscribe(m => - // { - // channel1Events.Add(m.Text); - // }); - - // sut.Subscribe(m => - // { - // channel2Events.Add(m.Text); - // }); - - // sut.Publish(new MessageA { Text = "1" }, true); - // sut.Publish(new MessageA { Text = "2" }, true); - // sut.Publish(new MessageA { Text = "3" }, false); - - // sut.Publish(new MessageB { Text = "a" }, true); - // sut.Publish(new MessageB { Text = "b" }, true); - - // Assert.Equal(new[] { "1", "1", "2", "2" }, channel1Events.ToArray()); - // Assert.Equal(new[] { "a", "b" }, channel2Events.ToArray()); - //} - - //[Fact] - //public async Task Should_make_request_reply_requests() - //{ - // sut.ReceiveAsync(x => - // { - // return Task.FromResult(x + x); - // }, true); - - // var response = await sut.RequestAsync(2, TimeSpan.FromSeconds(2), true); - - // Assert.Equal(4, response); - //} - - //[Fact] - //public async Task Should_timeout_when_response_is_too_slow() - //{ - // sut.ReceiveAsync(async x => - // { - // await Task.Delay(1000); - - // return x + x; - // }, true); - - // await Assert.ThrowsAsync(() => sut.RequestAsync(1, TimeSpan.FromSeconds(0.5), true)); - //} - - //[Fact] - //public async Task Should_timeout_when_nobody_responds() - //{ - // await Assert.ThrowsAsync(() => sut.RequestAsync(2, TimeSpan.FromSeconds(0.5), true)); - //} + [Fact] + public void Should_publish_to_handlers() + { + var channel1Events = new List(); + var channel2Events = new List(); + + sut.Subscribe(m => + { + channel1Events.Add(m.Text); + }); + + sut.Subscribe(m => + { + channel1Events.Add(m.Text); + }); + + sut.Subscribe(m => + { + channel2Events.Add(m.Text); + }); + + sut.Publish(new MessageA { Text = "1" }, true); + sut.Publish(new MessageA { Text = "2" }, true); + sut.Publish(new MessageA { Text = "3" }, false); + + sut.Publish(new MessageB { Text = "a" }, true); + sut.Publish(new MessageB { Text = "b" }, true); + + Assert.Equal(new[] { "1", "1", "2", "2" }, channel1Events.ToArray()); + Assert.Equal(new[] { "a", "b" }, channel2Events.ToArray()); + } + + [Fact] + public async Task Should_make_request_reply_requests() + { + sut.ReceiveAsync(x => + { + return Task.FromResult(x + x); + }, true); + + var response = await sut.RequestAsync(2, TimeSpan.FromSeconds(2), true); + + Assert.Equal(4, response); + } + + [Fact] + public async Task Should_timeout_when_response_is_too_slow() + { + sut.ReceiveAsync(async x => + { + await Task.Delay(1000); + + return x + x; + }, true); + + await Assert.ThrowsAsync(() => sut.RequestAsync(1, TimeSpan.FromSeconds(0.5), true)); + } + + [Fact] + public async Task Should_timeout_when_nobody_responds() + { + await Assert.ThrowsAsync(() => sut.RequestAsync(2, TimeSpan.FromSeconds(0.5), true)); + } } }