From 54f496757433c797224caa0425ebf55776f33281 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 17 Jul 2023 23:18:46 +0700 Subject: [PATCH] Bump XunitVersion from 2.4.2 to 2.5.0 (#6825) * Bump XunitVersion from 2.4.2 to 2.5.0 Bumps `XunitVersion` from 2.4.2 to 2.5.0. Updates `xunit` from 2.4.2 to 2.5.0 - [Commits](https://github.com/xunit/xunit/compare/2.4.2...2.5.0) Updates `xunit.runner.visualstudio` from 2.4.2 to 2.5.0 - [Commits](https://github.com/xunit/xunit/compare/2.4.2...2.5.0) Updates `xunit.runner.utility` from 2.4.2 to 2.5.0 - [Commits](https://github.com/xunit/xunit/compare/2.4.2...2.5.0) --- updated-dependencies: - dependency-name: xunit dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: xunit.runner.visualstudio dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: xunit.runner.utility dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] * Bump XunitVersion from 2.4.2 to 2.5.0 Bumps `XunitVersion` from 2.4.2 to 2.5.0. Updates `xunit` from 2.4.2 to 2.5.0 - [Commits](https://github.com/xunit/xunit/compare/2.4.2...2.5.0) Updates `xunit.runner.visualstudio` from 2.4.2 to 2.5.0 - [Commits](https://github.com/xunit/xunit/compare/2.4.2...2.5.0) Updates `xunit.runner.utility` from 2.4.2 to 2.5.0 - [Commits](https://github.com/xunit/xunit/compare/2.4.2...2.5.0) --- updated-dependencies: - dependency-name: xunit dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: xunit.runner.visualstudio dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: xunit.runner.utility dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] * Fix XUnit 2.5.0 and BenchmarkDotNet breaking changes * Fix namespace change bug * Fix namespace changes * Fix broken unit tests * Harden Cluster.Metrics `Sample()` method, discard illegal metrics values --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Gregorius Soedharmo --- src/Directory.Build.props | 4 +- .../Actor/ActorMemoryFootprintBenchmark.cs | 2 +- .../Actor/PingPongBenchmarks.cs | 2 +- .../Actor/SpawnActorBenchmarks.cs | 2 +- .../IO/TcpOperationsBenchmarks.cs | 2 +- .../Sharding/ShardSpawnBenchmarks.cs | 2 +- .../Collectors/DefaultCollector.cs | 36 ++++++++----- .../ORMultiDictionarySpec.cs | 30 +++++------ .../Akka.TestKit.Xunit.csproj | 4 +- .../Internals/AkkaEqualException.cs | 43 +++++++++++---- .../Akka.TestKit.Xunit/XunitAssertions.cs | 4 +- .../Internals/AkkaEqualException.cs | 46 ++++++++++++---- .../Akka.TestKit.Xunit2/XunitAssertions.cs | 4 +- .../MemberOrderingModelBasedTests.cs | 1 + .../Akka.Streams.Tests/Dsl/FlowAskSpec.cs | 11 ++-- .../Akka.Streams.Tests/Dsl/FlowGroupBySpec.cs | 3 +- .../Akka.Streams.Tests/Dsl/LazySourceSpec.cs | 17 +++--- .../Akka.Streams.Tests/IO/FileSinkSpec.cs | 2 +- .../Akka.Tests.Shared.Internals/AkkaSpec.cs | 53 ++++--------------- .../AkkaSpecExtensions.cs | 7 +-- .../Akka.Tests/Actor/RemotePathParsingSpec.cs | 1 + .../Akka.Tests/Pattern/CircuitBreakerSpec.cs | 21 ++------ .../Util/StableListPriorityQueueSpec.cs | 1 + 23 files changed, 157 insertions(+), 141 deletions(-) diff --git a/src/Directory.Build.props b/src/Directory.Build.props index d33e410db49..6c24322b94f 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -14,8 +14,8 @@ 11.0 - 2.4.2 - 2.4.2 + 2.5.0 + 2.5.0 17.6.3 0.12.2 [13.0.1,) diff --git a/src/benchmark/Akka.Benchmarks/Actor/ActorMemoryFootprintBenchmark.cs b/src/benchmark/Akka.Benchmarks/Actor/ActorMemoryFootprintBenchmark.cs index 162ef45ba5d..9989721cc0b 100644 --- a/src/benchmark/Akka.Benchmarks/Actor/ActorMemoryFootprintBenchmark.cs +++ b/src/benchmark/Akka.Benchmarks/Actor/ActorMemoryFootprintBenchmark.cs @@ -17,7 +17,7 @@ namespace Akka.Benchmarks.Actor { [Config(typeof(MicroBenchmarkConfig))] - [SimpleJob(RunStrategy.Monitoring, targetCount: 25, warmupCount: 5)] + [SimpleJob(RunStrategy.Monitoring, warmupCount: 5)] public class ActorMemoryFootprintBenchmark { public ActorSystem Sys; diff --git a/src/benchmark/Akka.Benchmarks/Actor/PingPongBenchmarks.cs b/src/benchmark/Akka.Benchmarks/Actor/PingPongBenchmarks.cs index cfb8187edd7..73ee3578c30 100644 --- a/src/benchmark/Akka.Benchmarks/Actor/PingPongBenchmarks.cs +++ b/src/benchmark/Akka.Benchmarks/Actor/PingPongBenchmarks.cs @@ -16,7 +16,7 @@ namespace Akka.Benchmarks.Actor { [Config(typeof(MonitoringConfig))] - [SimpleJob(RunStrategy.Monitoring, launchCount: 10, warmupCount: 10, targetCount: 10)] + [SimpleJob(RunStrategy.Monitoring, launchCount: 10, warmupCount: 10)] public class PingPongBenchmarks { public const int Operations = 1_000_000; diff --git a/src/benchmark/Akka.Benchmarks/Actor/SpawnActorBenchmarks.cs b/src/benchmark/Akka.Benchmarks/Actor/SpawnActorBenchmarks.cs index 4c74794dbc0..a2eaa81fc7f 100644 --- a/src/benchmark/Akka.Benchmarks/Actor/SpawnActorBenchmarks.cs +++ b/src/benchmark/Akka.Benchmarks/Actor/SpawnActorBenchmarks.cs @@ -15,7 +15,7 @@ namespace Akka.Benchmarks.Actor { [Config(typeof(MicroBenchmarkConfig))] - [SimpleJob(RunStrategy.Throughput, targetCount:10, warmupCount:5)] + [SimpleJob(RunStrategy.Throughput, warmupCount:5)] public class SpawnActorBenchmarks { [Params(100_000)] diff --git a/src/benchmark/Akka.Benchmarks/IO/TcpOperationsBenchmarks.cs b/src/benchmark/Akka.Benchmarks/IO/TcpOperationsBenchmarks.cs index 8cf649c0582..143f94715a4 100644 --- a/src/benchmark/Akka.Benchmarks/IO/TcpOperationsBenchmarks.cs +++ b/src/benchmark/Akka.Benchmarks/IO/TcpOperationsBenchmarks.cs @@ -23,7 +23,7 @@ namespace Akka.Benchmarks { [Config(typeof(MicroBenchmarkConfig))] - [SimpleJob(warmupCount: 1, invocationCount: 1, launchCount: 1, runStrategy: RunStrategy.Monitoring, targetCount: 100)] + [SimpleJob(warmupCount: 1, invocationCount: 1, launchCount: 1, runStrategy: RunStrategy.Monitoring)] public class TcpOperationsBenchmarks { private ActorSystem _system; diff --git a/src/benchmark/Akka.Cluster.Benchmarks/Sharding/ShardSpawnBenchmarks.cs b/src/benchmark/Akka.Cluster.Benchmarks/Sharding/ShardSpawnBenchmarks.cs index 11cf04057f2..8c5c6c00fb0 100644 --- a/src/benchmark/Akka.Cluster.Benchmarks/Sharding/ShardSpawnBenchmarks.cs +++ b/src/benchmark/Akka.Cluster.Benchmarks/Sharding/ShardSpawnBenchmarks.cs @@ -16,7 +16,7 @@ namespace Akka.Cluster.Benchmarks.Sharding { [Config(typeof(MonitoringConfig))] - [SimpleJob(RunStrategy.ColdStart, targetCount:1, warmupCount:0, launchCount:5)] + [SimpleJob(RunStrategy.ColdStart, warmupCount:0, launchCount:5)] public class ShardSpawnBenchmarks { [Params(StateStoreMode.Persistence, StateStoreMode.DData)] diff --git a/src/contrib/cluster/Akka.Cluster.Metrics/Collectors/DefaultCollector.cs b/src/contrib/cluster/Akka.Cluster.Metrics/Collectors/DefaultCollector.cs index 1ae64cc9587..72fe204173b 100644 --- a/src/contrib/cluster/Akka.Cluster.Metrics/Collectors/DefaultCollector.cs +++ b/src/contrib/cluster/Akka.Cluster.Metrics/Collectors/DefaultCollector.cs @@ -56,25 +56,37 @@ public NodeMetrics Sample() using (var process = Process.GetCurrentProcess()) { process.Refresh(); - var metrics = new List() - { - // Memory - NodeMetrics.Types.Metric.Create(StandardMetrics.MemoryUsed, GC.GetTotalMemory(true)).Value, + var metrics = new List(); + + var totalMemory = NodeMetrics.Types.Metric.Create(StandardMetrics.MemoryUsed, GC.GetTotalMemory(true)); + if(totalMemory.HasValue) + metrics.Add(totalMemory.Value); - // total committed process memory = working set + paged - NodeMetrics.Types.Metric.Create(StandardMetrics.MemoryAvailable, process.WorkingSet64 + process.PagedMemorySize64).Value, - // CPU Processors - NodeMetrics.Types.Metric.Create(StandardMetrics.Processors, Environment.ProcessorCount).Value, - }; + var availableMemory = NodeMetrics.Types.Metric.Create(StandardMetrics.MemoryAvailable, process.WorkingSet64 + process.PagedMemorySize64); + if(availableMemory.HasValue) + metrics.Add(availableMemory.Value); + + var processorCount = NodeMetrics.Types.Metric.Create(StandardMetrics.Processors, Environment.ProcessorCount); + if(processorCount.HasValue) + metrics.Add(processorCount.Value); if (process.MaxWorkingSet != IntPtr.Zero) - metrics.Add(NodeMetrics.Types.Metric.Create(StandardMetrics.MaxMemoryRecommended, process.MaxWorkingSet.ToInt64()).Value); + { + var workingSet = NodeMetrics.Types.Metric.Create(StandardMetrics.MaxMemoryRecommended, process.MaxWorkingSet.ToInt64()); + if(workingSet.HasValue) + metrics.Add(workingSet.Value); + } var (processCpuUsage, totalCpuUsage) = GetCpuUsages(process.Id); + // CPU % by process - metrics.Add(NodeMetrics.Types.Metric.Create(StandardMetrics.CpuProcessUsage, processCpuUsage).Value); + var cpuUsage = NodeMetrics.Types.Metric.Create(StandardMetrics.CpuProcessUsage, processCpuUsage); + if(cpuUsage.HasValue) + metrics.Add(cpuUsage.Value); + // CPU % by all processes that are used for overall CPU capacity calculation - metrics.Add(NodeMetrics.Types.Metric.Create(StandardMetrics.CpuTotalUsage, totalCpuUsage).Value); + var totalCpu = NodeMetrics.Types.Metric.Create(StandardMetrics.CpuTotalUsage, totalCpuUsage); + metrics.Add(totalCpu.Value); return new NodeMetrics(_address, DateTime.UtcNow.ToTimestamp(), metrics); } diff --git a/src/contrib/cluster/Akka.DistributedData.Tests/ORMultiDictionarySpec.cs b/src/contrib/cluster/Akka.DistributedData.Tests/ORMultiDictionarySpec.cs index 30c0c98d972..31ec85f5a93 100644 --- a/src/contrib/cluster/Akka.DistributedData.Tests/ORMultiDictionarySpec.cs +++ b/src/contrib/cluster/Akka.DistributedData.Tests/ORMultiDictionarySpec.cs @@ -35,18 +35,18 @@ public ORMultiDictionarySpec(ITestOutputHelper output) public void ORMultiDictionary_must_be_able_to_add_entries() { var m = ORMultiValueDictionary.Empty.AddItem(_node1, "a", "A").AddItem(_node1, "b", "B"); - Assert.Equal(ImmutableDictionary.CreateRange(new[] + m.Entries.Should().BeEquivalentTo(new[] { new KeyValuePair>("a", ImmutableHashSet.Create("A")), new KeyValuePair>("b", ImmutableHashSet.Create("B")) - }), m.Entries); + }); var m2 = m.AddItem(_node1, "a", "C"); - Assert.Equal(ImmutableDictionary.CreateRange(new[] + m2.Entries.Should().BeEquivalentTo(new[] { new KeyValuePair>("a", ImmutableHashSet.Create("A", "C")), new KeyValuePair>("b", ImmutableHashSet.Create("B")) - }), m2.Entries); + }); } [Fact] @@ -57,10 +57,10 @@ public void ORMultiDictionary_must_be_able_to_remove_entries() .AddItem(_node1, "b", "B") .RemoveItem(_node1, "a", "A"); - Assert.Equal(ImmutableDictionary.CreateRange(new[] + m.Entries.Should().BeEquivalentTo(ImmutableDictionary.CreateRange(new[] { new KeyValuePair>("b", ImmutableHashSet.Create("B")) - }), m.Entries); + })); } [Fact] @@ -70,10 +70,10 @@ public void ORMultiDictionary_must_be_able_to_replace_entries() .AddItem(_node1, "a", "A") .ReplaceItem(_node1, "a", "A", "B"); - Assert.Equal(ImmutableDictionary.CreateRange(new[] + m.Entries.Should().BeEquivalentTo(new[] { new KeyValuePair>("a", ImmutableHashSet.Create("B")) - }), m.Entries); + }); } [Fact] @@ -95,10 +95,10 @@ public void ORMultiDictionary_must_be_able_to_have_its_entries_correctly_merged_ }); var merged1 = m1.Merge(m2); - Assert.Equal(expected, merged1.Entries); + merged1.Entries.Should().BeEquivalentTo(expected); var merged2 = m2.Merge(m1); - Assert.Equal(expected, merged2.Entries); + merged2.Entries.Should().BeEquivalentTo(expected); } [Fact] @@ -183,14 +183,14 @@ public void ORMultiDictionary_must_be_able_to_get_all_bindings_for_an_entry_and_ .AddItem(_node1, "b", "B1"); m.TryGetValue("a", out var a); - Assert.Equal(ImmutableHashSet.Create("A1", "A2"), a); + a.Should().BeEquivalentTo(ImmutableHashSet.Create("A1", "A2")); var m2 = m.SetItems(_node1, "a", a.Remove("A1")); - Assert.Equal(ImmutableDictionary.CreateRange(new[] + m2.Entries.Should().BeEquivalentTo(new[] { new KeyValuePair>("a", ImmutableHashSet.Create("A2")), new KeyValuePair>("b", ImmutableHashSet.Create("B1")) - }), m2.Entries); + }); } [Fact] @@ -214,10 +214,10 @@ public void ORMultiDictionary_must_remove_all_bindings_for_a_given_key() .AddItem(_node1, "b", "B1"); var m2 = m.Remove(_node1, "a"); - Assert.Equal(ImmutableDictionary.CreateRange(new[] + m2.Entries.Should().BeEquivalentTo(new[] { new KeyValuePair>("b", ImmutableHashSet.Create("B1")) - }), m2.Entries); + }); } [Fact] diff --git a/src/contrib/testkits/Akka.TestKit.Xunit/Akka.TestKit.Xunit.csproj b/src/contrib/testkits/Akka.TestKit.Xunit/Akka.TestKit.Xunit.csproj index 32c6b57097e..0c16a328b8e 100644 --- a/src/contrib/testkits/Akka.TestKit.Xunit/Akka.TestKit.Xunit.csproj +++ b/src/contrib/testkits/Akka.TestKit.Xunit/Akka.TestKit.Xunit.csproj @@ -9,8 +9,8 @@ - - + + diff --git a/src/contrib/testkits/Akka.TestKit.Xunit/Internals/AkkaEqualException.cs b/src/contrib/testkits/Akka.TestKit.Xunit/Internals/AkkaEqualException.cs index c0645dd79eb..cf776c3be49 100644 --- a/src/contrib/testkits/Akka.TestKit.Xunit/Internals/AkkaEqualException.cs +++ b/src/contrib/testkits/Akka.TestKit.Xunit/Internals/AkkaEqualException.cs @@ -14,20 +14,44 @@ namespace Akka.TestKit.Xunit.Internals /// /// TBD /// - public class AkkaEqualException : EqualException + public class AkkaEqualException : XunitException { + private static readonly string NewLineAndIndent = Environment.NewLine + new string(' ', 10); // Length of "Expected: " and "Actual: " + private readonly string _format; private readonly object[] _args; + public static AkkaEqualException ForMismatchedValues( + object expected, + object actual, + string format = null, + params object[] args) + { + // Strings normally come through ForMismatchedStrings, so we want to make sure any + // string value that comes through here isn't re-formatted/truncated. This is for + // two reasons: (a) to support Assert.Equal(string1, string2) to get a full + // printout of the raw string values, which is useful when debugging; and (b) to + // allow the assertion functions to pre-format the value themselves, perhaps with + // additional information (like DateTime/DateTimeOffset when providing the precision + // of the comparison). + var expectedText = expected as string ?? ArgumentFormatter.Format(expected); + var actualText = actual as string ?? ArgumentFormatter.Format(actual); + + return new AkkaEqualException( + @$"Assert.Equal() Failure: {format ?? "Values differ"}{Environment.NewLine} +Expected: {expectedText.Replace(Environment.NewLine, NewLineAndIndent)}{Environment.NewLine} +Actual: {actualText.Replace(Environment.NewLine, NewLineAndIndent)}", + args + ); + + } + /// /// Initializes a new instance of the class. /// - /// The expected value of the object - /// The actual value of the object /// A template string that describes the error. /// An optional object array that contains zero or more objects to format. - public AkkaEqualException(object expected, object actual, string format = "", params object[] args) - : base(expected, actual) + public AkkaEqualException(string format = "", params object[] args): base(null) { _format = format; _args = args; @@ -36,10 +60,9 @@ public AkkaEqualException(object expected, object actual, string format = "", pa /// /// Initializes a new instance of the class. /// - /// The SerializationInfo that holds the serialized object data about the exception being thrown. - /// The StreamingContext that contains contextual information about the source or destination. - protected AkkaEqualException(SerializationInfo info, StreamingContext context) - : base(info, context) + /// The that holds the serialized object data about the exception being thrown. + /// The that contains contextual information about the source or destination. + protected AkkaEqualException(SerializationInfo info, StreamingContext context): base(null) { } @@ -63,7 +86,7 @@ public override string Message message = $@"[Could not string.Format(""{_format}"", {string.Join(", ", _args)})]"; } - return $"{base.Message} {message}"; + return base.Message is not null ? $"{base.Message} {message}" : message; } } } diff --git a/src/contrib/testkits/Akka.TestKit.Xunit/XunitAssertions.cs b/src/contrib/testkits/Akka.TestKit.Xunit/XunitAssertions.cs index cce8412a407..bec8a9d67b6 100644 --- a/src/contrib/testkits/Akka.TestKit.Xunit/XunitAssertions.cs +++ b/src/contrib/testkits/Akka.TestKit.Xunit/XunitAssertions.cs @@ -64,7 +64,7 @@ public void AssertEqual(T expected, T actual, string format = "", params obje { var comparer = new AkkaAssertEqualityComparer(); if(!comparer.Equals(expected, actual)) - throw new AkkaEqualException(expected, actual, format, args); + throw AkkaEqualException.ForMismatchedValues(expected, actual, format, args); } /// @@ -83,7 +83,7 @@ public void AssertEqual(T expected, T actual, string format = "", params obje public void AssertEqual(T expected, T actual, Func comparer, string format = "", params object[] args) { if(!comparer(expected, actual)) - throw new AkkaEqualException(expected, actual, format, args); + throw AkkaEqualException.ForMismatchedValues(expected, actual, format, args); } } } diff --git a/src/contrib/testkits/Akka.TestKit.Xunit2/Internals/AkkaEqualException.cs b/src/contrib/testkits/Akka.TestKit.Xunit2/Internals/AkkaEqualException.cs index ca1775dc755..eddf0359832 100644 --- a/src/contrib/testkits/Akka.TestKit.Xunit2/Internals/AkkaEqualException.cs +++ b/src/contrib/testkits/Akka.TestKit.Xunit2/Internals/AkkaEqualException.cs @@ -9,25 +9,50 @@ using System.Runtime.Serialization; using Xunit.Sdk; +#nullable enable namespace Akka.TestKit.Xunit2.Internals { /// /// TBD /// - public class AkkaEqualException : EqualException + public class AkkaEqualException : XunitException { - private readonly string _format; - private readonly object[] _args; + // Length of "Expected: " and "Actual: " + private static readonly string NewLineAndIndent = Environment.NewLine + new string(' ', 10); + + private readonly string? _format; + private readonly object[] _args = Array.Empty(); + public static AkkaEqualException ForMismatchedValues( + object? expected, + object? actual, + string? format = null, + params object[] args) + { + // Strings normally come through ForMismatchedStrings, so we want to make sure any + // string value that comes through here isn't re-formatted/truncated. This is for + // two reasons: (a) to support Assert.Equal(string1, string2) to get a full + // printout of the raw string values, which is useful when debugging; and (b) to + // allow the assertion functions to pre-format the value themselves, perhaps with + // additional information (like DateTime/DateTimeOffset when providing the precision + // of the comparison). + var expectedText = expected as string ?? ArgumentFormatter.Format(expected); + var actualText = actual as string ?? ArgumentFormatter.Format(actual); + + return new AkkaEqualException( + @$"Assert.Equal() Failure: {format ?? "Values differ"}Environment.NewLine +Expected: {expectedText.Replace(Environment.NewLine, NewLineAndIndent)}{Environment.NewLine} +Actual: {actualText.Replace(Environment.NewLine, NewLineAndIndent)}", + args + ); + } + /// /// Initializes a new instance of the class. /// - /// The expected value of the object - /// The actual value of the object /// A template string that describes the error. /// An optional object array that contains zero or more objects to format. - public AkkaEqualException(object expected, object actual, string format = "", params object[] args) - : base(expected, actual) + public AkkaEqualException(string format = "", params object[] args): base(null) { _format = format; _args = args; @@ -38,8 +63,7 @@ public AkkaEqualException(object expected, object actual, string format = "", pa /// /// The that holds the serialized object data about the exception being thrown. /// The that contains contextual information about the source or destination. - protected AkkaEqualException(SerializationInfo info, StreamingContext context) - : base(info, context) + protected AkkaEqualException(SerializationInfo info, StreamingContext context): base(null) { } @@ -56,14 +80,14 @@ public override string Message string message; try { - message = string.Format(_format, _args); + message = string.Format(_format!, _args); } catch(Exception) { message = $@"[Could not string.Format(""{_format}"", {string.Join(", ", _args)})]"; } - return $"{base.Message} {message}"; + return base.Message is not null ? $"{base.Message} {message}" : message; } } } diff --git a/src/contrib/testkits/Akka.TestKit.Xunit2/XunitAssertions.cs b/src/contrib/testkits/Akka.TestKit.Xunit2/XunitAssertions.cs index 20adbe85ff4..02e212c216f 100644 --- a/src/contrib/testkits/Akka.TestKit.Xunit2/XunitAssertions.cs +++ b/src/contrib/testkits/Akka.TestKit.Xunit2/XunitAssertions.cs @@ -64,7 +64,7 @@ public void AssertEqual(T expected, T actual, string format = "", params obje { var comparer = new AkkaAssertEqualityComparer(); if(!comparer.Equals(expected, actual)) - throw new AkkaEqualException(expected, actual, format, args); + throw AkkaEqualException.ForMismatchedValues(expected, actual, format, args); } /// @@ -83,7 +83,7 @@ public void AssertEqual(T expected, T actual, string format = "", params obje public void AssertEqual(T expected, T actual, Func comparer, string format = "", params object[] args) { if(!comparer(expected, actual)) - throw new AkkaEqualException(expected, actual, format, args); + throw AkkaEqualException.ForMismatchedValues(expected, actual, format, args); } } } diff --git a/src/core/Akka.Cluster.Tests/MemberOrderingModelBasedTests.cs b/src/core/Akka.Cluster.Tests/MemberOrderingModelBasedTests.cs index 725bec2f0f2..917911ac475 100644 --- a/src/core/Akka.Cluster.Tests/MemberOrderingModelBasedTests.cs +++ b/src/core/Akka.Cluster.Tests/MemberOrderingModelBasedTests.cs @@ -17,6 +17,7 @@ using FsCheck.Experimental; using FsCheck.Xunit; +#pragma warning disable xUnit1028 namespace Akka.Cluster.Tests { public class MemberOrderingModelBasedTests diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowAskSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowAskSpec.cs index 3db6cd56abb..e4a0766e34d 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowAskSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowAskSpec.cs @@ -14,6 +14,7 @@ using Akka.Streams.Dsl; using Akka.Streams.TestKit; using Akka.TestKit; +using Akka.TestKit.Extensions; using Akka.TestKit.TestActors; using Akka.TestKit.Xunit2.Attributes; using Akka.Util; @@ -258,18 +259,18 @@ public async Task Flow_with_ask_must_signal_ask_failure() => await this.AssertAl }, _materializer); [Fact] - public async Task Flow_with_ask_signal_failure_when_target_actor_is_terminated() => await this.AssertAllStagesStoppedAsync(() => { + public async Task Flow_with_ask_signal_failure_when_target_actor_is_terminated() => await this.AssertAllStagesStoppedAsync(async () => { var r = Sys.ActorOf(Props.Create(() => new Replier()).WithDispatcher("akka.test.stream-dispatcher"), "replyRandomDelays"); var done = Source.Maybe() .Ask(r, _timeout, 4) .RunWith(Sink.Ignore(), _materializer); - Intercept(() => + await InterceptAsync(async () => { r.Tell(PoisonPill.Instance); - done.Wait(RemainingOrDefault); - }); - return Task.CompletedTask; + await done; + }).ShouldCompleteWithin(RemainingOrDefault); + }, _materializer); [Fact] diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowGroupBySpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowGroupBySpec.cs index 8cc3bf43a1e..e593ac3e18a 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowGroupBySpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowGroupBySpec.cs @@ -19,6 +19,7 @@ using Akka.Streams.TestKit; using Akka.TestKit; using Akka.TestKit.Extensions; +using Akka.TestKit.Xunit2.Internals; using Akka.Util; using FluentAssertions; using FluentAssertions.Extensions; @@ -698,7 +699,7 @@ await this.AssertAllStagesStoppedAsync(async () => await RandomDemandAsync(map, props); } else - throw new AssertActualExpectedException(true, false, "state.HasDemand INVALID STATE"); + throw new XunitException("state.HasDemand INVALID STATE"); } else { diff --git a/src/core/Akka.Streams.Tests/Dsl/LazySourceSpec.cs b/src/core/Akka.Streams.Tests/Dsl/LazySourceSpec.cs index 3bfba2123dc..7292f421982 100644 --- a/src/core/Akka.Streams.Tests/Dsl/LazySourceSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/LazySourceSpec.cs @@ -20,6 +20,7 @@ using Xunit; using FluentAssertions.Extensions; using Xunit.Sdk; +using static FluentAssertions.FluentActions; namespace Akka.Streams.Tests.Dsl { @@ -64,16 +65,14 @@ await this.AssertAllStagesStoppedAsync(() => { [Fact] public async Task A_lazy_source_must_fail_the_materialized_value_when_downstream_cancels_without_ever_consuming_any_element() { - await this.AssertAllStagesStoppedAsync(() => { - var result = Source.Lazily(() => Source.From(new[] { 1, 2, 3 })) - .ToMaterialized(Sink.Cancelled(), Keep.Left) - .Run(Materializer); - - AssertThrows(() => + await this.AssertAllStagesStoppedAsync(async () => + { + await Awaiting(async () => { - var boom = result.Result; - }); - return Task.CompletedTask; + await Source.Lazily(() => Source.From(new[] { 1, 2, 3 })) + .ToMaterialized(Sink.Cancelled(), Keep.Left) + .Run(Materializer); + }).Should().ThrowAsync().ShouldCompleteWithin(3.Seconds()); }, Materializer); } diff --git a/src/core/Akka.Streams.Tests/IO/FileSinkSpec.cs b/src/core/Akka.Streams.Tests/IO/FileSinkSpec.cs index bc8d6eddc54..4bab68295b5 100644 --- a/src/core/Akka.Streams.Tests/IO/FileSinkSpec.cs +++ b/src/core/Akka.Streams.Tests/IO/FileSinkSpec.cs @@ -343,7 +343,7 @@ await TargetFileAsync(async f => }) .RunWith(FileIO.ToFile(f), _materializer); - var ex = Intercept(() => completion.Wait(TimeSpan.FromSeconds(3))); + var ex = await InterceptAsync(() => completion).ShouldCompleteWithin(3.Seconds()); ex.IoResult.Count.ShouldBe(1001); CheckFileContent(f, string.Join("", _testLines.TakeWhile(s => !s.Contains('b')))); await Task.CompletedTask; diff --git a/src/core/Akka.Tests.Shared.Internals/AkkaSpec.cs b/src/core/Akka.Tests.Shared.Internals/AkkaSpec.cs index fb73b6ae338..8d70ec89c9d 100644 --- a/src/core/Akka.Tests.Shared.Internals/AkkaSpec.cs +++ b/src/core/Akka.Tests.Shared.Internals/AkkaSpec.cs @@ -19,9 +19,11 @@ using Akka.TestKit.TestEvent; using Akka.Util; using Akka.Util.Internal; +using FluentAssertions; using Xunit; using Xunit.Abstractions; using Xunit.Sdk; +using static FluentAssertions.FluentActions; // ReSharper disable once CheckNamespace namespace Akka.TestKit @@ -271,23 +273,13 @@ protected T ExpectMsgPf(string hint, TestKitBase probe, Func pf) /// If the passed action does not complete abruptly with an exception that's an instance of the specified type. protected T Intercept(Action actionThatThrows) where T : Exception { - try - { - actionThatThrows(); - } - catch (Exception ex) - { - var exception = ex is AggregateException aggregateException - ? aggregateException.Flatten().InnerExceptions[0] - : ex; - - var exceptionType = typeof(T); - return exceptionType == exception.GetType() - ? (T)exception - : throw new ThrowsException(exceptionType, exception); - } + return Invoking(actionThatThrows) + .Should().ThrowExactly().And; + } - throw new ThrowsException(typeof(T)); + protected async Task InterceptAsync(Func funcThatThrows) where T : Exception + { + return (await funcThatThrows.Should().ThrowExactlyAsync()).And; } /// @@ -308,38 +300,13 @@ protected T Intercept(Action actionThatThrows) where T : Exception /// If the passed action does not complete abruptly with an exception that's an instance of the specified type. protected void AssertThrows(Action actionThatThrows) where T : Exception { - try - { - actionThatThrows(); - } - catch (Exception ex) - { - var exception = ex is AggregateException aggregateException - ? aggregateException.Flatten().InnerExceptions[0] - : ex; - - var exceptionType = typeof(T); - if (exceptionType == exception.GetType()) - return; - - throw new ThrowsException(exceptionType, exception); - } - - throw new ThrowsException(typeof(T)); + Intercept(actionThatThrows); } [Obsolete("Use AssertThrows instead.")] protected void Intercept(Action actionThatThrows) { - try - { - actionThatThrows(); - } - catch(Exception) - { - return; - } - throw new ThrowsException(typeof(Exception)); + Invoking(actionThatThrows).Should().Throw(); } protected void MuteDeadLetters(params Type[] messageClasses) diff --git a/src/core/Akka.Tests.Shared.Internals/AkkaSpecExtensions.cs b/src/core/Akka.Tests.Shared.Internals/AkkaSpecExtensions.cs index d87f279d59f..7bd82f080e6 100644 --- a/src/core/Akka.Tests.Shared.Internals/AkkaSpecExtensions.cs +++ b/src/core/Akka.Tests.Shared.Internals/AkkaSpecExtensions.cs @@ -9,6 +9,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Akka.TestKit.Xunit2.Internals; using Akka.Util.Internal; using Xunit; using Xunit.Sdk; @@ -79,12 +80,12 @@ public static async Task ShouldBeAsync(this IAsyncEnumerable self, IEnumer { l1.Add($"'{e1.Current}'"); if (!e2.MoveNext()) - throw new AssertActualExpectedException( + throw AkkaEqualException.ForMismatchedValues( l2, l1, $"Input has more elements than expected, differ at index {index}"); l2.Add($"'{e2.Current}'"); if(!comparer.Equals(e1.Current, e2.Current)) - throw new AssertActualExpectedException( + throw AkkaEqualException.ForMismatchedValues( l2, l1, $"Input is not equal to expected, differ at index {index}"); index++; @@ -93,7 +94,7 @@ public static async Task ShouldBeAsync(this IAsyncEnumerable self, IEnumer if (e2.MoveNext()) { l2.Add($"'{e2.Current}'"); - throw new AssertActualExpectedException( + throw AkkaEqualException.ForMismatchedValues( l2, l1, $"Input has less elements than expected, differ at index {index}"); } } diff --git a/src/core/Akka.Tests/Actor/RemotePathParsingSpec.cs b/src/core/Akka.Tests/Actor/RemotePathParsingSpec.cs index e0582f2a188..8d4a4ec5892 100644 --- a/src/core/Akka.Tests/Actor/RemotePathParsingSpec.cs +++ b/src/core/Akka.Tests/Actor/RemotePathParsingSpec.cs @@ -14,6 +14,7 @@ using FsCheck.Xunit; using static Akka.Util.RuntimeDetector; +#pragma warning disable xUnit1028 namespace Akka.Tests.Actor { /// diff --git a/src/core/Akka.Tests/Pattern/CircuitBreakerSpec.cs b/src/core/Akka.Tests/Pattern/CircuitBreakerSpec.cs index 6081231018f..c59b60f5062 100644 --- a/src/core/Akka.Tests/Pattern/CircuitBreakerSpec.cs +++ b/src/core/Akka.Tests/Pattern/CircuitBreakerSpec.cs @@ -8,14 +8,15 @@ using System; using System.Diagnostics; using System.Linq; +using System.Runtime.ExceptionServices; using System.Runtime.Serialization; using System.Threading; using System.Threading.Tasks; using Akka.Pattern; using Akka.TestKit; using Akka.Util.Internal; +using FluentAssertions; using Xunit; -using Xunit.Sdk; namespace Akka.Tests.Pattern { @@ -360,23 +361,7 @@ protected T InterceptException(Action actionThatThrows) where T : Exception = protected static async Task InterceptException(Func actionThatThrows) where T : Exception { - try - { - await actionThatThrows(); - } - catch (Exception ex) - { - var exception = ex is AggregateException aggregateException - ? aggregateException.Flatten().InnerExceptions[0] - : ex; - - var exceptionType = typeof(T); - return exceptionType == exception.GetType() - ? (T)exception - : throw new ThrowsException(exceptionType, exception); - } - - throw new ThrowsException(typeof(T)); + return (await actionThatThrows.Should().ThrowExactlyAsync()).And; } public TestBreaker ShortCallTimeoutCb() => diff --git a/src/core/Akka.Tests/Util/StableListPriorityQueueSpec.cs b/src/core/Akka.Tests/Util/StableListPriorityQueueSpec.cs index 478ad0722a9..39e83b87260 100644 --- a/src/core/Akka.Tests/Util/StableListPriorityQueueSpec.cs +++ b/src/core/Akka.Tests/Util/StableListPriorityQueueSpec.cs @@ -12,6 +12,7 @@ using FsCheck; using FsCheck.Xunit; +#pragma warning disable xUnit1028 namespace Akka.Tests.Util { public class StableListPriorityQueueSpec