Skip to content

Commit

Permalink
Bump XunitVersion from 2.4.2 to 2.5.0 (#6825)
Browse files Browse the repository at this point in the history
* 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](xunit/xunit@2.4.2...2.5.0)

Updates `xunit.runner.visualstudio` from 2.4.2 to 2.5.0
- [Commits](xunit/xunit@2.4.2...2.5.0)

Updates `xunit.runner.utility` from 2.4.2 to 2.5.0
- [Commits](xunit/xunit@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] <support@github.com>

* 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](xunit/xunit@2.4.2...2.5.0)

Updates `xunit.runner.visualstudio` from 2.4.2 to 2.5.0
- [Commits](xunit/xunit@2.4.2...2.5.0)

Updates `xunit.runner.utility` from 2.4.2 to 2.5.0
- [Commits](xunit/xunit@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] <support@github.com>

* 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] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Gregorius Soedharmo <arkatufus@yahoo.com>
  • Loading branch information
dependabot[bot] and Arkatufus authored Jul 17, 2023
1 parent 15635b5 commit 54f4967
Show file tree
Hide file tree
Showing 23 changed files with 157 additions and 141 deletions.
4 changes: 2 additions & 2 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<LangVersion>11.0</LangVersion>
</PropertyGroup>
<PropertyGroup>
<XunitVersion>2.4.2</XunitVersion>
<XunitRunnerVersion>2.4.2</XunitRunnerVersion>
<XunitVersion>2.5.0</XunitVersion>
<XunitRunnerVersion>2.5.0</XunitRunnerVersion>
<TestSdkVersion>17.6.3</TestSdkVersion>
<HyperionVersion>0.12.2</HyperionVersion>
<NewtonsoftJsonVersion>[13.0.1,)</NewtonsoftJsonVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/benchmark/Akka.Benchmarks/Actor/PingPongBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,37 @@ public NodeMetrics Sample()
using (var process = Process.GetCurrentProcess())
{
process.Refresh();
var metrics = new List<NodeMetrics.Types.Metric>()
{
// Memory
NodeMetrics.Types.Metric.Create(StandardMetrics.MemoryUsed, GC.GetTotalMemory(true)).Value,
var metrics = new List<NodeMetrics.Types.Metric>();

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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ public ORMultiDictionarySpec(ITestOutputHelper output)
public void ORMultiDictionary_must_be_able_to_add_entries()
{
var m = ORMultiValueDictionary<string, string>.Empty.AddItem(_node1, "a", "A").AddItem(_node1, "b", "B");
Assert.Equal(ImmutableDictionary.CreateRange(new[]
m.Entries.Should().BeEquivalentTo(new[]
{
new KeyValuePair<string, IImmutableSet<string>>("a", ImmutableHashSet.Create("A")),
new KeyValuePair<string, IImmutableSet<string>>("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<string, IImmutableSet<string>>("a", ImmutableHashSet.Create("A", "C")),
new KeyValuePair<string, IImmutableSet<string>>("b", ImmutableHashSet.Create("B"))
}), m2.Entries);
});
}

[Fact]
Expand All @@ -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<string, IImmutableSet<string>>("b", ImmutableHashSet.Create("B"))
}), m.Entries);
}));
}

[Fact]
Expand All @@ -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<string, IImmutableSet<string>>("a", ImmutableHashSet.Create("B"))
}), m.Entries);
});
}

[Fact]
Expand All @@ -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]
Expand Down Expand Up @@ -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<string, IImmutableSet<string>>("a", ImmutableHashSet.Create("A2")),
new KeyValuePair<string, IImmutableSet<string>>("b", ImmutableHashSet.Create("B1"))
}), m2.Entries);
});
}

[Fact]
Expand All @@ -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<string, IImmutableSet<string>>("b", ImmutableHashSet.Create("B1"))
}), m2.Entries);
});
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\core\Akka.TestKit\Akka.TestKit.csproj"/>
<PackageReference Include="xunit" Version="$(XunitVersion)"/>
<ProjectReference Include="..\..\..\core\Akka.TestKit\Akka.TestKit.csproj" />
<PackageReference Include="xunit" Version="$(XunitVersion)" />
</ItemGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,44 @@ namespace Akka.TestKit.Xunit.Internals
/// <summary>
/// TBD
/// </summary>
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<object>(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
);

}

/// <summary>
/// Initializes a new instance of the <see cref="AkkaEqualException"/> class.
/// </summary>
/// <param name="expected">The expected value of the object</param>
/// <param name="actual">The actual value of the object</param>
/// <param name="format">A template string that describes the error.</param>
/// <param name="args">An optional object array that contains zero or more objects to format.</param>
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;
Expand All @@ -36,10 +60,9 @@ public AkkaEqualException(object expected, object actual, string format = "", pa
/// <summary>
/// Initializes a new instance of the <see cref="AkkaEqualException"/> class.
/// </summary>
/// <param name="info">The SerializationInfo that holds the serialized object data about the exception being thrown.</param>
/// <param name="context">The StreamingContext that contains contextual information about the source or destination.</param>
protected AkkaEqualException(SerializationInfo info, StreamingContext context)
: base(info, context)
/// <param name="info">The <see cref="SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
/// <param name="context">The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param>
protected AkkaEqualException(SerializationInfo info, StreamingContext context): base(null)
{
}

Expand All @@ -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;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/contrib/testkits/Akka.TestKit.Xunit/XunitAssertions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void AssertEqual<T>(T expected, T actual, string format = "", params obje
{
var comparer = new AkkaAssertEqualityComparer<T>();
if(!comparer.Equals(expected, actual))
throw new AkkaEqualException(expected, actual, format, args);
throw AkkaEqualException.ForMismatchedValues(expected, actual, format, args);
}

/// <summary>
Expand All @@ -83,7 +83,7 @@ public void AssertEqual<T>(T expected, T actual, string format = "", params obje
public void AssertEqual<T>(T expected, T actual, Func<T, T, bool> comparer, string format = "", params object[] args)
{
if(!comparer(expected, actual))
throw new AkkaEqualException(expected, actual, format, args);
throw AkkaEqualException.ForMismatchedValues(expected, actual, format, args);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,50 @@
using System.Runtime.Serialization;
using Xunit.Sdk;

#nullable enable
namespace Akka.TestKit.Xunit2.Internals
{
/// <summary>
/// TBD
/// </summary>
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<object>();

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<object>(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
);
}

/// <summary>
/// Initializes a new instance of the <see cref="AkkaEqualException"/> class.
/// </summary>
/// <param name="expected">The expected value of the object</param>
/// <param name="actual">The actual value of the object</param>
/// <param name="format">A template string that describes the error.</param>
/// <param name="args">An optional object array that contains zero or more objects to format.</param>
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;
Expand All @@ -38,8 +63,7 @@ public AkkaEqualException(object expected, object actual, string format = "", pa
/// </summary>
/// <param name="info">The <see cref="SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
/// <param name="context">The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param>
protected AkkaEqualException(SerializationInfo info, StreamingContext context)
: base(info, context)
protected AkkaEqualException(SerializationInfo info, StreamingContext context): base(null)
{
}

Expand All @@ -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;
}
}
}
Expand Down
Loading

0 comments on commit 54f4967

Please sign in to comment.