Skip to content

Cleanup to skip/flaky attributes #2186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 15, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Data;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Testing.xunit;
using Microsoft.AspNetCore.Testing;
using Microsoft.Data.SqlClient;
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.Configuration;
Expand Down
1 change: 0 additions & 1 deletion src/Configuration/Config.Xml/test/XmlConfigurationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Security.Cryptography.Xml;
using System.Xml;
using Microsoft.AspNetCore.Testing;
using Microsoft.AspNetCore.Testing.xunit;
using Microsoft.Extensions.Configuration.Test;
using Xunit;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Testing;
using Microsoft.AspNetCore.Testing.xunit;
using Microsoft.Extensions.Configuration.Ini;
using Microsoft.Extensions.Configuration.Json;
using Microsoft.Extensions.Configuration.UserSecrets;
Expand Down
2 changes: 1 addition & 1 deletion src/DiagnosticAdapter/test/DiagnosticSourceAdapterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Diagnostics;
using System.Runtime.CompilerServices;

using Microsoft.AspNetCore.Testing.xunit;
using Microsoft.AspNetCore.Testing;
using Xunit;

namespace Microsoft.Extensions.DiagnosticAdapter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Testing;
using Microsoft.AspNetCore.Testing.xunit;
using Microsoft.Extensions.FileProviders.Internal;
using Microsoft.Extensions.FileProviders.Physical;
using Microsoft.Extensions.Primitives;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using Microsoft.AspNetCore.Testing.xunit;
using Microsoft.AspNetCore.Testing;

namespace Microsoft.Extensions.Hosting.IntegrationTesting
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System;
using System.Runtime.InteropServices;
using Microsoft.AspNetCore.Testing.xunit;
using Microsoft.AspNetCore.Testing;

