diff --git a/tests/MySqlConnector.Tests/Metrics/ConnectionTimeTests.cs b/tests/MySqlConnector.Tests/Metrics/ConnectionTimeTests.cs index 1a250442e..98156fe21 100644 --- a/tests/MySqlConnector.Tests/Metrics/ConnectionTimeTests.cs +++ b/tests/MySqlConnector.Tests/Metrics/ConnectionTimeTests.cs @@ -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(); @@ -15,7 +14,7 @@ public async Task ConnectionTime() Assert.InRange(time, 0, 300); } - [Fact] + [Fact(Skip = MetricsSkip)] public async Task ConnectionTimeWithDelay() { var csb = CreateConnectionStringBuilder(); @@ -29,7 +28,7 @@ public async Task ConnectionTimeWithDelay() Assert.InRange(time, 1000, 1300); } - [Fact] + [Fact(Skip = MetricsSkip)] public async Task OpenFromPoolTime() { var csb = CreateConnectionStringBuilder(); @@ -45,7 +44,7 @@ public async Task OpenFromPoolTime() Assert.InRange(time, 0, 200); } - [Fact] + [Fact(Skip = MetricsSkip)] public async Task OpenFromPoolTimeWithDelay() { var csb = CreateConnectionStringBuilder(); @@ -62,7 +61,7 @@ public async Task OpenFromPoolTimeWithDelay() Assert.InRange(time, 1000, 1200); } - [Fact] + [Fact(Skip = MetricsSkip)] public async Task UseTime() { var csb = CreateConnectionStringBuilder(); @@ -76,7 +75,7 @@ public async Task UseTime() Assert.InRange(time, 0, 100); } - [Fact] + [Fact(Skip = MetricsSkip)] public async Task UseTimeWithDelay() { var csb = CreateConnectionStringBuilder(); @@ -91,4 +90,3 @@ public async Task UseTimeWithDelay() Assert.InRange(time, 500, 600); } } -#endif diff --git a/tests/MySqlConnector.Tests/Metrics/ConnectionsUsageTests.cs b/tests/MySqlConnector.Tests/Metrics/ConnectionsUsageTests.cs index 258c15858..09e9440e8 100644 --- a/tests/MySqlConnector.Tests/Metrics/ConnectionsUsageTests.cs +++ b/tests/MySqlConnector.Tests/Metrics/ConnectionsUsageTests.cs @@ -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"; @@ -59,7 +58,7 @@ public void NamedDataSource() Assert.Equal(2, Server.ActiveConnections); } - [Fact] + [Fact(Skip = MetricsSkip)] public void NamedDataSourceWithMinPoolSize() { var csb = CreateConnectionStringBuilder(); @@ -92,7 +91,7 @@ public void NamedDataSourceWithMinPoolSize() Assert.Equal(3, Server.ActiveConnections); } - [Fact] + [Fact(Skip = MetricsSkip)] public void UnnamedDataSource() { var csb = CreateConnectionStringBuilder(); @@ -149,7 +148,7 @@ public void UnnamedDataSource() Assert.Equal(2, Server.ActiveConnections); } - [Fact] + [Fact(Skip = MetricsSkip)] public void NoDataSource() { var csb = CreateConnectionStringBuilder(); @@ -207,7 +206,7 @@ public void NoDataSource() Assert.Equal(2, Server.ActiveConnections); } - [Fact] + [Fact(Skip = MetricsSkip)] public async Task PendingRequestForCreation() { var csb = CreateConnectionStringBuilder(); @@ -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(); @@ -244,4 +243,3 @@ public async Task PendingRequestForOpenFromPool() AssertMeasurement("db.client.connections.pending_requests", 0); } } -#endif diff --git a/tests/MySqlConnector.Tests/Metrics/MetricsTestsBase.cs b/tests/MySqlConnector.Tests/Metrics/MetricsTestsBase.cs index 7e4291124..6751b7477 100644 --- a/tests/MySqlConnector.Tests/Metrics/MetricsTestsBase.cs +++ b/tests/MySqlConnector.Tests/Metrics/MetricsTestsBase.cs @@ -76,6 +76,12 @@ protected List 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> tags, object? state) { var (poolName, stateTag) = GetTags(tags); diff --git a/tests/MySqlConnector.Tests/Metrics/MinMaxConnectionsTests.cs b/tests/MySqlConnector.Tests/Metrics/MinMaxConnectionsTests.cs index 246b06305..a5a4e658a 100644 --- a/tests/MySqlConnector.Tests/Metrics/MinMaxConnectionsTests.cs +++ b/tests/MySqlConnector.Tests/Metrics/MinMaxConnectionsTests.cs @@ -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(); @@ -19,7 +18,7 @@ public void SetsMinimumIdleToDefault() AssertMeasurement("db.client.connections.idle.min", 0); } - [Fact] + [Fact(Skip = MetricsSkip)] public void SetsMaximumIdleToDefault() { var csb = CreateConnectionStringBuilder(); @@ -33,7 +32,7 @@ public void SetsMaximumIdleToDefault() AssertMeasurement("db.client.connections.idle.max", 100); } - [Fact] + [Fact(Skip = MetricsSkip)] public void SetsMaximumToDefault() { var csb = CreateConnectionStringBuilder(); @@ -47,7 +46,7 @@ public void SetsMaximumToDefault() AssertMeasurement("db.client.connections.max", 100); } - [Fact] + [Fact(Skip = MetricsSkip)] public void SetsMinimumIdleToCustom() { var csb = CreateConnectionStringBuilder(); @@ -66,7 +65,7 @@ public void SetsMinimumIdleToCustom() AssertMeasurement("db.client.connections.idle.min", 0); } - [Fact] + [Fact(Skip = MetricsSkip)] public void SetsMaximumIdleToCustom() { var csb = CreateConnectionStringBuilder(); @@ -85,7 +84,7 @@ public void SetsMaximumIdleToCustom() AssertMeasurement("db.client.connections.idle.max", 0); } - [Fact] + [Fact(Skip = MetricsSkip)] public void SetsMaximumToCustom() { var csb = CreateConnectionStringBuilder(); @@ -104,4 +103,3 @@ public void SetsMaximumToCustom() AssertMeasurement("db.client.connections.max", 0); } } -#endif diff --git a/tests/MySqlConnector.Tests/MySqlConnector.Tests.csproj b/tests/MySqlConnector.Tests/MySqlConnector.Tests.csproj index c8c37e604..6e91e5916 100644 --- a/tests/MySqlConnector.Tests/MySqlConnector.Tests.csproj +++ b/tests/MySqlConnector.Tests/MySqlConnector.Tests.csproj @@ -18,6 +18,10 @@ 11.0 + + NO_METRICS_TESTS + +