From a2d9326826a23aea33e3b10d89b34de5e90cfb2a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=A9=99=E5=AD=90?= <454313500@qq.com>
Date: Wed, 29 May 2024 23:42:56 +0800
Subject: [PATCH] =?UTF-8?q?test=EF=BC=9A=E6=B7=BB=E5=8A=A0=E7=BA=BF?=
=?UTF-8?q?=E7=A8=8Bdb=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../test/Yi.Abp.Test/Demo/ThreadDb_Test.cs | 110 ++++++++++++++++++
.../test/Yi.Abp.Test/Yi.Abp.Test.csproj | 6 +
Yi.Abp.Net8/test/Yi.Abp.Test/YiAbpTestBase.cs | 2 +-
3 files changed, 117 insertions(+), 1 deletion(-)
create mode 100644 Yi.Abp.Net8/test/Yi.Abp.Test/Demo/ThreadDb_Test.cs
diff --git a/Yi.Abp.Net8/test/Yi.Abp.Test/Demo/ThreadDb_Test.cs b/Yi.Abp.Net8/test/Yi.Abp.Test/Demo/ThreadDb_Test.cs
new file mode 100644
index 00000000..7a519d88
--- /dev/null
+++ b/Yi.Abp.Net8/test/Yi.Abp.Test/Demo/ThreadDb_Test.cs
@@ -0,0 +1,110 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Volo.Abp.Uow;
+using Xunit;
+using Yi.Framework.Rbac.Application.Contracts.IServices;
+using Yi.Framework.Rbac.Domain.Entities;
+using Yi.Framework.Rbac.Domain.Shared.Consts;
+using Yi.Framework.SqlSugarCore.Abstractions;
+
+namespace Yi.Abp.Test.Demo
+{
+ public class ThreadDb_Test : YiAbpTestBase
+ {
+ ///
+ /// 并发
+ ///
+ ///
+ [Fact]
+ public async Task Repository_Test()
+ {
+ try
+ {
+ var rep = GetRequiredService>();
+ List tasks = new List();
+ for (int i = 0; i < 10; i++)
+ {
+ tasks.Add(Task.Run(async () =>
+ {
+ await rep.GetListAsync();
+ }));
+ }
+ await Task.WhenAll(tasks);
+ await Console.Out.WriteLineAsync("成功");
+ }
+ catch
+ (Exception ex)
+ {
+ Console.WriteLine(ex.ToString());
+ }
+ }
+
+ ///
+ /// 工作单元
+ ///
+ ///
+ [Fact]
+ public async Task Uow_In_Test()
+ {
+ try
+ {
+ var rep = GetRequiredService>();
+ List tasks = new List();
+ for (int i = 0; i < 10; i++)
+ {
+ tasks.Add(Task.Run(async () =>
+ {
+ using (var uow = GetRequiredService().Begin(true, true))
+ {
+ await rep.GetListAsync();
+ await uow.CompleteAsync();
+ }
+ }));
+ }
+ await Task.WhenAll(tasks);
+ await Console.Out.WriteLineAsync("成功");
+ }
+ catch
+ (Exception ex)
+ {
+ Console.WriteLine(ex.ToString());
+ }
+ }
+
+
+ ///
+ /// 工作单元
+ ///
+ ///
+ [Fact]
+ public async Task Uow_Out_Test()
+ {
+ try
+ {
+ var rep = GetRequiredService>();
+ List tasks = new List();
+ using (var uow = GetRequiredService().Begin(true, true))
+ {
+ for (int i = 0; i < 10; i++)
+ {
+ tasks.Add(Task.Run(async () =>
+ {
+ await rep.GetListAsync();
+ await uow.CompleteAsync();
+ }));
+ }
+ }
+ await Task.WhenAll(tasks);
+ await Console.Out.WriteLineAsync("成功");
+ }
+ catch
+ (Exception ex)
+ {
+ Console.WriteLine(ex.ToString());
+ }
+ }
+ }
+}
diff --git a/Yi.Abp.Net8/test/Yi.Abp.Test/Yi.Abp.Test.csproj b/Yi.Abp.Net8/test/Yi.Abp.Test/Yi.Abp.Test.csproj
index dccbd824..b871335d 100644
--- a/Yi.Abp.Net8/test/Yi.Abp.Test/Yi.Abp.Test.csproj
+++ b/Yi.Abp.Net8/test/Yi.Abp.Test/Yi.Abp.Test.csproj
@@ -6,9 +6,15 @@
enable
+
+
+ PreserveNewest
+ true
+ PreserveNewest
+
Always
true
diff --git a/Yi.Abp.Net8/test/Yi.Abp.Test/YiAbpTestBase.cs b/Yi.Abp.Net8/test/Yi.Abp.Test/YiAbpTestBase.cs
index c9b69fa7..0ea415ba 100644
--- a/Yi.Abp.Net8/test/Yi.Abp.Test/YiAbpTestBase.cs
+++ b/Yi.Abp.Net8/test/Yi.Abp.Test/YiAbpTestBase.cs
@@ -40,7 +40,7 @@ namespace Yi.Abp.Test
protected virtual void ConfigureAppConfiguration(IConfigurationBuilder configurationBuilder)
{
configurationBuilder.AddJsonFile("appsettings.json");
- //configurationBuilder.AddJsonFile("appsettings.Development.json");
+ configurationBuilder.AddJsonFile("appsettings.Development.json");
}
}