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.
54 lines
1.3 KiB
54 lines
1.3 KiB
// ==========================================================================
|
|
// CompletionTimerTests.cs
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex Group
|
|
// All rights reserved.
|
|
// ==========================================================================
|
|
|
|
using System.Threading;
|
|
using Squidex.Infrastructure.Tasks;
|
|
using Xunit;
|
|
|
|
// ReSharper disable AccessToModifiedClosure
|
|
|
|
namespace Squidex.Infrastructure.Timers
|
|
{
|
|
public class CompletionTimerTests
|
|
{
|
|
[Fact]
|
|
public void Should_invoke_once_even_with_delay()
|
|
{
|
|
var called = false;
|
|
|
|
var timer = new CompletionTimer(2000, ct =>
|
|
{
|
|
called = true;
|
|
|
|
return TaskHelper.Done;
|
|
}, 2000);
|
|
|
|
timer.Wakeup();
|
|
timer.Dispose();
|
|
|
|
Assert.True(called);
|
|
}
|
|
|
|
public void Should_invoke_dispose_within_timer()
|
|
{
|
|
CompletionTimer timer = null;
|
|
|
|
timer = new CompletionTimer(10, ct =>
|
|
{
|
|
timer?.Dispose();
|
|
|
|
return TaskHelper.Done;
|
|
}, 10);
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
timer.Wakeup();
|
|
timer.Dispose();
|
|
}
|
|
}
|
|
}
|
|
|