Skip to content

Commit

Permalink
Improve metrics test skipping for CI.
Browse files Browse the repository at this point in the history
Signed-off-by: Bradley Grainger <[email protected]>
  • Loading branch information
bgrainger committed Oct 29, 2023
1 parent 2a058ea commit 93b8208
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 24 deletions.
14 changes: 6 additions & 8 deletions tests/MySqlConnector.Tests/Metrics/ConnectionTimeTests.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#if METRICS_TESTS
namespace MySqlConnector.Tests.Metrics;

public class ConnectionTimeTests : MetricsTestsBase
{
[Fact]
[Fact(Skip = MetricsSkip)]
public async Task ConnectionTime()
{
var csb = CreateConnectionStringBuilder();
Expand All @@ -15,7 +14,7 @@ public async Task ConnectionTime()
Assert.InRange(time, 0, 300);
}

[Fact]
[Fact(Skip = MetricsSkip)]
public async Task ConnectionTimeWithDelay()
{
var csb = CreateConnectionStringBuilder();
Expand All @@ -29,7 +28,7 @@ public async Task ConnectionTimeWithDelay()
Assert.InRange(time, 1000, 1300);
}

[Fact]
[Fact(Skip = MetricsSkip)]
public async Task OpenFromPoolTime()
{
var csb = CreateConnectionStringBuilder();
Expand All @@ -45,7 +44,7 @@ public async Task OpenFromPoolTime()
Assert.InRange(time, 0, 200);
}

[Fact]
[Fact(Skip = MetricsSkip)]
public async Task OpenFromPoolTimeWithDelay()
{
var csb = CreateConnectionStringBuilder();
Expand All @@ -62,7 +61,7 @@ public async Task OpenFromPoolTimeWithDelay()
Assert.InRange(time, 1000, 1200);
}

[Fact]
[Fact(Skip = MetricsSkip)]
public async Task UseTime()
{
var csb = CreateConnectionStringBuilder();
Expand All @@ -76,7 +75,7 @@ public async Task UseTime()
Assert.InRange(time, 0, 100);
}

[Fact]
[Fact(Skip = MetricsSkip)]
public async Task UseTimeWithDelay()
{
var csb = CreateConnectionStringBuilder();
Expand All @@ -91,4 +90,3 @@ public async Task UseTimeWithDelay()
Assert.InRange(time, 500, 600);
}
}
#endif
14 changes: 6 additions & 8 deletions tests/MySqlConnector.Tests/Metrics/ConnectionsUsageTests.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#if METRICS_TESTS
#nullable enable

namespace MySqlConnector.Tests.Metrics;

public class ConnectionsUsageTests : MetricsTestsBase
{
[Fact]
[Fact(Skip = MetricsSkip)]
public void NamedDataSource()
{
PoolName = "metrics-test";
Expand Down Expand Up @@ -59,7 +58,7 @@ public void NamedDataSource()
Assert.Equal(2, Server.ActiveConnections);
}

[Fact]
[Fact(Skip = MetricsSkip)]
public void NamedDataSourceWithMinPoolSize()
{
var csb = CreateConnectionStringBuilder();
Expand Down Expand Up @@ -92,7 +91,7 @@ public void NamedDataSourceWithMinPoolSize()
Assert.Equal(3, Server.ActiveConnections);
}

[Fact]
[Fact(Skip = MetricsSkip)]
public void UnnamedDataSource()
{
var csb = CreateConnectionStringBuilder();
Expand Down Expand Up @@ -149,7 +148,7 @@ public void UnnamedDataSource()
Assert.Equal(2, Server.ActiveConnections);
}

[Fact]
[Fact(Skip = MetricsSkip)]
public void NoDataSource()
{
var csb = CreateConnectionStringBuilder();
Expand Down Expand Up @@ -207,7 +206,7 @@ public void NoDataSource()
Assert.Equal(2, Server.ActiveConnections);
}

[Fact]
[Fact(Skip = MetricsSkip)]
public async Task PendingRequestForCreation()
{
var csb = CreateConnectionStringBuilder();
Expand All @@ -224,7 +223,7 @@ public async Task PendingRequestForCreation()
AssertMeasurement("db.client.connections.pending_requests", 0);
}

[Fact]
[Fact(Skip = MetricsSkip)]
public async Task PendingRequestForOpenFromPool()
{
var csb = CreateConnectionStringBuilder();
Expand All @@ -244,4 +243,3 @@ public async Task PendingRequestForOpenFromPool()
AssertMeasurement("db.client.connections.pending_requests", 0);
}
}
#endif
6 changes: 6 additions & 0 deletions tests/MySqlConnector.Tests/Metrics/MetricsTestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ protected List<float> GetAndClearMeasurements(string name)
return list;
}

