Browse Source

Moved to task scheduler.

pull/195/head
Sebastian Stehle 8 years ago
parent
commit
f486fe696d
  1. 2
      src/Squidex.Infrastructure/CQRS/Events/Actors/EventConsumerActor.cs
  2. 2
      src/Squidex.Infrastructure/States/StateFactory.cs
  3. 126
      tests/Squidex.Infrastructure.Tests/InMemoryPubSubTests.cs

2
src/Squidex.Infrastructure/CQRS/Events/Actors/EventConsumerActor.cs

@ -19,7 +19,7 @@ namespace Squidex.Infrastructure.CQRS.Events.Actors
private readonly EventDataFormatter formatter; private readonly EventDataFormatter formatter;
private readonly IEventStore eventStore; private readonly IEventStore eventStore;
private readonly ISemanticLog log; private readonly ISemanticLog log;
private readonly TaskFactory taskFactory = new TaskFactory(new LimitedConcurrencyLevelTaskScheduler(1)); private readonly SingleThreadedDispatcher dispatcher = new SingleThreadedDispatcher(1);
private IEventSubscription currentSubscription; private IEventSubscription currentSubscription;
private IEventConsumer eventConsumer; private IEventConsumer eventConsumer;

2
src/Squidex.Infrastructure/States/StateFactory.cs

@ -76,7 +76,7 @@ namespace Squidex.Infrastructure.States
.SetAbsoluteExpiration(CacheDuration) .SetAbsoluteExpiration(CacheDuration)
.RegisterPostEvictionCallback((k, v, r, s) => .RegisterPostEvictionCallback((k, v, r, s) =>
{ {
taskFactory.StartNew(async () => taskFactory.StartNew(() =>
{ {
state.Dispose(); state.Dispose();
states.Remove(state); states.Remove(state);

126
tests/Squidex.Infrastructure.Tests/InMemoryPubSubTests.cs

@ -27,68 +27,68 @@ namespace Squidex.Infrastructure
public string Text { get; set; } public string Text { get; set; }
} }
//[Fact] [Fact]
//public void Should_publish_to_handlers() public void Should_publish_to_handlers()
//{ {
// var channel1Events = new List<string>(); var channel1Events = new List<string>();
// var channel2Events = new List<string>(); var channel2Events = new List<string>();
// sut.Subscribe<MessageA>(m => sut.Subscribe<MessageA>(m =>
// { {
// channel1Events.Add(m.Text); channel1Events.Add(m.Text);
// }); });
// sut.Subscribe<MessageA>(m => sut.Subscribe<MessageA>(m =>
// { {
// channel1Events.Add(m.Text); channel1Events.Add(m.Text);
// }); });
// sut.Subscribe<MessageB>(m => sut.Subscribe<MessageB>(m =>
// { {
// channel2Events.Add(m.Text); channel2Events.Add(m.Text);
// }); });
// sut.Publish(new MessageA { Text = "1" }, true); sut.Publish(new MessageA { Text = "1" }, true);
// sut.Publish(new MessageA { Text = "2" }, true); sut.Publish(new MessageA { Text = "2" }, true);
// sut.Publish(new MessageA { Text = "3" }, false); sut.Publish(new MessageA { Text = "3" }, false);
// sut.Publish(new MessageB { Text = "a" }, true); sut.Publish(new MessageB { Text = "a" }, true);
// sut.Publish(new MessageB { Text = "b" }, true); sut.Publish(new MessageB { Text = "b" }, true);
// Assert.Equal(new[] { "1", "1", "2", "2" }, channel1Events.ToArray()); Assert.Equal(new[] { "1", "1", "2", "2" }, channel1Events.ToArray());
// Assert.Equal(new[] { "a", "b" }, channel2Events.ToArray()); Assert.Equal(new[] { "a", "b" }, channel2Events.ToArray());
//} }
//[Fact] [Fact]
//public async Task Should_make_request_reply_requests() public async Task Should_make_request_reply_requests()
//{ {
// sut.ReceiveAsync<int, int>(x => sut.ReceiveAsync<int, int>(x =>
// { {
// return Task.FromResult(x + x); return Task.FromResult(x + x);
// }, true); }, true);
// var response = await sut.RequestAsync<int, int>(2, TimeSpan.FromSeconds(2), true); var response = await sut.RequestAsync<int, int>(2, TimeSpan.FromSeconds(2), true);
// Assert.Equal(4, response); Assert.Equal(4, response);
//} }
//[Fact] [Fact]
//public async Task Should_timeout_when_response_is_too_slow() public async Task Should_timeout_when_response_is_too_slow()
//{ {
// sut.ReceiveAsync<int, int>(async x => sut.ReceiveAsync<int, int>(async x =>
// { {
// await Task.Delay(1000); await Task.Delay(1000);
// return x + x; return x + x;
// }, true); }, true);
// await Assert.ThrowsAsync<TaskCanceledException>(() => sut.RequestAsync<int, int>(1, TimeSpan.FromSeconds(0.5), true)); await Assert.ThrowsAsync<TaskCanceledException>(() => sut.RequestAsync<int, int>(1, TimeSpan.FromSeconds(0.5), true));
//} }
//[Fact] [Fact]
//public async Task Should_timeout_when_nobody_responds() public async Task Should_timeout_when_nobody_responds()
//{ {
// await Assert.ThrowsAsync<TaskCanceledException>(() => sut.RequestAsync<int, int>(2, TimeSpan.FromSeconds(0.5), true)); await Assert.ThrowsAsync<TaskCanceledException>(() => sut.RequestAsync<int, int>(2, TimeSpan.FromSeconds(0.5), true));
//} }
} }
} }

Loading…
Cancel
Save