namespace Microsoft.Extensions.Hosting.IntegrationTesting
{
Expand Down
1 change: 0 additions & 1 deletion src/Hosting/test/FunctionalTests/ShutdownTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Testing;
using Microsoft.AspNetCore.Testing.xunit;
using Microsoft.Extensions.Hosting.IntegrationTesting;
using Microsoft.Extensions.Logging.Testing;
using Xunit;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Microsoft.AspNetCore.Testing.xunit;
using Microsoft.AspNetCore.Testing;
using Xunit.Abstractions;
using Xunit.Sdk;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Collections.Generic;
using Microsoft.AspNetCore.Testing.xunit;
using Microsoft.AspNetCore.Testing;
using Xunit.Abstractions;
using Xunit.Sdk;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Testing.xunit;
using Microsoft.AspNetCore.Testing;
using Xunit;
using Xunit.Abstractions;
using Xunit.Sdk;
Expand Down
2 changes: 1 addition & 1 deletion src/Logging/Logging.Testing/src/Xunit/LoggedTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Testing.xunit;
using Microsoft.AspNetCore.Testing;
using Xunit.Abstractions;
using Xunit.Sdk;

Expand Down
2 changes: 1 addition & 1 deletion src/Logging/Logging.Testing/test/LoggedTestXunitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System.Linq;
using System.Reflection;
using Microsoft.AspNetCore.Testing.xunit;
using Microsoft.AspNetCore.Testing;
using Microsoft.Extensions.DependencyInjection;
using Xunit;
using Xunit.Abstractions;
Expand Down
2 changes: 1 addition & 1 deletion src/Logging/test/EventLogLoggerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Microsoft.AspNetCore.Testing.xunit;
using Microsoft.AspNetCore.Testing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging.EventLog;
using Xunit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ public static class TestPlatformHelper
public static bool IsMac =>
RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Xunit;
using Xunit.Sdk;

namespace Microsoft.AspNetCore.Testing.xunit
namespace Microsoft.AspNetCore.Testing
{
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
[XunitTestCaseDiscoverer("Microsoft.AspNetCore.Testing.xunit." + nameof(ConditionalFactDiscoverer), "Microsoft.AspNetCore.Testing")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Xunit.Abstractions;
using Xunit.Sdk;

namespace Microsoft.AspNetCore.Testing.xunit
namespace Microsoft.AspNetCore.Testing
{
internal class ConditionalFactDiscoverer : FactDiscoverer
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Xunit;
using Xunit.Sdk;

namespace Microsoft.AspNetCore.Testing.xunit
namespace Microsoft.AspNetCore.Testing
{
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
[XunitTestCaseDiscoverer("Microsoft.AspNetCore.Testing.xunit." + nameof(ConditionalTheoryDiscoverer), "Microsoft.AspNetCore.Testing")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Xunit.Abstractions;
using Xunit.Sdk;

namespace Microsoft.AspNetCore.Testing.xunit
namespace Microsoft.AspNetCore.Testing
{
internal class ConditionalTheoryDiscoverer : TheoryDiscoverer
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Linq;
using System.Runtime.InteropServices;

namespace Microsoft.AspNetCore.Testing.xunit
namespace Microsoft.AspNetCore.Testing
{
[AttributeUsage(AttributeTargets.Method, Inherited = true, AllowMultiple = false)]
public sealed class DockerOnlyAttribute : Attribute, ITestCondition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System;
using System.Linq;

namespace Microsoft.AspNetCore.Testing.xunit
namespace Microsoft.AspNetCore.Testing
{
/// <summary>
/// Skips a test when the value of an environment variable matches any of the supplied values.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using Xunit.Sdk;

namespace Microsoft.AspNetCore.Testing.xunit
namespace Microsoft.AspNetCore.Testing
{
/// <summary>
/// Marks a test as "Flaky" so that the build will sequester it and ignore failures.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Xunit.Abstractions;
using Xunit.Sdk;

namespace Microsoft.AspNetCore.Testing.xunit
namespace Microsoft.AspNetCore.Testing
{
public class FlakyTestDiscoverer : ITraitDiscoverer
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System;

namespace Microsoft.AspNetCore.Testing.xunit
namespace Microsoft.AspNetCore.Testing
{
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class FrameworkSkipConditionAttribute : Attribute, ITestCondition
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

namespace Microsoft.AspNetCore.Testing.xunit
namespace Microsoft.AspNetCore.Testing
{
internal interface IEnvironmentVariable
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

namespace Microsoft.AspNetCore.Testing.xunit
namespace Microsoft.AspNetCore.Testing
{
public interface ITestCondition
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Runtime.InteropServices;
using Microsoft.Win32;

namespace Microsoft.AspNetCore.Testing.xunit
namespace Microsoft.AspNetCore.Testing
{
/// <summary>
/// Skips a test if the OS is the given type (Windows) and the OS version is less than specified.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Linq;
using System.Runtime.InteropServices;

namespace Microsoft.AspNetCore.Testing.xunit
namespace Microsoft.AspNetCore.Testing
{
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = true)]
public class OSSkipConditionAttribute : Attribute, ITestCondition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System;

namespace Microsoft.AspNetCore.Testing.xunit
namespace Microsoft.AspNetCore.Testing
{
[Flags]
public enum OperatingSystems
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System;

namespace Microsoft.AspNetCore.Testing.xunit
namespace Microsoft.AspNetCore.Testing
{
[Flags]
public enum RuntimeFrameworks
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;

namespace Microsoft.AspNetCore.Testing
{
/// <summary>
/// Skip test if running on CI
/// </summary>
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false)]
public class SkipOnCIAttribute : Attribute, ITestCondition
{
public SkipOnCIAttribute(string issueUrl = "")
{
IssueUrl = issueUrl;
}

public string IssueUrl { get; }

public bool IsMet
{
get
{
return !OnCI();
}
}

public string SkipReason
{
get
{
return $"This test is skipped on CI";
}
}

public static bool OnCI() => OnHelix() || OnAzdo();
public static bool OnHelix() => !string.IsNullOrEmpty(GetTargetHelixQueue());
public static string GetTargetHelixQueue() => Environment.GetEnvironmentVariable("helix");
public static bool OnAzdo() => !string.IsNullOrEmpty(GetIfOnAzdo());
public static string GetIfOnAzdo() => Environment.GetEnvironmentVariable("AGENT_OS");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Linq;

namespace Microsoft.AspNetCore.Testing
{
/// <summary>
/// Skip test if running on helix (or a particular helix queue).
/// </summary>
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false)]
public class SkipOnHelixAttribute : Attribute, ITestCondition
{
public SkipOnHelixAttribute(string issueUrl)
{
if (string.IsNullOrEmpty(issueUrl))
{
throw new ArgumentException();
}
IssueUrl = issueUrl;
}

public string IssueUrl { get; }

public bool IsMet
{
get
{
var skip = OnHelix() && (Queues == null || Queues.ToLowerInvariant().Split(';').Contains(GetTargetHelixQueue().ToLowerInvariant()));
return !skip;
}
}

// Queues that should be skipped on, i.e. "Windows.10.Amd64.ClientRS4.VS2017.Open;OSX.1012.Amd64.Open"
public string Queues { get; set; }

public string SkipReason
{
get
{
return $"This test is skipped on helix";
}
}

public static bool OnHelix() => !string.IsNullOrEmpty(GetTargetHelixQueue());

public static string GetTargetHelixQueue() => Environment.GetEnvironmentVariable("helix");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Xunit.Abstractions;
using Xunit.Sdk;

namespace Microsoft.AspNetCore.Testing.xunit
namespace Microsoft.AspNetCore.Testing
{
public class SkippedTestCase : XunitTestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Xunit.Abstractions;
using Xunit.Sdk;

namespace Microsoft.AspNetCore.Testing.xunit
namespace Microsoft.AspNetCore.Testing
{
public static class TestMethodExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

namespace Microsoft.AspNetCore.Testing.xunit
namespace Microsoft.AspNetCore.Testing
{
public static class WindowsVersions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using Microsoft.AspNetCore.Testing.xunit;
using Microsoft.AspNetCore.Testing;
using Xunit;

namespace Microsoft.AspNetCore.Testing
Expand Down
Loading