Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
94b69a7
removed cruft from `EventFitlerApplier`
Aaronontheweb Mar 19, 2025
4d63aa6
Akka.TestKit: ensure that `EventFilter` utilizes `WithinAsync` timeouts
Aaronontheweb Mar 19, 2025
157ddb1
Merge branch 'dev' into testkit-WithinAsync-bugfix
Aaronontheweb Mar 19, 2025
fb01d82
Merge branch 'dev' into testkit-WithinAsync-bugfix
Aaronontheweb Mar 19, 2025
9559606
fixed epsilon calculation
Aaronontheweb Mar 20, 2025
e259988
harden specs and fixed some TBDs inside `ActorRefProvider`
Aaronontheweb Mar 20, 2025
5f9dec7
Merge branch 'dev' into testkit-WithinAsync-bugfix
Aaronontheweb Mar 20, 2025
3989066
fixed 1 more TBD
Aaronontheweb Mar 20, 2025
9eaf51f
reverted CTS changes
Aaronontheweb Mar 20, 2025
b1d1bb6
Clarified leeway comment
Aaronontheweb Mar 20, 2025
04ac015
Merge branch 'dev' into testkit-WithinAsync-bugfix
Aaronontheweb Mar 20, 2025
d5fcfe1
increased the epsilon value on account of Azure DevOps
Aaronontheweb Mar 20, 2025
4ef6e96
Merge branch 'dev' into testkit-WithinAsync-bugfix
Aaronontheweb Mar 20, 2025
fa8f30b
Merge branch 'dev' into testkit-WithinAsync-bugfix
Aaronontheweb Mar 20, 2025
a01b0c8
Merge branch 'dev' into testkit-WithinAsync-bugfix
Arkatufus Mar 21, 2025
de75955
Merge branch 'dev' into testkit-WithinAsync-bugfix
Aaronontheweb Mar 23, 2025
e56b01a
Merge branch 'dev' into testkit-WithinAsync-bugfix
Aaronontheweb Mar 23, 2025
658d25a
Merge branch 'dev' into testkit-WithinAsync-bugfix
Aaronontheweb Mar 24, 2025
d5db94b
Merge branch 'dev' into testkit-WithinAsync-bugfix
Aaronontheweb Apr 18, 2025
0e5e174
Merge branch 'dev' into testkit-WithinAsync-bugfix
Aaronontheweb Apr 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/core/Akka.Cluster.Tests/Serialization/BugFix3724Spec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//-----------------------------------------------------------------------

