diff --git a/src/core/Akka.TestKit.Tests/TestKit_Config_Tests.cs b/src/core/Akka.TestKit.Tests/TestKit_Config_Tests.cs index 0ac5a404dce..89ae224b2ad 100644 --- a/src/core/Akka.TestKit.Tests/TestKit_Config_Tests.cs +++ b/src/core/Akka.TestKit.Tests/TestKit_Config_Tests.cs @@ -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; diff --git a/src/core/Akka.TestKit/Internal/Reference.conf b/src/core/Akka.TestKit/Internal/Reference.conf index b5e18e3e159..d08b360d617 100644 --- a/src/core/Akka.TestKit/Internal/Reference.conf +++ b/src/core/Akka.TestKit/Internal/Reference.conf @@ -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 diff --git a/src/core/Akka.TestKit/TestKitBase.cs b/src/core/Akka.TestKit/TestKitBase.cs index 0e760de6f3a..4e837f52d42 100644 --- a/src/core/Akka.TestKit/TestKitBase.cs +++ b/src/core/Akka.TestKit/TestKitBase.cs @@ -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; } } /// /// The that is recreated and used for each test. @@ -403,6 +404,20 @@ public TimeSpan RemainingOrDefault get { return RemainingOr(Dilated(SingleExpectDefaultTimeout)); } } + /// + /// + /// Retrieves the time remaining for execution of the innermost enclosing + /// Within block. + /// If missing that, then it returns the properly dilated default for this + /// case from settings (key: "akka.test.expect-no-message-default"). + /// + /// The returned value is always finite. + /// + public TimeSpan NoMessageRemainingOrDefault + { + get { return RemainingOr(Dilated(ExpectNoMessageDefaultTimeout)); } + } + /// /// /// Retrieves the time remaining for execution of the innermost enclosing diff --git a/src/core/Akka.TestKit/TestKitBase_Expect.cs b/src/core/Akka.TestKit/TestKitBase_Expect.cs index dd219f5d0bf..4474beee416 100644 --- a/src/core/Akka.TestKit/TestKitBase_Expect.cs +++ b/src/core/Akka.TestKit/TestKitBase_Expect.cs @@ -458,7 +458,7 @@ private async ValueTask InternalExpectMsgEnvelopeAsync( /// /// 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". /// public void ExpectNoMsg(CancellationToken cancellationToken = default) { @@ -469,7 +469,7 @@ public void ExpectNoMsg(CancellationToken cancellationToken = default) /// public async ValueTask ExpectNoMsgAsync(CancellationToken cancellationToken = default) { - await InternalExpectNoMsgAsync(RemainingOrDefault, cancellationToken) + await InternalExpectNoMsgAsync(NoMessageRemainingOrDefault, cancellationToken) .ConfigureAwait(false); } diff --git a/src/core/Akka.TestKit/TestKitSettings.cs b/src/core/Akka.TestKit/TestKitSettings.cs index b7dd269fd1d..ec7b6b29d5f 100644 --- a/src/core/Akka.TestKit/TestKitSettings.cs +++ b/src/core/Akka.TestKit/TestKitSettings.cs @@ -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; @@ -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); @@ -54,6 +56,9 @@ public TestKitSettings(Config config) /// Gets the config value "akka.test.single-expect-default". It is always finite. public TimeSpan SingleExpectDefault { get { return _singleExpectDefault; } } + /// Gets the config value "akka.test.expect-no-message-default". It is always finite. + public TimeSpan ExpectNoMessageDefault { get { return _expectNoMessageDefault; } } + /// Gets the config value "akka.test.filter-leeway". It is always finite. public TimeSpan TestEventFilterLeeway { get { return _testEventFilterLeeway; } }