diff --git a/logs/exceptions.md b/logs/exceptions.md index ccd6e6f68b..2cb9eed6fc 100644 --- a/logs/exceptions.md +++ b/logs/exceptions.md @@ -6,10 +6,12 @@ ### Proto.Cluster.Tests (Timeout) `System.TimeoutException: Request timed out` in `InMemoryPartitionActivatorClusterTests.HandlesSlowResponsesCorrectly`. + +### Proto.Actor.Tests.EscalateFailureTests +`System.TimeoutException: The condition was not met within the timeout of 00:00:00.1000000` in `Proto.Mailbox.Tests.EscalateFailureTests.GivenNonCompletedSystemMessageTaskThrewException_ShouldEscalateFailure`. + ### Proto.Mailbox.Tests.EscalateFailureTests.GivenNonCompletedUserMessageTaskGotCancelled_ShouldEscalateFailure `System.TimeoutException: The condition was not met within the timeout of 00:00:00.1000000` when waiting for mailbox failure escalation. ### Proto.Tests.SupervisionTestsAllForOne.AllForOneStrategy_Should_PassExceptionOnRestart `System.InvalidOperationException: Collection was modified; enumeration operation may not execute.` during enumeration of mailbox statistics. -### Proto.Tests.SupervisionTestsAllForOne.AllForOneStrategy_Should_PassExceptionOnRestart -`System.InvalidOperationException: Collection was modified; enumeration operation may not execute.` during enumeration of mailbox statistics. diff --git a/logs/log1755977337.md b/logs/log1755977337.md new file mode 100644 index 0000000000..0ad8d76ad4 --- /dev/null +++ b/logs/log1755977337.md @@ -0,0 +1,9 @@ +# Task Log + +## Summary +- Added reusable `GossipNetworkPartition` middleware under `tests/Proto.TestKit`. +- Refactored `PartitionConsensusTests` to consume the shared middleware. +- Wired the helper into `Proto.Cluster.Tests` so future partition tests can reuse it. + +## Motivation +Centralizing the gossip partition helper avoids duplication and makes partition scenarios easier to express in tests, improving maintainability and clarity. diff --git a/logs/log1755978126.md b/logs/log1755978126.md new file mode 100644 index 0000000000..ee84262596 --- /dev/null +++ b/logs/log1755978126.md @@ -0,0 +1,8 @@ +## Summary +- move GossipNetworkPartition helper into Proto.TestKit project +- remove file link from Proto.Cluster.Tests project and reference Proto.Cluster from Proto.TestKit + +## Testing +- `dotnet test --no-build tests/Proto.Actor.Tests/Proto.Actor.Tests.csproj` +- `dotnet test tests/Proto.Remote.Tests/Proto.Remote.Tests.csproj` +- `dotnet test tests/Proto.Cluster.Tests/Proto.Cluster.Tests.csproj` diff --git a/src/Proto.TestKit/GossipNetworkPartition.cs b/src/Proto.TestKit/GossipNetworkPartition.cs new file mode 100644 index 0000000000..e0348b9826 --- /dev/null +++ b/src/Proto.TestKit/GossipNetworkPartition.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Immutable; +using Proto; +using Proto.Cluster.Gossip; + +namespace Proto.TestKit; + +// Middleware to simulate network partitions for gossip messages in tests +public static class GossipNetworkPartition +{ + private static ImmutableHashSet _isolated = ImmutableHashSet.Empty; + + // Prevent gossip between the given address and any other nodes + public static void Isolate(string address) => _isolated = _isolated.Add(address); + + // Clear all simulated partitions + public static void Clear() => _isolated = ImmutableHashSet.Empty; + + // Middleware that drops gossip requests to or from isolated nodes + public static Func Middleware => next => async (ctx, target, envelope) => + { + if (envelope.Message is GossipRequest && target.Id == Gossiper.GossipActorName) + { + var from = ctx.System.Address; + var to = target.Address; + + if (_isolated.Contains(from) || _isolated.Contains(to)) + { + // message dropped due to simulated partition + return; + } + } + + await next(ctx, target, envelope); + }; +} diff --git a/src/Proto.TestKit/Proto.TestKit.csproj b/src/Proto.TestKit/Proto.TestKit.csproj index 9b3519b9e3..58f9e2de7d 100644 --- a/src/Proto.TestKit/Proto.TestKit.csproj +++ b/src/Proto.TestKit/Proto.TestKit.csproj @@ -8,6 +8,7 @@ + diff --git a/tests/Proto.Cluster.Tests/PartitionConsensusTests.cs b/tests/Proto.Cluster.Tests/PartitionConsensusTests.cs index f3d814b300..1c0cae3d4f 100644 --- a/tests/Proto.Cluster.Tests/PartitionConsensusTests.cs +++ b/tests/Proto.Cluster.Tests/PartitionConsensusTests.cs @@ -1,11 +1,11 @@ using System; -using System.Collections.Generic; using System.Threading.Tasks; using ClusterTest.Messages; using FluentAssertions; using Proto; using Proto.Cluster; using Proto.Cluster.Gossip; +using Proto.TestKit; using Xunit; using static Proto.TestKit.TestKit; @@ -87,28 +87,4 @@ protected override ActorSystemConfig GetActorSystemConfig() .WithConfigureSystemProps((name, p) => baseConfig.ConfigureSystemProps(name, p).WithSenderMiddleware(GossipNetworkPartition.Middleware)); } } - - private static class GossipNetworkPartition - { - private static readonly HashSet Dropped = new(); - - public static void Isolate(string address) => Dropped.Add(address); - public static void Clear() => Dropped.Clear(); - - public static Func Middleware => next => async (ctx, target, envelope) => - { - if (envelope.Message is GossipRequest && target.Id == Gossiper.GossipActorName) - { - var from = ctx.System.Address; - var to = target.Address; - - if (Dropped.Contains(from) || Dropped.Contains(to)) - { - return; - } - } - - await next(ctx, target, envelope); - }; - } } diff --git a/tests/Proto.Cluster.Tests/Proto.Cluster.Tests.csproj b/tests/Proto.Cluster.Tests/Proto.Cluster.Tests.csproj index aab0b0c8f0..4aa6b692ba 100644 --- a/tests/Proto.Cluster.Tests/Proto.Cluster.Tests.csproj +++ b/tests/Proto.Cluster.Tests/Proto.Cluster.Tests.csproj @@ -13,6 +13,7 @@ +