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 1 commit
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
Prev Previous commit
Next Next commit
test conditionally skip
  • Loading branch information
TimothyMothra committed Jun 6, 2024
commit 831ed1f3d030d275bd1d09304eb5db6f4c00bf05
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,13 @@
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Logging;
using Xunit;
using static Xunit.CustomXunitAttributes;

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

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

[Fact]
[ConditionallySkipOSFact(platformToSkip: "macos", reason: "This test consistently exceeds 1 hour runtime limit when running on MacOS & Net60")]
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}");
}
}
}
}
Loading