From 5cd9514cf27b78cf74f4d784b63246c5477552f2 Mon Sep 17 00:00:00 2001 From: Javad Rahnama Date: Mon, 26 Feb 2024 12:46:16 -0800 Subject: [PATCH] Test | Adjust tests to read IsAzureSynapse value from database (#2367) --- BUILDGUIDE.md | 1 - .../ManualTests/DataCommon/DataTestUtility.cs | 41 +++++++++++++++---- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/BUILDGUIDE.md b/BUILDGUIDE.md index 3b2e79c551..4434af3f1a 100644 --- a/BUILDGUIDE.md +++ b/BUILDGUIDE.md @@ -184,7 +184,6 @@ Manual Tests require the below setup to run: |FileStreamDirectory | (Optional) If File Stream is enabled on SQL Server, pass local directory path to be used for setting up File Stream enabled database. | `D:\\escaped\\absolute\\path\\to\\directory\\` | |UseManagedSNIOnWindows | (Optional) Enables testing with Managed SNI on Windows| `true` OR `false`| |DNSCachingConnString | Connection string for a server that supports DNS Caching| - |IsAzureSynpase | (Optional) When set to 'true', test suite runs compatible tests for Azure Synapse/Parallel Data Warehouse. | `true` OR `false`| |EnclaveAzureDatabaseConnString | (Optional) Connection string for Azure database with enclaves | |ManagedIdentitySupported | (Optional) When set to `false` **Managed Identity** related tests won't run. The default value is `true`. | |IsManagedInstance | (Optional) When set to `true` **TVP** related tests will use on non-Azure bs files to compare test results. this is needed when testing against Managed Instances or TVP Tests will fail on Test set 3. The default value is `false`. | diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs index e167a264a2..5d6f9205b1 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs @@ -51,7 +51,7 @@ public static class DataTestUtility public static readonly bool TracingEnabled = false; public static readonly bool SupportsIntegratedSecurity = false; public static readonly bool UseManagedSNIOnWindows = false; - public static readonly bool IsAzureSynapse = false; + public static Uri AKVBaseUri = null; public static readonly string PowerShellPath = null; public static string FileStreamDirectory = null; @@ -95,13 +95,31 @@ public static class DataTestUtility private static string s_sQLServerVersion = string.Empty; private static bool s_isTDS8Supported; + //SQL Server EngineEdition + private static string s_sqlServerEngineEdition; + + // Azure Synapse EngineEditionId == 6 + // More could be read at https://learn.microsoft.com/en-us/sql/t-sql/functions/serverproperty-transact-sql?view=sql-server-ver16#propertyname + public static bool IsAzureSynapse + { + get + { + if (!string.IsNullOrEmpty(TCPConnectionString)) + { + s_sqlServerEngineEdition ??= GetSqlServerProperty(TCPConnectionString, "EngineEdition"); + } + _ = int.TryParse(s_sqlServerEngineEdition, out int engineEditon); + return engineEditon == 6; + } + } + public static string SQLServerVersion { get { if (!string.IsNullOrEmpty(TCPConnectionString)) { - s_sQLServerVersion ??= GetSqlServerVersion(TCPConnectionString); + s_sQLServerVersion ??= GetSqlServerProperty(TCPConnectionString, "ProductMajorVersion"); } return s_sQLServerVersion; } @@ -143,7 +161,6 @@ static DataTestUtility() DNSCachingConnString = c.DNSCachingConnString; DNSCachingServerCR = c.DNSCachingServerCR; DNSCachingServerTR = c.DNSCachingServerTR; - IsAzureSynapse = c.IsAzureSynapse; IsDNSCachingSupportedCR = c.IsDNSCachingSupportedCR; IsDNSCachingSupportedTR = c.IsDNSCachingSupportedTR; EnclaveAzureDatabaseConnString = c.EnclaveAzureDatabaseConnString; @@ -272,19 +289,27 @@ private static Task AcquireTokenAsync(string authorityURL, string userID public static bool IsKerberosTest => !string.IsNullOrEmpty(KerberosDomainUser) && !string.IsNullOrEmpty(KerberosDomainPassword); - public static string GetSqlServerVersion(string connectionString) + public static string GetSqlServerProperty(string connectionString, string propertyName) { - string version = string.Empty; + string propertyValue = string.Empty; using SqlConnection conn = new(connectionString); conn.Open(); SqlCommand command = conn.CreateCommand(); - command.CommandText = "SELECT SERVERProperty('ProductMajorVersion')"; + command.CommandText = $"SELECT SERVERProperty('{propertyName}')"; SqlDataReader reader = command.ExecuteReader(); if (reader.Read()) { - version = reader.GetString(0); + switch (propertyName) + { + case "EngineEdition": + propertyValue = reader.GetInt32(0).ToString(); + break; + case "ProductMajorVersion": + propertyValue = reader.GetString(0); + break; + } } - return version; + return propertyValue; } public static bool GetSQLServerStatusOnTDS8(string connectionString)