mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.6 KiB
56 lines
1.6 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Xunit;
|
|
|
|
namespace Squidex.Infrastructure.Tasks
|
|
{
|
|
public class SingleThreadedDispatcherTests
|
|
{
|
|
private readonly SingleThreadedDispatcher sut = new SingleThreadedDispatcher();
|
|
|
|
[Fact]
|
|
public async Task Should_handle_with_task_messages_sequentially()
|
|
{
|
|
var source = Enumerable.Range(1, 100);
|
|
var target = new List<int>();
|
|
|
|
foreach (var item in source)
|
|
{
|
|
sut.DispatchAsync(() =>
|
|
{
|
|
target.Add(item);
|
|
|
|
return TaskHelper.Done;
|
|
}).Forget();
|
|
}
|
|
|
|
await sut.StopAndWaitAsync();
|
|
|
|
Assert.Equal(source, target);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Should_handle_messages_sequentially()
|
|
{
|
|
var source = Enumerable.Range(1, 100);
|
|
var target = new List<int>();
|
|
|
|
foreach (var item in source)
|
|
{
|
|
sut.DispatchAsync(() => target.Add(item)).Forget();
|
|
}
|
|
|
|
await sut.StopAndWaitAsync();
|
|
|
|
Assert.Equal(source, target);
|
|
}
|
|
}
|
|
}
|
|
|