Skip to content

Commit

Permalink
Test | Adjust tests to read IsAzureSynapse value from database (#2367)
Browse files Browse the repository at this point in the history
  • Loading branch information
Javad Rahnama authored Feb 26, 2024
1 parent 5a98166 commit 5cd9514
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
1 change: 0 additions & 1 deletion BUILDGUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -272,19 +289,27 @@ private static Task<string> 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)
Expand Down

0 comments on commit 5cd9514

Please sign in to comment.