Skip to content

Commit 5cd9514

Browse files
author
Javad Rahnama
authored
Test | Adjust tests to read IsAzureSynapse value from database (#2367)
1 parent 5a98166 commit 5cd9514

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

BUILDGUIDE.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ Manual Tests require the below setup to run:
184184
|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\\` |
185185
|UseManagedSNIOnWindows | (Optional) Enables testing with Managed SNI on Windows| `true` OR `false`|
186186
|DNSCachingConnString | Connection string for a server that supports DNS Caching|
187-
|IsAzureSynpase | (Optional) When set to 'true', test suite runs compatible tests for Azure Synapse/Parallel Data Warehouse. | `true` OR `false`|
188187
|EnclaveAzureDatabaseConnString | (Optional) Connection string for Azure database with enclaves |
189188
|ManagedIdentitySupported | (Optional) When set to `false` **Managed Identity** related tests won't run. The default value is `true`. |
190189
|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`. |

src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public static class DataTestUtility
5151
public static readonly bool TracingEnabled = false;
5252
public static readonly bool SupportsIntegratedSecurity = false;
5353
public static readonly bool UseManagedSNIOnWindows = false;
54-
public static readonly bool IsAzureSynapse = false;
54+
5555
public static Uri AKVBaseUri = null;
5656
public static readonly string PowerShellPath = null;
5757
public static string FileStreamDirectory = null;
@@ -95,13 +95,31 @@ public static class DataTestUtility
9595
private static string s_sQLServerVersion = string.Empty;
9696
private static bool s_isTDS8Supported;
9797

98+
//SQL Server EngineEdition
99+
private static string s_sqlServerEngineEdition;
100+
101+
// Azure Synapse EngineEditionId == 6
102+
// More could be read at https://learn.microsoft.com/en-us/sql/t-sql/functions/serverproperty-transact-sql?view=sql-server-ver16#propertyname
103+
public static bool IsAzureSynapse
104+
{
105+
get
106+
{
107+
if (!string.IsNullOrEmpty(TCPConnectionString))
108+
{
109+
s_sqlServerEngineEdition ??= GetSqlServerProperty(TCPConnectionString, "EngineEdition");
110+
}
111+
_ = int.TryParse(s_sqlServerEngineEdition, out int engineEditon);
112+
return engineEditon == 6;
113+
}
114+
}
115+
98116
public static string SQLServerVersion
99117
{
100118
get
101119
{
102120
if (!string.IsNullOrEmpty(TCPConnectionString))
103121
{
104-
s_sQLServerVersion ??= GetSqlServerVersion(TCPConnectionString);
122+
s_sQLServerVersion ??= GetSqlServerProperty(TCPConnectionString, "ProductMajorVersion");
105123
}
106124
return s_sQLServerVersion;
107125
}
@@ -143,7 +161,6 @@ static DataTestUtility()
143161
DNSCachingConnString = c.DNSCachingConnString;
144162
DNSCachingServerCR = c.DNSCachingServerCR;
145163
DNSCachingServerTR = c.DNSCachingServerTR;
146-
IsAzureSynapse = c.IsAzureSynapse;
147164
IsDNSCachingSupportedCR = c.IsDNSCachingSupportedCR;
148165
IsDNSCachingSupportedTR = c.IsDNSCachingSupportedTR;
149166
EnclaveAzureDatabaseConnString = c.EnclaveAzureDatabaseConnString;
@@ -272,19 +289,27 @@ private static Task<string> AcquireTokenAsync(string authorityURL, string userID
272289

273290
public static bool IsKerberosTest => !string.IsNullOrEmpty(KerberosDomainUser) && !string.IsNullOrEmpty(KerberosDomainPassword);
274291

275-
public static string GetSqlServerVersion(string connectionString)
292+
public static string GetSqlServerProperty(string connectionString, string propertyName)
276293
{
277-
string version = string.Empty;
294+
string propertyValue = string.Empty;
278295
using SqlConnection conn = new(connectionString);
279296
conn.Open();
280297
SqlCommand command = conn.CreateCommand();
281-
command.CommandText = "SELECT SERVERProperty('ProductMajorVersion')";
298+
command.CommandText = $"SELECT SERVERProperty('{propertyName}')";
282299
SqlDataReader reader = command.ExecuteReader();
283300
if (reader.Read())
284301
{
285-
version = reader.GetString(0);
302+
switch (propertyName)
303+
{
304+
case "EngineEdition":
305+
propertyValue = reader.GetInt32(0).ToString();
306+
break;
307+
case "ProductMajorVersion":
308+
propertyValue = reader.GetString(0);
309+
break;
310+
}
286311
}
287-
return version;
312+
return propertyValue;
288313
}
289314

290315
public static bool GetSQLServerStatusOnTDS8(string connectionString)

0 commit comments

Comments
 (0)