Skip to content

Commit

Permalink
* added config expect-no-message-default = 3s
Browse files Browse the repository at this point in the history
* added this config into TestKit setting as ExpectNoMessageDefault property
* in TestKit_Expect, bounded relevant overloads of ExpectNoMsg and ExpectNoMsgAsync to the new config
* updated unit test
  • Loading branch information
YariSPB committed Nov 17, 2023
1 parent aeec1b9 commit 218c582
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/core/Akka.TestKit.Tests/TestKit_Config_Tests.cs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ private async ValueTask<MessageEnvelope> InternalExpectMsgEnvelopeAsync<T>(
///
/// 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
Original file line number Diff line number Diff line change
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

0 comments on commit 218c582

Please sign in to comment.