Enhance user management and node health check features
- Updated `ListUsersQueryHandler` to include plan names and config quotas in `UserSummaryDto`, enriching user data retrieval. - Implemented `WithPlanNamesAsync` method to fetch plan names based on user plan IDs, improving user experience in the admin interface. - Enhanced `Node` class with a `ConsecutiveProbeFailures` property for better status management during health checks. - Modified `NodeHealthCheckService` to utilize the new `RecordProbe` method, implementing a hysteresis mechanism for node status changes. - Updated frontend components to display user config quotas and plan names, improving clarity in user management. - Enhanced tests for user listing and node status handling to ensure robust functionality and coverage. - Updated documentation to reflect changes in user and node management features.
This commit is contained in:
@@ -120,6 +120,79 @@ public class NodeTests
|
||||
Assert.Equal(NodeStatus.Online, node.Status);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RecordProbe_SingleFailure_DoesNotGoOffline_WhenThresholdNotReached()
|
||||
{
|
||||
var node = Node.Register("Node", new Uri("https://example.com"), Credentials, null);
|
||||
node.UpdateStatus(NodeStatus.Online);
|
||||
|
||||
var changed = node.RecordProbe(reachable: false, failureThreshold: 2);
|
||||
|
||||
Assert.False(changed);
|
||||
Assert.Equal(NodeStatus.Online, node.Status);
|
||||
Assert.Equal(1, node.ConsecutiveProbeFailures);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RecordProbe_GoesOffline_OnlyAfterConsecutiveFailuresReachThreshold()
|
||||
{
|
||||
var node = Node.Register("Node", new Uri("https://example.com"), Credentials, null);
|
||||
node.UpdateStatus(NodeStatus.Online);
|
||||
|
||||
Assert.False(node.RecordProbe(reachable: false, failureThreshold: 2));
|
||||
Assert.Equal(NodeStatus.Online, node.Status);
|
||||
|
||||
var changed = node.RecordProbe(reachable: false, failureThreshold: 2);
|
||||
|
||||
Assert.True(changed);
|
||||
Assert.Equal(NodeStatus.Offline, node.Status);
|
||||
Assert.Equal(2, node.ConsecutiveProbeFailures);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RecordProbe_FlappingFailSuccess_NeverGoesOffline()
|
||||
{
|
||||
var node = Node.Register("Node", new Uri("https://example.com"), Credentials, null);
|
||||
node.UpdateStatus(NodeStatus.Online);
|
||||
|
||||
// Чередование fail/success (ровно паттерн со скриншота) не должно ронять статус:
|
||||
// порогу нужны ДВЕ подряд неудачи, а удачная проба обнуляет счётчик.
|
||||
for (var i = 0; i < 5; i++)
|
||||
{
|
||||
Assert.False(node.RecordProbe(reachable: false, failureThreshold: 2));
|
||||
Assert.False(node.RecordProbe(reachable: true, failureThreshold: 2));
|
||||
Assert.Equal(NodeStatus.Online, node.Status);
|
||||
Assert.Equal(0, node.ConsecutiveProbeFailures);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RecordProbe_SuccessAfterOffline_ReturnsOnlineImmediately_AndResetsCounter()
|
||||
{
|
||||
var node = Node.Register("Node", new Uri("https://example.com"), Credentials, null);
|
||||
node.RecordProbe(reachable: false, failureThreshold: 2);
|
||||
node.RecordProbe(reachable: false, failureThreshold: 2);
|
||||
Assert.Equal(NodeStatus.Offline, node.Status);
|
||||
|
||||
var changed = node.RecordProbe(reachable: true, failureThreshold: 2);
|
||||
|
||||
Assert.True(changed);
|
||||
Assert.Equal(NodeStatus.Online, node.Status);
|
||||
Assert.Equal(0, node.ConsecutiveProbeFailures);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RecordProbe_SuccessWhenAlreadyOnline_ReportsNoChange()
|
||||
{
|
||||
var node = Node.Register("Node", new Uri("https://example.com"), Credentials, null);
|
||||
node.UpdateStatus(NodeStatus.Online);
|
||||
|
||||
var changed = node.RecordProbe(reachable: true, failureThreshold: 2);
|
||||
|
||||
Assert.False(changed);
|
||||
Assert.Equal(NodeStatus.Online, node.Status);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MarkSynced_SetsLastSyncAt()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user