Files
ThreadPilot/Tests/ThreadPilot.Core.Tests/PerformanceMonitoringServiceTests.cs
T
Kool 27e7b04913 Harden persistence, monitoring, and shutdown reliability (#46)
Addresses the audit findings across persistent-rule recovery, settings merge behavior, CPU identity, monitoring lifecycle, notifications, autostart, tray updates, and shutdown disposal. Includes regression coverage and the corrected disabled-monitoring view. CI DevSecOps and CodeQL pass.
2026-08-12 01:00:17 +02:00

46 lines
1.7 KiB
C#

namespace ThreadPilot.Core.Tests
{
using System.Reflection;
using Microsoft.Extensions.Logging.Abstractions;
using Moq;
using ThreadPilot.Services;
public sealed class PerformanceMonitoringServiceTests
{
[Fact]
public void BuildCpuCoreUsages_PreservesLogicalProcessorIdsAcrossMissingCounters()
{
var usages = PerformanceMonitoringService.BuildCpuCoreUsages(
[(0, 10d), (3, 30d)],
topology: null);
Assert.Equal([0, 3], usages.Select(usage => usage.CoreId));
Assert.Equal(["Core 0", "Core 3"], usages.Select(usage => usage.CoreName));
}
[Fact]
public async Task StopStart_DoesNotClearAnInFlightTickGuard()
{
using var service = CreateService();
var tickField = typeof(PerformanceMonitoringService).GetField(
"isMonitoringTickInProgress",
BindingFlags.Instance | BindingFlags.NonPublic)!;
await service.StartMonitoringAsync();
tickField.SetValue(service, 1);
await service.StopMonitoringAsync();
await service.StartMonitoringAsync();
Assert.Equal(1, tickField.GetValue(service));
}
private static PerformanceMonitoringService CreateService() =>
new(
NullLogger<PerformanceMonitoringService>.Instance,
new Mock<IProcessService>().Object,
new Mock<ICpuTopologyService>().Object,
new Mock<IApplicationSettingsService>().Object,
new Mock<IEnhancedLoggingService>().Object);
}
}