Skip to content

Commit 1cc9f8e

Browse files
authored
Track activation requests in partition identity tests (#2267)
1 parent 39aadff commit 1cc9f8e

File tree

2 files changed

+36
-10
lines changed

2 files changed

+36
-10
lines changed

tests/Proto.Cluster.PartitionIdentity.Tests/PartitionIdentityTests.cs

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using System.Threading.Tasks;
1313
using ClusterTest.Messages;
1414
using FluentAssertions;
15+
using Proto.Cluster;
1516
using Proto.Cluster.Identity;
1617
using Proto.Cluster.Partition;
1718
using Proto.Cluster.Tests;
@@ -91,12 +92,20 @@ PartitionIdentityLookup.Send send
9192
var actorStates = fixture.Repository.Contents.ToList();
9293

9394
var totalCalls = actorStates.Select(it => it.TotalCount).Sum();
94-
var restarts = actorStates.Select(it => it.Events.Count(it => it is ActorStopped) - 1).Sum();
95+
var restarts = actorStates.Select(it => it.Events.Count(e => e is ActorStopped) - 1).Sum();
96+
var totalActivationRequests =
97+
actorStates.Select(it => it.Events.Count(e => e is ActivationRequested)).Sum();
9598

96-
_output.WriteLine($"{totalCalls} requests, {restarts} restarts against " + actorStates.Count + " identities");
99+
_output.WriteLine(
100+
$"{totalCalls} requests, {restarts} restarts, {totalActivationRequests} activation requests against " +
101+
actorStates.Count + " identities");
97102

98103
foreach (var actorState in actorStates)
99104
{
105+
var activationReqs = actorState.Events.Count(e => e is ActivationRequested);
106+
var starts = actorState.Events.Count(e => e is ActorStarted);
107+
activationReqs.Should().Be(starts);
108+
100109
if (actorState.Inconsistent)
101110
{
102111
Assert.False(actorState.Inconsistent, actorState.ToString());
@@ -298,12 +307,22 @@ protected override ClusterKind[] ClusterKinds
298307
};
299308

300309
protected override IIdentityLookup GetIdentityLookup(string clusterName) =>
301-
new PartitionIdentityLookup(new PartitionConfig
302-
{
303-
GetPidTimeout = TimeSpan.FromSeconds(5),
304-
HandoverChunkSize = _chunkSize,
305-
RebalanceRequestTimeout = TimeSpan.FromSeconds(3),
306-
Mode = _mode,
307-
Send = _send
308-
});
310+
new PartitionIdentityLookup(
311+
new PartitionConfig
312+
{
313+
GetPidTimeout = TimeSpan.FromSeconds(5),
314+
HandoverChunkSize = _chunkSize,
315+
RebalanceRequestTimeout = TimeSpan.FromSeconds(3),
316+
Mode = _mode,
317+
Send = _send
318+
},
319+
props => props.WithReceiverMiddleware(next => async (ctx, env) =>
320+
{
321+
if (env.Message is ActivationRequest req)
322+
{
323+
Repository.Get(req.Identity, this).RecordActivationRequest(ctx.System.Id);
324+
}
325+
326+
await next(ctx, env);
327+
}));
309328
}

tests/Proto.Cluster.Tests/ConcurrencyVerificationActor.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ public record ActorStarted(string Member, PID Activation, DateTimeOffset When, i
105105
public record ActorStopped(string Member, PID Activation, DateTimeOffset When, int StoredCount, long GlobalCount)
106106
: VerificationEvent(Activation, When);
107107

108+
public record ActivationRequested(string Member, DateTimeOffset When)
109+
: VerificationEvent(null!, When);
110+
108111
public record ConsistencyError(
109112
PID Activation,
110113
DateTimeOffset When,
@@ -139,6 +142,9 @@ public ActorState(string id, IClusterFixture clusterFixture)
139142
public long TotalCount => Interlocked.Read(ref _totalCount);
140143
public ConcurrentBag<VerificationEvent> Events { get; } = new();
141144

145+
public void RecordActivationRequest(string member) =>
146+
Events.Add(new ActivationRequested(member, DateTimeOffset.Now));
147+
142148
public void RecordStarted(IContext context)
143149
{
144150
lock (_padlock)
@@ -200,6 +206,7 @@ private string EventsToString() =>
200206
{
201207
ActorStarted started => $"[{started.When:O}] Actor started on member {started.Member}\n",
202208
ActorStopped stopped => $"[{stopped.When:O}] Actor stopped on member {stopped.Member}\n",
209+
ActivationRequested req => $"[{req.When:O}] Activation requested on member {req.Member}\n",
203210
ClusterSnapshot snapshot => $"[{snapshot.When:O}] Cluster snapshot:\n{snapshot.Snapshot}\n",
204211
ConsistencyError err =>
205212
$"[{err.When:O}] Consistency error, actual: {err.ActualCount}, expected: {err.ExpectedCount}, stored: {err.StoredCount}, global: {err.GlobalCount}",

0 commit comments

Comments
 (0)