Skip to content
This repository was archived by the owner on Jul 15, 2023. It is now read-only.

Update xunit version to 2.4 and target NS2.0 #269

Merged
merged 10 commits into from
Jul 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion BuildForPublication.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
setlocal EnableDelayedExpansion
set errorlevel=
set BuildConfiguration=Release
set VersionSuffix=beta-build0019
set VersionSuffix=beta-build0020

REM Check that git is on path.
where.exe /Q git.exe || (
Expand Down
4 changes: 2 additions & 2 deletions build.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ setlocal
cd /d %~dp0tests\simpleharness
call :dotnet_build || exit /b 1

for %%v in (netcoreapp1.0 netcoreapp1.1 netcoreapp2.0 net461) do (
for %%v in (netcoreapp2.0 net461) do (
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add netcoreapp2.1 testing too, and download latest tooling too: 2.1.300?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong opinion here but I think netcoreapp2.0 is enough for the test matrix.

dotnet.exe publish -c %BuildConfiguration% --framework "%%v" || exit /b 1
pushd ".\bin\%BuildConfiguration%\%%v\publish"
if "%%v" == "net461" (
Expand All @@ -90,7 +90,7 @@ setlocal
cd /d %~dp0tests\scenariobenchmark
call :dotnet_build || exit /b 1

for %%v in (netcoreapp1.0 netcoreapp1.1 netcoreapp2.0 net461) do (
for %%v in (netcoreapp2.0 net461) do (
dotnet.exe publish -c %BuildConfiguration% --framework "%%v" || exit /b 1
pushd ".\bin\%BuildConfiguration%\%%v\publish"
if "%%v" == "net461" (
Expand Down
2 changes: 1 addition & 1 deletion dotnet-install.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ setlocal
)

echo Executing dotnet installer script "%DotNet_Path%\dotnet-install.ps1"
for %%v in (1.0.0 1.1.0 2.0.0) do (
for %%v in (2.0.0) do (
echo Installing dotnet sdk version %%~v
powershell -NoProfile -ExecutionPolicy unrestricted -Command "&'%DotNet_Path%\dotnet-install.ps1' -InstallDir '%DotNet_Path%' -Version '%%~v'" || (
call :print_error_message Failed to install dotnet shared runtime %%~v
Expand Down
2 changes: 1 addition & 1 deletion src/version.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<MicrosoftDiagnosticsTracingLibraryVersion>2.0.5</MicrosoftDiagnosticsTracingLibraryVersion>
<XunitPackageVersion>2.2.0-beta2-build3300</XunitPackageVersion>
<XunitPackageVersion>2.4.0</XunitPackageVersion>
</PropertyGroup>
</Project>
19 changes: 15 additions & 4 deletions src/xunit.performance.api/ConsoleDiagnosticMessageSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,23 @@ namespace Microsoft.Xunit.Performance.Api
/// This is the message sink that receives IDiagnosticMessage messages from
/// the XunitFrontController.
/// </summary>
internal sealed class ConsoleDiagnosticMessageSink : TestMessageVisitor<IDiagnosticMessage>
internal sealed class ConsoleDiagnosticMessageSink : TestMessageSink
{
protected override bool Visit(IDiagnosticMessage diagnosticMessage)
public ConsoleDiagnosticMessageSink()
{
WriteErrorLine(diagnosticMessage.Message);
return true;
Diagnostics.DiagnosticMessageEvent += OnDiagnosticMessageEvent;
}

private static void OnDiagnosticMessageEvent(MessageHandlerArgs<IDiagnosticMessage> args)
{
WriteErrorLine(args.Message.Message);
}

public override void Dispose()
{
Diagnostics.DiagnosticMessageEvent -= OnDiagnosticMessageEvent;

base.Dispose();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,30 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading;
using Xunit;
using Xunit.Abstractions;

namespace Microsoft.Xunit.Performance.Api
{
internal sealed class PerformanceTestMessageVisitor : TestMessageVisitor<IDiscoveryCompleteMessage>
internal sealed class PerformanceTestMessageSink : TestMessageSink
{
public PerformanceTestMessageVisitor()
public PerformanceTestMessageSink()
{
Finished = new ManualResetEvent(false);
Tests = new List<PerformanceTestMessage>();
Discovery.TestCaseDiscoveryMessageEvent += OnTestCaseDiscoveryMessageEvent;
Discovery.DiscoveryCompleteMessageEvent += OnDiscoveryCompleteMessageEvent;
}

public List<PerformanceTestMessage> Tests { get; }

protected override bool Visit(ITestCaseDiscoveryMessage testCaseDiscovered)
private void OnTestCaseDiscoveryMessageEvent(MessageHandlerArgs<ITestCaseDiscoveryMessage> args)
{
var testCase = testCaseDiscovered.TestCase;
var testCase = args.Message.TestCase;
if (string.IsNullOrEmpty(testCase.SkipReason)) /* TODO: Currently there are not filters */
{
var testMethod = testCaseDiscovered.TestMethod;
var testMethod = args.Message.TestMethod;
var metrics = new List<PerformanceMetricInfo>();
var attributesInfo = GetMetricAttributes(testMethod);

Expand All @@ -38,12 +42,16 @@ protected override bool Visit(ITestCaseDiscoveryMessage testCaseDiscovered)
{
Tests.Add(new PerformanceTestMessage
{
TestCase = testCaseDiscovered.TestCase,
TestCase = args.Message.TestCase,
Metrics = metrics
});
}
}
return true;
}

private void OnDiscoveryCompleteMessageEvent(MessageHandlerArgs<IDiscoveryCompleteMessage> args)
{
Finished.Set();
}

private static IEnumerable<IAttributeInfo> GetMetricAttributes(ITestMethod testMethod)
Expand Down Expand Up @@ -78,5 +86,15 @@ private static Type GetType(string assemblyName, string typeName)

return null;
}

public override void Dispose()
{
Discovery.DiscoveryCompleteMessageEvent -= OnDiscoveryCompleteMessageEvent;
Discovery.TestCaseDiscoveryMessageEvent -= OnTestCaseDiscoveryMessageEvent;

base.Dispose();
}

public ManualResetEvent Finished { get; }
}
}
12 changes: 6 additions & 6 deletions src/xunit.performance.api/XunitBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ public static XUnitPerformanceMetricData GetMetadata(
appDomainSupport: AppDomainSupport.Denied,
diagnosticMessageSink: new ConsoleDiagnosticMessageSink()))
{
using (var testMessageVisitor = new PerformanceTestMessageVisitor())
using (var testMessageSink = new PerformanceTestMessageSink())
{
controller.Find(
includeSourceInformation: false,
messageSink: testMessageVisitor,
messageSink: testMessageSink,
discoveryOptions: TestFrameworkOptions.ForDiscovery());
testMessageVisitor.Finished.WaitOne();
testMessageSink.Finished.WaitOne();

var testProviders =
from test in testMessageVisitor.Tests
from test in testMessageSink.Tests
from metric in test.Metrics.Cast<PerformanceMetric>()
from provider in metric.ProviderInfo
select provider;
Expand All @@ -38,7 +38,7 @@ from provider in metric.ProviderInfo
userProviders = ProviderInfo.Merge(userProviders.Concat(performanceMetricInfo.ProviderInfo));

// Inject performance metrics into the tests
foreach (var test in testMessageVisitor.Tests)
foreach (var test in testMessageSink.Tests)
{
test.Metrics = collectDefaultMetrics ?
test.Metrics.Union(performanceMetricInfos, new PerformanceMetricInfoComparer()) :
Expand All @@ -47,7 +47,7 @@ from provider in metric.ProviderInfo

return new XUnitPerformanceMetricData {
Providers = ProviderInfo.Merge(testProviders.Concat(userProviders)),
PerformanceTestMessages = testMessageVisitor.Tests,
PerformanceTestMessages = testMessageSink.Tests,
};
}
}
Expand Down
9 changes: 3 additions & 6 deletions src/xunit.performance.api/xunit.performance.api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,18 @@

<PropertyGroup>
<AssemblyTitle>xunit.performance.api</AssemblyTitle>
<TargetFrameworks>netstandard1.6;net461</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' != 'Windows_NT'">netstandard1.6</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net461;netcoreapp2.0</TargetFrameworks>
<Title>xUnit Performance Api</Title>
<RootNamespace>Microsoft.Xunit.Performance.Api</RootNamespace>
<IsPackable>true</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.1.1-beta" />
<PackageReference Include="CommandLineParser.NS20" Version="2.3.1" />
<PackageReference Include="Microsoft.3rdpartytools.MarkdownLog" Version="0.10.0-alpha-experimental" />
<PackageReference Include="Microsoft.Diagnostics.Tracing.TraceEvent" Version="$(MicrosoftDiagnosticsTracingLibraryVersion)">
<IncludeAssets>All</IncludeAssets>
</PackageReference>
<PackageReference Include="System.ValueTuple" Version="4.3.1" />
<PackageReference Include="System.Xml.XmlSerializer" Version="4.3.0" />
<PackageReference Include="System.Diagnostics.Process" Version="4.3.0" />
<PackageReference Include="xunit.runner.utility" Version="$(XunitPackageVersion)" />
</ItemGroup>

Expand Down
3 changes: 2 additions & 1 deletion src/xunit.performance.core/xunit.performance.core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

<PropertyGroup>
<AssemblyTitle>xunit.performance.core</AssemblyTitle>
<TargetFramework>netstandard1.3</TargetFramework>
<TargetFramework>netstandard2.0</TargetFramework>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I think this could stay as netstandard1.3

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

netstandard2.0 pull less dependencies in which results in a cleaner package graph.

<Title>xUnit Performance Core</Title>
<IsPackable>true</IsPackable>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System;
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Reflection;

namespace Microsoft.Xunit.Performance.Execution
{
/// <summary>
///
/// </summary>
internal static class AllocatedBytesForCurrentThread
{
/// <summary>
Expand Down
10 changes: 5 additions & 5 deletions src/xunit.performance.execution/BenchmarkDiscoverer.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Collections.Generic;
using Xunit.Abstractions;
using Xunit.Sdk;
Expand All @@ -10,7 +9,7 @@ namespace Microsoft.Xunit.Performance
{
internal class BenchmarkDiscoverer : TheoryDiscoverer, ITraitDiscoverer
{
private IMessageSink _diagnosticMessageSink;
private readonly IMessageSink _diagnosticMessageSink;

public BenchmarkDiscoverer(IMessageSink diagnosticMessageSink)
: base(diagnosticMessageSink)
Expand All @@ -21,14 +20,15 @@ public BenchmarkDiscoverer(IMessageSink diagnosticMessageSink)
public override IEnumerable<IXunitTestCase> Discover(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo benchmarkAttribute)
{
var defaultMethodDisplay = discoveryOptions.MethodDisplayOrDefault();
var defaultMethodDisplayOptions = discoveryOptions.MethodDisplayOptionsOrDefault();

//
// Special case Skip, because we want a single Skip (not one per data item), and a skipped test may
// not actually have any data (which is quasi-legal, since it's skipped).
//
if (benchmarkAttribute.GetNamedArgument<string>("Skip") != null)
{
yield return new XunitTestCase(_diagnosticMessageSink, defaultMethodDisplay, testMethod);
yield return new XunitTestCase(_diagnosticMessageSink, defaultMethodDisplay, defaultMethodDisplayOptions, testMethod);
yield break;
}

Expand All @@ -45,14 +45,14 @@ public override IEnumerable<IXunitTestCase> Discover(ITestFrameworkDiscoveryOpti
// TheoryDiscoverer returns one of these if it cannot enumerate the cases now.
// We'll return a BenchmarkTestCase with no data associated.
//
yield return new BenchmarkTestCase(_diagnosticMessageSink, defaultMethodDisplay, testMethod, benchmarkAttribute);
yield return new BenchmarkTestCase(_diagnosticMessageSink, defaultMethodDisplay, defaultMethodDisplayOptions, testMethod, benchmarkAttribute);
}
else
{
//
// This is a test case with data
//
yield return new BenchmarkTestCase(_diagnosticMessageSink, defaultMethodDisplay, testMethod, benchmarkAttribute, theoryCase.TestMethodArguments);
yield return new BenchmarkTestCase(_diagnosticMessageSink, defaultMethodDisplay, defaultMethodDisplayOptions, testMethod, benchmarkAttribute, theoryCase.TestMethodArguments);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/xunit.performance.execution/BenchmarkTestCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ internal class BenchmarkTestCase : XunitTestCase
[Obsolete("Called by the de-serializer; should only be called by deriving classes for de-serialization purposes")]
public BenchmarkTestCase() { }

public BenchmarkTestCase(IMessageSink diagnosticMessageSink, TestMethodDisplay defaultMethodDisplay, ITestMethod testMethod, IAttributeInfo attr, object[] testMethodArguments = null)
: base(diagnosticMessageSink, defaultMethodDisplay, testMethod, testMethodArguments)
public BenchmarkTestCase(IMessageSink diagnosticMessageSink, TestMethodDisplay defaultMethodDisplay, TestMethodDisplayOptions defaultMethodDisplayOptions, ITestMethod testMethod, IAttributeInfo attr, object[] testMethodArguments = null)
: base(diagnosticMessageSink, defaultMethodDisplay, defaultMethodDisplayOptions, testMethod, testMethodArguments)
{
DiscoverArguments = testMethodArguments == null;
}
Expand Down
5 changes: 2 additions & 3 deletions src/xunit.performance.execution/BenchmarkTestInvoker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ protected override object CallTestMethod(object testClassInstance)
{
var result = TestMethod.Invoke(testClassInstance, TestMethodArguments);

var task = result as Task;
if (task != null)
if (result is Task task)
{
await task;
success = true;
Expand Down Expand Up @@ -83,7 +82,7 @@ internal sealed class BenchmarkIteratorImpl : BenchmarkIterator
private int _currentIteration;
private bool _currentIterationMeasurementStarted;
private bool _currentIterationMeasurementStopped;
private int _maxIterations;
private readonly int _maxIterations;

internal string IterationStopReason { get; private set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

<PropertyGroup>
<AssemblyTitle>xunit.performance.execution</AssemblyTitle>
<TargetFrameworks>netstandard1.5;net461</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' != 'Windows_NT'">netstandard1.5</TargetFrameworks>
<TargetFramework>netstandard2.0</TargetFramework>
<Title>xUnit Performance Execution</Title>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<IsPackable>true</IsPackable>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

<PropertyGroup>
<AssemblyTitle>xunit.performance.metrics</AssemblyTitle>
<TargetFrameworks>netstandard1.6;net461</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' != 'Windows_NT'">netstandard1.6</TargetFrameworks>
<TargetFramework>netstandard2.0</TargetFramework>
<Title>xUnit Performance Metrics</Title>
<IsPackable>true</IsPackable>
</PropertyGroup>

<ItemGroup>
Expand All @@ -15,7 +15,6 @@

<ItemGroup>
<PackageReference Include="Microsoft.Diagnostics.Tracing.TraceEvent" Version="$(MicrosoftDiagnosticsTracingLibraryVersion)" />
<PackageReference Include="System.Runtime.Serialization.Formatters" Version="4.3.0" />
</ItemGroup>

</Project>
6 changes: 4 additions & 2 deletions tests/scenariobenchmark/Program.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.Xunit.Performance.Api;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;


namespace simpleharness
namespace scenariobenchmark
{
public class Program
{
Expand Down
4 changes: 2 additions & 2 deletions tests/scenariobenchmark/scenariobenchmark.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp1.0;netcoreapp1.1;netcoreapp2.0;net461</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' != 'Windows_NT'">netcoreapp1.0;netcoreapp1.1;netcoreapp2.0</TargetFrameworks>
<TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' != 'Windows_NT'">netcoreapp2.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
5 changes: 4 additions & 1 deletion tests/simpleharness/EmptyBenchmarkTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using Microsoft.Xunit.Performance;
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.Xunit.Performance;

namespace simpleharness
{
Expand Down
3 changes: 3 additions & 0 deletions tests/simpleharness/EndToEndTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.Xunit.Performance;

namespace simpleharness
Expand Down
Loading