mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-05-13 14:14:29 +08:00
test(arch): 优化架构上下文并发测试的超时配置
- 将工作线程数量从16调整为8 - 添加工作线程启动超时设置为5秒 - 添加首次解析超时设置为5秒 - 使用可配置超时替代硬编码的1秒等待时间 - 提高测试稳定性和可读性
This commit is contained in:
parent
2425d28097
commit
a068a5e707
@ -16,7 +16,6 @@ using GFramework.Core.Events;
|
|||||||
using GFramework.Core.Ioc;
|
using GFramework.Core.Ioc;
|
||||||
using GFramework.Core.Logging;
|
using GFramework.Core.Logging;
|
||||||
using GFramework.Core.Query;
|
using GFramework.Core.Query;
|
||||||
using GFramework.Cqrs.Abstractions.Cqrs;
|
|
||||||
|
|
||||||
namespace GFramework.Core.Tests.Architectures;
|
namespace GFramework.Core.Tests.Architectures;
|
||||||
|
|
||||||
@ -45,6 +44,15 @@ namespace GFramework.Core.Tests.Architectures;
|
|||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class ArchitectureContextTests
|
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]
|
[SetUp]
|
||||||
public void SetUp()
|
public void SetUp()
|
||||||
{
|
{
|
||||||
@ -76,15 +84,6 @@ public class ArchitectureContextTests
|
|||||||
_context = new ArchitectureContext(_container);
|
_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>
|
||||||
/// 测试构造函数在所有参数都有效时不应抛出异常
|
/// 测试构造函数在所有参数都有效时不应抛出异常
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -309,7 +308,9 @@ public class ArchitectureContextTests
|
|||||||
[Test]
|
[Test]
|
||||||
public async Task SendRequestAsync_Should_ResolveCqrsRuntime_OnlyOnce_When_AccessedConcurrently()
|
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 startGate = new ManualResetEventSlim(false);
|
||||||
using var allowResolutionToComplete = new ManualResetEventSlim(false);
|
using var allowResolutionToComplete = new ManualResetEventSlim(false);
|
||||||
using var workersReady = new CountdownEvent(workerCount);
|
using var workersReady = new CountdownEvent(workerCount);
|
||||||
@ -342,13 +343,13 @@ public class ArchitectureContextTests
|
|||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
Assert.That(
|
Assert.That(
|
||||||
workersReady.Wait(TimeSpan.FromSeconds(1)),
|
workersReady.Wait(workerStartupTimeout),
|
||||||
Is.True,
|
Is.True,
|
||||||
"Expected all workers to be ready before releasing start gate.");
|
"Expected all workers to be ready before releasing start gate.");
|
||||||
startGate.Set();
|
startGate.Set();
|
||||||
|
|
||||||
Assert.That(
|
Assert.That(
|
||||||
SpinWait.SpinUntil(() => Volatile.Read(ref resolutionCallCount) > 0, TimeSpan.FromSeconds(1)),
|
SpinWait.SpinUntil(() => Volatile.Read(ref resolutionCallCount) > 0, firstResolutionTimeout),
|
||||||
Is.True,
|
Is.True,
|
||||||
"Expected at least one CQRS runtime resolution attempt.");
|
"Expected at least one CQRS runtime resolution attempt.");
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user