增加对BackgroundLongTask异步执行的测试

This commit is contained in:
falcon 2022-03-31 11:36:33 +08:00
parent 96002f73f3
commit 3333e7f12c

View File

@ -4,6 +4,7 @@ using System.Threading;
using System;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Hosting;
using System.Threading.Tasks;
namespace Falcon.SugarApi.Test
{
@ -23,6 +24,28 @@ namespace Falcon.SugarApi.Test
Thread.Sleep(2 * 1000);
Assert.IsTrue(task.State == 2, "停止状态错误");
Console.WriteLine($"{DateTime.Now.ToString("HH:mm:ss")}:测试完成");
var asyncTask = new BackTaskAsync();
Console.WriteLine("启动异步任务");
asyncTask.StartAsync(token.Token).Wait();
Thread.Sleep(5 * 1000);
Console.WriteLine("停止异步任务");
asyncTask.StopAsync(token.Token).Wait();
}
}
public class BackTaskAsync : BackgroundLongTask
{
public BackTaskAsync() {
this.Log = new TestLog<BackTaskObject>();
}
public ILogger Log { get; set; }
public override float RunTimespan => 1;
protected async override void Run() {
this.Log.LogInformation($"{DateTime.Now.ToString("HH:mm:ss")}:BackTaskAsync Run!");
await Task.CompletedTask;
}
}