test(arch): 优化架构上下文并发测试的超时配置

- 将工作线程数量从16调整为8
- 添加工作线程启动超时设置为5秒
- 添加首次解析超时设置为5秒
- 使用可配置超时替代硬编码的1秒等待时间
- 提高测试稳定性和可读性
This commit is contained in:
GeWuYou 2026-04-15 18:52:53 +08:00
parent 2425d28097
commit a068a5e707

View File

@ -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;
/// <summary>
/// 测试构造函数在所有参数都有效时不应抛出异常
/// </summary>
@ -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.");