using System;
using System.Threading.Tasks;
using Akka.Actor;
using Akka.TestKit;
using Akka.Util.Internal;
Expand All @@ -23,8 +24,10 @@ namespace Akka.Cluster.Tests.Serialization
public class BugFix3724Spec : AkkaSpec
{
public BugFix3724Spec(ITestOutputHelper helper)
: base(@"akka.actor.provider = cluster
akka.actor.serialize-messages = on", helper)
: base("""
akka.actor.provider = cluster
akka.actor.serialize-messages = on
""", helper)
{
_cluster = Cluster.Get(Sys);
_selfAddress = Sys.AsInstanceOf<ExtendedActorSystem>().Provider.DefaultAddress;
Expand All @@ -34,17 +37,18 @@ public BugFix3724Spec(ITestOutputHelper helper)
private readonly Cluster _cluster;

[Fact(DisplayName = "Should be able to use 'akka.actor.serialize-messages' while running Akka.Cluster")]
public void Should_serialize_all_AkkaCluster_messages()
public async Task Should_serialize_all_AkkaCluster_messages()
{
_cluster.Subscribe(TestActor, ClusterEvent.SubscriptionInitialStateMode.InitialStateAsEvents,
typeof(ClusterEvent.MemberUp));
Within(TimeSpan.FromSeconds(10), () =>
await WithinAsync(TimeSpan.FromSeconds(10), async () =>
{
EventFilter.Exception<Exception>().Expect(0, () =>
// Expect 0 means we have to wait for the full duration
await EventFilter.Exception<Exception>().ExpectAsync(0, async () =>
{
// wait for a singleton cluster to fully form and publish a member up event
_cluster.Join(_selfAddress);
var up = ExpectMsg<ClusterEvent.MemberUp>();
await _cluster.JoinAsync(_selfAddress);
var up = await ExpectMsgAsync<ClusterEvent.MemberUp>();
up.Member.Address.Should().Be(_selfAddress);
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/core/Akka.Cluster/Cluster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ bool GetAssertInvariants()
}

/// <summary>
/// TBD
/// Debug setting for internal purposes.
/// </summary>
internal static bool IsAssertInvariantsEnabled
{
Expand Down
15 changes: 8 additions & 7 deletions src/core/Akka.Streams.Tests/Dsl/HubSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,14 @@ await this.AssertAllStagesStoppedAsync(async () =>

await WithinAsync(10.Seconds(), async () =>
{
await EventFilter.Error(contains: "Upstream producer failed with exception").ExpectOneAsync(async () =>
{
Source.Failed<int>(new TestException("failing")).RunWith(sink, Materializer);
Source.From(Enumerable.Range(1, 10)).RunWith(sink, Materializer);
var result = await task.ShouldCompleteWithin(3.Seconds());
result.Should().BeEquivalentTo(Enumerable.Range(1, 10));
});
await EventFilter.Error(contains: "Upstream producer failed with exception")
.ExpectOneAsync(async () =>
{
Source.Failed<int>(new TestException("failing")).RunWith(sink, Materializer);
Source.From(Enumerable.Range(1, 10)).RunWith(sink, Materializer);
var result = await task.ShouldCompleteWithin(3.Seconds());
result.Should().BeEquivalentTo(Enumerable.Range(1, 10));
});
});
}, Materializer);
}
Expand Down
64 changes: 63 additions & 1 deletion src/core/Akka.TestKit.Tests/TestKitBaseTests/WithinTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class WithinTests : AkkaSpec
[Fact]
public void Within_should_increase_max_timeout_by_the_provided_epsilon_value()
{
Within(TimeSpan.FromSeconds(1), () => ExpectNoMsg(), TimeSpan.FromMilliseconds(50));
Within(TimeSpan.FromSeconds(1), () => ExpectNoMsg(), TimeSpan.FromMilliseconds(500));
}

[Fact]
Expand Down Expand Up @@ -63,5 +63,67 @@ await WithinAsync(
0.1.Seconds());
}).Should().ThrowAsync<XunitException>();
}

[Fact]
public async Task WithinAsync_timeout_should_propagate_to_EventFilter()
{
// This test passes if:
// 1. The test fails quickly due to the short WithinAsync timeout (expected)
// 2. The timeoutOccurred flag remains false - meaning our short timeout was respected
//
// This test will fail if:
// 1. The EventFilter ignores the WithinAsync timeout and uses its own longer default timeout
// 2. The timeoutOccurred flag will be set to true in that case

var testEvent = "test-event-" + Guid.NewGuid().ToString("N");
var filter = EventFilter.Info(contains: testEvent);

// Use a very short timeout for WithinAsync - something that would definitely
// fail if the EventFilter is using its own longer default timeout
var shortTimeout = 200.Milliseconds();

// Create a custom timeout tracker for precise measurement
var timeoutOccurred = false;
var timerCts = new System.Threading.CancellationTokenSource();
var timerTask = Task.Run(async () => {
try
{
// Wait slightly longer than the short timeout
await Task.Delay(shortTimeout.Add(300.Milliseconds()), timerCts.Token);
// If we get here, the test is taking too long
timeoutOccurred = true;
}
catch (System.Threading.Tasks.TaskCanceledException)
{
// This is expected if the test completes in time
}
});

try
{
// This should fail quickly with the short timeout
// The timeout error is wrapped in an AggregateException when using our fix
await Assert.ThrowsAsync<AggregateException>(async () =>
{
await WithinAsync(shortTimeout, async () =>
{
// This won't receive any messages and should inherit the short timeout
await filter.ExpectOneAsync(() => Task.CompletedTask);
});
});

// Cancel the timeout tracker since we've already completed
timerCts.Cancel();
await Task.WhenAny(timerTask);

// Verify the test completed before our manual timeout
Assert.False(timeoutOccurred,
"The test took longer than expected. EventFilter likely did not inherit WithinAsync timeout.");
}
finally
{
timerCts.Cancel();
}
}
}
}
Loading
Loading