Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Akka.TestKit: configurable expect-no-message-default value #6675 #7006

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/core/Akka.TestKit.Tests/TestKit_Config_Tests.cs
Expand Up @@ -19,6 +19,7 @@ public void DefaultValues_should_be_correct()
{
TestKitSettings.DefaultTimeout.ShouldBe(TimeSpan.FromSeconds(5));
TestKitSettings.SingleExpectDefault.ShouldBe(TimeSpan.FromSeconds(3));
TestKitSettings.ExpectNoMessageDefault.ShouldBe(TimeSpan.FromSeconds(3));
TestKitSettings.TestEventFilterLeeway.ShouldBe(TimeSpan.FromSeconds(3));
TestKitSettings.TestTimeFactor.ShouldBe(1);
var callingThreadDispatcherTypeName = typeof(CallingThreadDispatcherConfigurator).FullName + ", " + typeof(CallingThreadDispatcher).Assembly.GetName().Name;
Expand Down
4 changes: 4 additions & 0 deletions src/core/Akka.TestKit/Internal/Reference.conf
Expand Up @@ -23,6 +23,10 @@ akka {
# by default
single-expect-default = 3s

# duration to wait in expectNoMsg
# by default
expect-no-message-default = 3s

# The timeout that is added as an implicit by DefaultTimeout trait
# This is used for Ask-pattern
default-timeout = 5s
Expand Down
15 changes: 15 additions & 0 deletions src/core/Akka.TestKit/TestKitBase.cs
Expand Up @@ -230,6 +230,7 @@ protected void InitializeTest(ActorSystem system, Config config, string actorSys
}

private TimeSpan SingleExpectDefaultTimeout { get { return _testState.TestKitSettings.SingleExpectDefault; } }
private TimeSpan ExpectNoMessageDefaultTimeout { get { return _testState.TestKitSettings.ExpectNoMessageDefault; } }

/// <summary>
/// The <see cref="ActorSystem"/> that is recreated and used for each test.
Expand Down Expand Up @@ -403,6 +404,20 @@ public TimeSpan RemainingOrDefault
get { return RemainingOr(Dilated(SingleExpectDefaultTimeout)); }
}

/// <summary>
/// <para>
/// Retrieves the time remaining for execution of the innermost enclosing
/// <see cref="Within(TimeSpan, Action, TimeSpan?, CancellationToken)">Within</see> block.
/// If missing that, then it returns the properly dilated default for this
/// case from settings (key: "akka.test.expect-no-message-default").
/// </para>
/// <remarks>The returned value is always finite.</remarks>
/// </summary>
public TimeSpan NoMessageRemainingOrDefault
{
get { return RemainingOr(Dilated(ExpectNoMessageDefaultTimeout)); }
}

/// <summary>
/// <para>
/// Retrieves the time remaining for execution of the innermost enclosing
Expand Down
4 changes: 2 additions & 2 deletions src/core/Akka.TestKit/TestKitBase_Expect.cs
Expand Up @@ -458,7 +458,7 @@ private void AssertPredicateIsTrueForMessage<T>(Predicate<T> isMessage, T m, str
///
/// Wait time is bounded by remaining time for execution of the innermost enclosing 'within'
/// block, if inside a 'within' block; otherwise by the config value
/// "akka.test.single-expect-default".
/// "akka.test.expect-no-message-default".
/// </summary>
public void ExpectNoMsg(CancellationToken cancellationToken = default)
{
Expand All @@ -469,7 +469,7 @@ public void ExpectNoMsg(CancellationToken cancellationToken = default)
/// <inheritdoc cref="ExpectNoMsg(CancellationToken)"/>
public async ValueTask ExpectNoMsgAsync(CancellationToken cancellationToken = default)
{
await InternalExpectNoMsgAsync(RemainingOrDefault, cancellationToken)
await InternalExpectNoMsgAsync(NoMessageRemainingOrDefault, cancellationToken)
.ConfigureAwait(false);
}

Expand Down
5 changes: 5 additions & 0 deletions src/core/Akka.TestKit/TestKitSettings.cs
Expand Up @@ -18,6 +18,7 @@ public class TestKitSettings : IExtension
{
private readonly TimeSpan _defaultTimeout;
private readonly TimeSpan _singleExpectDefault;
private readonly TimeSpan _expectNoMessageDefault;
private readonly TimeSpan _testEventFilterLeeway;
private readonly double _timefactor;
private readonly bool _logTestKitCalls;
Expand All @@ -36,6 +37,7 @@ public TestKitSettings(Config config)

_defaultTimeout = config.GetTimeSpan("akka.test.default-timeout", null, allowInfinite:false);
_singleExpectDefault = config.GetTimeSpan("akka.test.single-expect-default", null, allowInfinite: false);
_expectNoMessageDefault = config.GetTimeSpan("akka.test.expect-no-message-default", null, allowInfinite: false);
_testEventFilterLeeway = config.GetTimeSpan("akka.test.filter-leeway", null, allowInfinite: false);
_timefactor = config.GetDouble("akka.test.timefactor", 0);
_logTestKitCalls = config.GetBoolean("akka.test.testkit.debug", false);
Expand All @@ -54,6 +56,9 @@ public TestKitSettings(Config config)
/// <summary>Gets the config value "akka.test.single-expect-default". It is always finite.</summary>
public TimeSpan SingleExpectDefault { get { return _singleExpectDefault; } }

/// <summary>Gets the config value "akka.test.expect-no-message-default". It is always finite.</summary>
public TimeSpan ExpectNoMessageDefault { get { return _expectNoMessageDefault; } }

/// <summary>Gets the config value "akka.test.filter-leeway". It is always finite.</summary>
public TimeSpan TestEventFilterLeeway { get { return _testEventFilterLeeway; } }

Expand Down