#if NO_METRICS_TESTS
protected const string MetricsSkip = "Metrics tests are skipped";
#else
protected const string MetricsSkip = null;
#endif

private void OnMeasurementRecorded(Instrument instrument, int measurement, ReadOnlySpan<KeyValuePair<string, object?>> tags, object? state)
{
var (poolName, stateTag) = GetTags(tags);
Expand Down
14 changes: 6 additions & 8 deletions tests/MySqlConnector.Tests/Metrics/MinMaxConnectionsTests.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#if METRICS_TESTS
#nullable enable

namespace MySqlConnector.Tests.Metrics;

public class MinMaxConnectionsTests : MetricsTestsBase
{
[Fact]
[Fact(Skip = MetricsSkip)]
public void SetsMinimumIdleToDefault()
{
var csb = CreateConnectionStringBuilder();
Expand All @@ -19,7 +18,7 @@ public void SetsMinimumIdleToDefault()
AssertMeasurement("db.client.connections.idle.min", 0);
}

[Fact]
[Fact(Skip = MetricsSkip)]
public void SetsMaximumIdleToDefault()
{
var csb = CreateConnectionStringBuilder();
Expand All @@ -33,7 +32,7 @@ public void SetsMaximumIdleToDefault()
AssertMeasurement("db.client.connections.idle.max", 100);
}

[Fact]
[Fact(Skip = MetricsSkip)]
public void SetsMaximumToDefault()
{
var csb = CreateConnectionStringBuilder();
Expand All @@ -47,7 +46,7 @@ public void SetsMaximumToDefault()
AssertMeasurement("db.client.connections.max", 100);
}

[Fact]
[Fact(Skip = MetricsSkip)]
public void SetsMinimumIdleToCustom()
{
var csb = CreateConnectionStringBuilder();
Expand All @@ -66,7 +65,7 @@ public void SetsMinimumIdleToCustom()
AssertMeasurement("db.client.connections.idle.min", 0);
}

[Fact]
[Fact(Skip = MetricsSkip)]
public void SetsMaximumIdleToCustom()
{
var csb = CreateConnectionStringBuilder();
Expand All @@ -85,7 +84,7 @@ public void SetsMaximumIdleToCustom()
AssertMeasurement("db.client.connections.idle.max", 0);
}

[Fact]
[Fact(Skip = MetricsSkip)]
public void SetsMaximumToCustom()
{
var csb = CreateConnectionStringBuilder();
Expand All @@ -104,4 +103,3 @@ public void SetsMaximumToCustom()
AssertMeasurement("db.client.connections.max", 0);
}
}
#endif
4 changes: 4 additions & 0 deletions tests/MySqlConnector.Tests/MySqlConnector.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
<LangVersion>11.0</LangVersion>
</PropertyGroup>

<PropertyGroup Condition=" '$(GITHUB_ACTIONS)' == 'true' OR '$(APPVEYOR)' == 'True' OR '$(TF_BUILD)' == 'True' ">
<DefineConstants>NO_METRICS_TESTS</DefineConstants>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio">
Expand Down

0 comments on commit 93b8208

Please sign in to comment.