Skip to content
Closed
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
62 changes: 62 additions & 0 deletions src/Testing/src/xunit/HelixQueues.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Linq;

namespace Microsoft.AspNetCore.Testing;

[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = true)]
public class HelixQueues : Attribute, ITestCondition
{
public HelixQueues()
{
}

public string Includes { get; set; }
public string Excludes { get; set; }

public bool IsMet
{
get
{
return HelixHelper.OnHelix() && IsQueueMatch(Includes) && !IsQueueMatch(Excludes);
}
}

public string SkipReason => "Queue is filtered by Includes/Excludes.";

private bool IsQueueMatch(string queues)
{
if (string.IsNullOrEmpty(queues))
{
return false;
}

if (queues == "*")
{
return true;
}

var targetQueue = HelixHelper.GetTargetHelixQueue();

if (queues.Contains("All.Windows") && targetQueue.StartsWith("windows", StringComparison.OrdinalIgnoreCase))
{
return true;
}

if (queues.Contains("All.OSX") && targetQueue.StartsWith("osx", StringComparison.OrdinalIgnoreCase))
{
return true;
}

if (queues.Contains("All.Ubuntu") && targetQueue.StartsWith("ubuntu", StringComparison.OrdinalIgnoreCase))
{
return true;
}

return queues.ToLowerInvariant().Split(';').Contains(targetQueue);
}

public static bool OnHelix() => HelixHelper.OnHelix();
}
5 changes: 5 additions & 0 deletions src/Testing/src/xunit/SkipOnHelixAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ private bool ShouldSkip()

var targetQueue = GetTargetHelixQueue().ToLowerInvariant();

if (Queues.Contains("All.Windows") && targetQueue.StartsWith("windows", StringComparison.OrdinalIgnoreCase))
{
return true;
}

if (Queues.Contains("All.OSX") && targetQueue.StartsWith("osx", StringComparison.OrdinalIgnoreCase))
{
return true;
Expand Down
47 changes: 47 additions & 0 deletions src/Testing/test/HelixQueuesTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

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

namespace Microsoft.AspNetCore.Testing.Tests;

public class HelixQueuesTests
{
[ConditionalFact]
[HelixQueues(Includes = "*", Excludes = "All.Windows")] // Run everywhere except for Windows.
public void Test_Should_Be_Skipped_On_Windows()
{
var queue = HelixHelper.GetTargetHelixQueue();

if (queue.StartsWith("windows", StringComparison.OrdinalIgnoreCase))
{
throw new InvalidOperationException("This test should not run on Windows!");
}
}

[ConditionalFact]
[HelixQueues(Includes = "*", Excludes = "All.OSX")]
public void Test_Should_Be_Skipped_On_OSX()
{
var queue = HelixHelper.GetTargetHelixQueue();

if (queue.StartsWith("osx", StringComparison.OrdinalIgnoreCase))
{
throw new InvalidOperationException("This test should not run on OSX!");
}
}

[ConditionalFact]
[HelixQueues(Includes = "*", Excludes = "All.Ubuntu")]
public void Test_Should_Be_Skipped_On_Ubuntu()
{
var queue = HelixHelper.GetTargetHelixQueue();

if (queue.StartsWith("ubuntu", StringComparison.OrdinalIgnoreCase))
{
throw new InvalidOperationException("This test should not run on Ubuntu!");
}
}
}