From a068a5e707291c118a0b8bd1eb046d0bee4ed030 Mon Sep 17 00:00:00 2001 From: GeWuYou <95328647+GeWuYou@users.noreply.github.com> Date: Wed, 15 Apr 2026 18:52:53 +0800 Subject: [PATCH] =?UTF-8?q?test(arch):=20=E4=BC=98=E5=8C=96=E6=9E=B6?= =?UTF-8?q?=E6=9E=84=E4=B8=8A=E4=B8=8B=E6=96=87=E5=B9=B6=E5=8F=91=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E7=9A=84=E8=B6=85=E6=97=B6=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将工作线程数量从16调整为8 - 添加工作线程启动超时设置为5秒 - 添加首次解析超时设置为5秒 - 使用可配置超时替代硬编码的1秒等待时间 - 提高测试稳定性和可读性 --- .../Architectures/ArchitectureContextTests.cs | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/GFramework.Core.Tests/Architectures/ArchitectureContextTests.cs b/GFramework.Core.Tests/Architectures/ArchitectureContextTests.cs index dd524414..09c3f4d1 100644 --- a/GFramework.Core.Tests/Architectures/ArchitectureContextTests.cs +++ b/GFramework.Core.Tests/Architectures/ArchitectureContextTests.cs @@ -16,7 +16,6 @@ using GFramework.Core.Events; using GFramework.Core.Ioc; using GFramework.Core.Logging; using GFramework.Core.Query; -using GFramework.Cqrs.Abstractions.Cqrs; namespace GFramework.Core.Tests.Architectures; @@ -45,6 +44,15 @@ namespace GFramework.Core.Tests.Architectures; [TestFixture] public class ArchitectureContextTests { + private AsyncQueryExecutor? _asyncQueryBus; + private CommandExecutor? _commandBus; + private MicrosoftDiContainer? _container; + + private ArchitectureContext? _context; + private DefaultEnvironment? _environment; + private EventBus? _eventBus; + private QueryExecutor? _queryBus; + [SetUp] public void SetUp() { @@ -76,15 +84,6 @@ public class ArchitectureContextTests _context = new ArchitectureContext(_container); } - private AsyncQueryExecutor? _asyncQueryBus; - private CommandExecutor? _commandBus; - private MicrosoftDiContainer? _container; - - private ArchitectureContext? _context; - private DefaultEnvironment? _environment; - private EventBus? _eventBus; - private QueryExecutor? _queryBus; - /// /// 测试构造函数在所有参数都有效时不应抛出异常 /// @@ -309,7 +308,9 @@ public class ArchitectureContextTests [Test] public async Task SendRequestAsync_Should_ResolveCqrsRuntime_OnlyOnce_When_AccessedConcurrently() { - const int workerCount = 16; + const int workerCount = 8; + var workerStartupTimeout = TimeSpan.FromSeconds(5); + var firstResolutionTimeout = TimeSpan.FromSeconds(5); using var startGate = new ManualResetEventSlim(false); using var allowResolutionToComplete = new ManualResetEventSlim(false); using var workersReady = new CountdownEvent(workerCount); @@ -342,13 +343,13 @@ public class ArchitectureContextTests .ToArray(); Assert.That( - workersReady.Wait(TimeSpan.FromSeconds(1)), + workersReady.Wait(workerStartupTimeout), Is.True, "Expected all workers to be ready before releasing start gate."); startGate.Set(); Assert.That( - SpinWait.SpinUntil(() => Volatile.Read(ref resolutionCallCount) > 0, TimeSpan.FromSeconds(1)), + SpinWait.SpinUntil(() => Volatile.Read(ref resolutionCallCount) > 0, firstResolutionTimeout), Is.True, "Expected at least one CQRS runtime resolution attempt.");