Skip to content
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

[AzureMonitorDistro] Conditionally skip failing tests #44423

Merged
merged 6 commits into from
Jun 6, 2024
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 @@ -23,6 +23,7 @@
<Compile Include="$(AzureCoreSharedSources)AzureEventSource.cs" LinkBase="SharedSource\Azure.Core" />
<Compile Include="..\..\..\Azure.Monitor.OpenTelemetry.Exporter\tests\Azure.Monitor.OpenTelemetry.Exporter.Tests\CommonTestFramework\EventSourceTestHelper.cs" LinkBase="CommonTestFramework" />
<Compile Include="..\..\..\Azure.Monitor.OpenTelemetry.Exporter\tests\Azure.Monitor.OpenTelemetry.Exporter.Tests\CommonTestFramework\TestEventListener.cs" LinkBase="CommonTestFramework" />
<Compile Include="..\..\..\Azure.Monitor.OpenTelemetry.Exporter\tests\Azure.Monitor.OpenTelemetry.Exporter.Tests\CommonTestFramework\CustomXunitAttributes.cs" LinkBase="CommonTestFramework" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Logging;
using Xunit;
using static Xunit.CustomXunitAttributes;

namespace Azure.Monitor.OpenTelemetry.AspNetCore.Tests
{
public class AzureSdkLoggingTests
{
#if NET6_0
[ConditionallySkipOSTheory(platformToSkip: "macos", reason: "This test consistently exceeds 1 hour runtime limit when running on MacOS & Net60")]
#else
[Theory]
#endif
[InlineData(LogLevel.Information, "TestInfoEvent: hello")]
[InlineData(LogLevel.Warning, "TestWarningEvent: hello")]
[InlineData(LogLevel.Debug, null)]
Expand Down Expand Up @@ -49,7 +54,11 @@ public async Task DistroLogForwarderIsAdded(LogLevel eventLevel, string expected
}
}

#if NET6_0
[ConditionallySkipOSTheory(platformToSkip: "macos", reason: "This test consistently exceeds 1 hour runtime limit when running on MacOS & Net60")]
#else
[Theory]
#endif
[InlineData(LogLevel.Information, "TestInfoEvent: hello")]
[InlineData(LogLevel.Warning, "TestWarningEvent: hello")]
[InlineData(LogLevel.Debug, null)]
Expand Down Expand Up @@ -86,7 +95,11 @@ public async Task PublicLogForwarderIsAdded(LogLevel eventLevel, string expected
}
}

#if NET6_0
[ConditionallySkipOSFact(platformToSkip: "macos", reason: "This test consistently exceeds 1 hour runtime limit when running on MacOS & Net60")]
#else
[Fact]
#endif
public async Task SelfDiagnosticsIsDisabled()
{
var enableLevel = LogLevel.Debug;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Runtime.InteropServices;

namespace Xunit
{
public class CustomXunitAttributes
{
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class ConditionallySkipOSFactAttribute : FactAttribute
{
private readonly string _platformToSkip;
private readonly string _reason;

public ConditionallySkipOSFactAttribute(string platformToSkip, string reason)
TimothyMothra marked this conversation as resolved.
Show resolved Hide resolved
{
_platformToSkip = platformToSkip;
_reason = reason;
}

public override string Skip
{
get => IsCurrentOS(_platformToSkip)
? $"Test skipped on {_platformToSkip}. {_reason}"
: base.Skip;
set => base.Skip = value;
}
}

[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class ConditionallySkipOSTheoryAttribute : TheoryAttribute
{
private readonly string _platformToSkip;
private readonly string _reason;

public ConditionallySkipOSTheoryAttribute(string platformToSkip, string reason)
{
_platformToSkip = platformToSkip;
_reason = reason;
}

public override string Skip
{
get
{
return IsCurrentOS(_platformToSkip)
? $"Test skipped on {_platformToSkip}. {_reason}"
: base.Skip;
}
set => base.Skip = value;
}
}

private static bool IsCurrentOS(string osName)
{
switch (osName.ToLowerInvariant())
{
case "windows":
return RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
case "linux":
return RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
case "osx":
case "macos":
return RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
default:
throw new ArgumentException($"Unsupported OS name: {osName}");
}
}
}
}