diff --git a/tests/IntegrationFactAttribute.cs b/tests/IntegrationFactAttribute.cs new file mode 100644 index 0000000..d73e09f --- /dev/null +++ b/tests/IntegrationFactAttribute.cs @@ -0,0 +1,18 @@ +using System; +using System.Runtime.InteropServices; +using Xunit; + +namespace Prometheus.Client.MetricPusher.Tests; + +public sealed class IntegrationFactAttribute : FactAttribute +{ + public IntegrationFactAttribute() + { + bool.TryParse(Environment.GetEnvironmentVariable("GITHUB_ACTIONS"), out var isGitHubActions); + + if (isGitHubActions && RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + Skip = "Integration test skipped due to environment conditions"; + } + } +} diff --git a/tests/MetricPushServerTests.cs b/tests/MetricPushServerTests.cs index 7e813bb..030920d 100644 --- a/tests/MetricPushServerTests.cs +++ b/tests/MetricPushServerTests.cs @@ -11,11 +11,11 @@ public class MetricPushServerTests public async Task PushContinuesOnError() { var pusher = Substitute.For(); - pusher.PushAsync().Returns(Task.FromException(new Exception("Push error"))); + pusher.PushAsync().Returns(Task.FromException(new Exception("Simulated Push Error"))); - var worker = new MetricPushServer(pusher, TimeSpan.FromSeconds(0.05)); + var worker = new MetricPushServer(pusher); worker.Start(); - await Task.Delay(150); + await Task.Delay(2500); await pusher.Received(3).PushAsync(); worker.Stop(); diff --git a/tests/MetricPusherTests.cs b/tests/MetricPusherIntegrationTests.cs similarity index 94% rename from tests/MetricPusherTests.cs rename to tests/MetricPusherIntegrationTests.cs index 701f609..ca6f79a 100644 --- a/tests/MetricPusherTests.cs +++ b/tests/MetricPusherIntegrationTests.cs @@ -8,12 +8,12 @@ namespace Prometheus.Client.MetricPusher.Tests; -public class MetricPusherTests(PushGatewayFixture fixture, ITestOutputHelper output) : IClassFixture +public class MetricPusherIntegrationTests(PushGatewayFixture fixture, ITestOutputHelper output) : IClassFixture { private readonly string _endpoint = fixture.GetEndpoint(); private readonly IMetricFactory _metricFactory = new MetricFactory(new CollectorRegistry()); - [Fact] + [IntegrationFact] public async Task PushWithoutException() { var counter = _metricFactory.CreateCounter("counter1", "help"); @@ -25,7 +25,7 @@ public async Task PushWithoutException() Assert.Null(ex); } - [Fact] + [IntegrationFact] public async Task PushToWrongUrlWithHttpRequestException() { var counter = _metricFactory.CreateCounter("counter2", "help"); @@ -37,7 +37,7 @@ public async Task PushToWrongUrlWithHttpRequestException() Assert.IsType(ex); } - [Fact] + [IntegrationFact] public async Task PushWithAdditionalHeadersWithoutException() { var counter = _metricFactory.CreateCounter("counter3", "help"); @@ -56,7 +56,7 @@ public async Task PushWithAdditionalHeadersWithoutException() Assert.Null(ex); } - [Fact] + [IntegrationFact] public async Task Worker10StepsWithExpectedResult() { var counter = _metricFactory.CreateCounter("worker_counter1", "help");