Skip to content

Commit

Permalink
Merge pull request #127 from prom-client-net/enable-win-tests
Browse files Browse the repository at this point in the history
enable win tests
  • Loading branch information
phnx47 authored Dec 13, 2024
2 parents 8b36d59 + 99e0f73 commit dc7847c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
18 changes: 18 additions & 0 deletions tests/IntegrationFactAttribute.cs
Original file line number Diff line number Diff line change
@@ -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";
}
}
}
6 changes: 3 additions & 3 deletions tests/MetricPushServerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ public class MetricPushServerTests
public async Task PushContinuesOnError()
{
var pusher = Substitute.For<IMetricPusher>();
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

namespace Prometheus.Client.MetricPusher.Tests;

public class MetricPusherTests(PushGatewayFixture fixture, ITestOutputHelper output) : IClassFixture<PushGatewayFixture>
public class MetricPusherIntegrationTests(PushGatewayFixture fixture, ITestOutputHelper output) : IClassFixture<PushGatewayFixture>
{
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");
Expand All @@ -25,7 +25,7 @@ public async Task PushWithoutException()
Assert.Null(ex);
}

[Fact]
[IntegrationFact]
public async Task PushToWrongUrlWithHttpRequestException()
{
var counter = _metricFactory.CreateCounter("counter2", "help");
Expand All @@ -37,7 +37,7 @@ public async Task PushToWrongUrlWithHttpRequestException()
Assert.IsType<HttpRequestException>(ex);
}

[Fact]
[IntegrationFact]
public async Task PushWithAdditionalHeadersWithoutException()
{
var counter = _metricFactory.CreateCounter("counter3", "help");
Expand All @@ -56,7 +56,7 @@ public async Task PushWithAdditionalHeadersWithoutException()
Assert.Null(ex);
}

[Fact]
[IntegrationFact]
public async Task Worker10StepsWithExpectedResult()
{
var counter = _metricFactory.CreateCounter("worker_counter1", "help");
Expand Down

0 comments on commit dc7847c

Please sign in to comment.