Cleanup to skip/flaky attributes (dotnet/extensions#2186)

\n\nCommit migrated from cfef5e07fb
This commit is contained in:
Justin Kotalik 2019-08-15 09:12:53 -07:00 committed by GitHub
parent 9372816b7c
commit c717230b13
30 changed files with 144 additions and 27 deletions

View File

@ -20,4 +20,4 @@ namespace Microsoft.AspNetCore.Testing
public static bool IsMac =>
RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
}
}
}

View File

@ -5,7 +5,7 @@ using System;
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")]

View File

@ -4,7 +4,7 @@
using Xunit.Abstractions;
using Xunit.Sdk;
namespace Microsoft.AspNetCore.Testing.xunit
namespace Microsoft.AspNetCore.Testing
{
internal class ConditionalFactDiscoverer : FactDiscoverer
{

View File

@ -5,7 +5,7 @@ using System;
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")]

View File

@ -5,7 +5,7 @@ using System.Collections.Generic;
using Xunit.Abstractions;
using Xunit.Sdk;
namespace Microsoft.AspNetCore.Testing.xunit
namespace Microsoft.AspNetCore.Testing
{
internal class ConditionalTheoryDiscoverer : TheoryDiscoverer
{

View File

@ -6,7 +6,7 @@ using System.IO;
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

View File

@ -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.

View File

@ -2,7 +2,7 @@ using System;
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.

View File

@ -4,7 +4,7 @@ using System.Linq;
using Xunit.Abstractions;
using Xunit.Sdk;
namespace Microsoft.AspNetCore.Testing.xunit
namespace Microsoft.AspNetCore.Testing
{
public class FlakyTestDiscoverer : ITraitDiscoverer
{

View File

@ -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

View File

@ -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
{

View File

@ -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
{

View File

@ -5,7 +5,7 @@ using System;
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.

View File

@ -6,7 +6,7 @@ using System.Collections.Generic;
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

View File

@ -3,7 +3,7 @@
using System;
namespace Microsoft.AspNetCore.Testing.xunit
namespace Microsoft.AspNetCore.Testing
{
[Flags]
public enum OperatingSystems

View File

@ -3,7 +3,7 @@
using System;
namespace Microsoft.AspNetCore.Testing.xunit
namespace Microsoft.AspNetCore.Testing
{
[Flags]
public enum RuntimeFrameworks

View File

@ -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");
}
}

View File

@ -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");
}
}

View File

@ -5,7 +5,7 @@ using System;
using Xunit.Abstractions;
using Xunit.Sdk;
namespace Microsoft.AspNetCore.Testing.xunit
namespace Microsoft.AspNetCore.Testing
{
public class SkippedTestCase : XunitTestCase
{

View File

@ -5,7 +5,7 @@ using System.Linq;
using Xunit.Abstractions;
using Xunit.Sdk;
namespace Microsoft.AspNetCore.Testing.xunit
namespace Microsoft.AspNetCore.Testing
{
public static class TestMethodExtensions
{

View File

@ -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
{

View File

@ -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

View File

@ -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;
using Xunit.Abstractions;

View File

@ -3,7 +3,7 @@
using System;
using System.Runtime.InteropServices;
using Microsoft.AspNetCore.Testing.xunit;
using Microsoft.AspNetCore.Testing;
using Xunit;
namespace Microsoft.AspNetCore.Testing

View File

@ -3,7 +3,7 @@
using Xunit;
namespace Microsoft.AspNetCore.Testing.xunit
namespace Microsoft.AspNetCore.Testing
{
public class EnvironmentVariableSkipConditionTest
{

View File

@ -1,4 +1,6 @@
using Microsoft.AspNetCore.Testing.xunit;
// 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.Collections.Generic;
using Xunit;

View File

@ -5,7 +5,7 @@ using System;
using System.Runtime.InteropServices;
using Xunit;
namespace Microsoft.AspNetCore.Testing.xunit
namespace Microsoft.AspNetCore.Testing
{
public class OSSkipConditionAttributeTest
{

View File

@ -5,7 +5,7 @@ using System;
using System.Runtime.InteropServices;
using Xunit;
namespace Microsoft.AspNetCore.Testing.xunit
namespace Microsoft.AspNetCore.Testing
{
public class OSSkipConditionTest
{

View File

@ -0,0 +1,22 @@
// 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 Microsoft.AspNetCore.Testing;
using Xunit;
namespace Microsoft.AspNetCore.Testing.Tests
{
public class SkipOnCITests
{
[ConditionalFact]
[SkipOnCI]
public void AlwaysSkipOnCI()
{
if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("HELIX")) || !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("AGENT_OS")))
{
throw new Exception("Flaky!");
}
}
}
}

View File

@ -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;
namespace Microsoft.AspNetCore.Testing