Skip to content

Commit

Permalink
Tests | Fix issues with Azure Synapse (#1099)
Browse files Browse the repository at this point in the history
  • Loading branch information
cheenamalhotra authored Jun 4, 2021
1 parent 89e15c4 commit 6ba4694
Show file tree
Hide file tree
Showing 8 changed files with 225 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public enum AsyncAPI
ExecuteXmlReaderAsync
}

[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))]
// Synapse: WAITFOR DELAY not supported [Parse error at line: 1, column: 1: Incorrect syntax near 'WAITFOR'.]
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureSynapse))]
[ClassData(typeof(AsyncTimeoutTestVariations))]
public static void TestDelayedAsyncTimeout(AsyncAPI api, string commonObj, int delayPeriod, bool marsEnabled) =>
RunTest(api, commonObj, delayPeriod, marsEnabled);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public static void CheckSparseColumnBit()
}

// Synapse: Statement 'Drop Database' is not supported in this version of SQL Server.
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureServer))]
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureServer), nameof(DataTestUtility.IsNotAzureSynapse))]
public static void CollatedDataReaderTest()
{
var databaseName = DataTestUtility.GetUniqueName("DB");
Expand Down Expand Up @@ -293,7 +293,7 @@ first_name varchar(100) null,
Assert.Contains("user_id", names, StringComparer.Ordinal);
}

[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))]
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureSynapse))]
public static void CheckNullRowVersionIsBDNull()
{
lock (s_rowVersionLock)
Expand Down Expand Up @@ -323,7 +323,8 @@ public static void CheckNullRowVersionIsBDNull()
}
}

[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))]
// Synapse: Cannot find data type 'rowversion'.
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureSynapse))]
public static void CheckLegacyNullRowVersionIsEmptyArray()
{
lock (s_rowVersionLock)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
namespace Microsoft.Data.SqlClient.ManualTesting.Tests
{
/// <summary>
/// Defines a collection of types to be used by the test. Tests can start with CreateSql2005Collection or
/// Defines a collection of types to be used by the test. Tests start with
/// CreateSql2008Collection and add/remove types, as needed.
/// </summary>
public sealed class SqlRandomTypeInfoCollection : System.Collections.ObjectModel.KeyedCollection<SqlDbType, SqlRandomTypeInfo>
{
private static readonly SqlRandomTypeInfo[] s_sql2005Types =
private static readonly SqlRandomTypeInfo[] s_sql2008Types =
{
// var types
new SqlVarBinaryTypeInfo(),
Expand Down Expand Up @@ -67,11 +67,62 @@ public sealed class SqlRandomTypeInfoCollection : System.Collections.ObjectModel

// xml
new SqlXmlTypeInfo(),

// date/time types
new SqlDateTypeInfo(),
new SqlDateTime2TypeInfo(),
new SqlDateTimeOffsetTypeInfo(),
new SqlTimeTypeInfo(),
};

// types added in SQL 2008
private static readonly SqlRandomTypeInfo[] s_newInSql2008Types =
private static readonly SqlRandomTypeInfo[] s_sqlSynapseTypes =
{
// var types
new SqlVarBinaryTypeInfo(),
new SqlVarCharTypeInfo(),
new SqlNVarCharTypeInfo(),

// integer data types
new SqlBigIntTypeInfo(),
new SqlIntTypeInfo(),
new SqlSmallIntTypeInfo(),
new SqlTinyIntTypeInfo(),

// fixed length blobs
new SqlCharTypeInfo(),
new SqlNCharTypeInfo(),
new SqlBinaryTypeInfo(),

// large blobs
new SqlImageTypeInfo(),

// bit
new SqlBitTypeInfo(),

// decimal
new SqlDecimalTypeInfo(),

// money types
new SqlMoneyTypeInfo(),
new SqlSmallMoneyTypeInfo(),

// float types
new SqRealTypeInfo(),
new SqFloatTypeInfo(),

// typestamp (== rowversion)
new SqlRowVersionTypeInfo(),

// unique identifier (== guid)
new SqlUniqueIdentifierTypeInfo(),

// date/time types
new SqlDateTimeTypeInfo(),
new SqlSmallDateTimeTypeInfo(),

// variant
new SqlVariantTypeInfo(),

// date/time types
new SqlDateTypeInfo(),
new SqlDateTime2TypeInfo(),
Expand Down Expand Up @@ -152,19 +203,11 @@ public void AddRange(SqlRandomTypeInfo[] types)
}

/// <summary>
/// creates a collection of types supported in SQL 2005
/// </summary>
public static SqlRandomTypeInfoCollection CreateSql2005Collection()
{
return new SqlRandomTypeInfoCollection(s_sql2005Types);
}

/// <summary>
/// creates a collection of types supported in SQL 2005 and 2008
/// creates a collection of types supported in SQL 2008+
/// </summary>
public static SqlRandomTypeInfoCollection CreateSql2008Collection()
{
return new SqlRandomTypeInfoCollection(s_sql2005Types, s_newInSql2008Types);
return DataTestUtility.IsNotAzureSynapse() ? new SqlRandomTypeInfoCollection(s_sql2008Types) : new SqlRandomTypeInfoCollection(s_sqlSynapseTypes);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,49 @@ internal sealed class SqlVariantTypeInfo : SqlRandomTypeInfo
new SqlSmallDateTimeTypeInfo(),
};

private static readonly SqlRandomTypeInfo[] s_variantSubTypesSynapse =
{
// var types
new SqlVarBinaryTypeInfo(),
new SqlVarCharTypeInfo(),
new SqlNVarCharTypeInfo(),

// integer data types
new SqlBigIntTypeInfo(),
new SqlIntTypeInfo(),
new SqlSmallIntTypeInfo(),
new SqlTinyIntTypeInfo(),

// fixed length blobs
new SqlCharTypeInfo(),
new SqlNCharTypeInfo(),
new SqlBinaryTypeInfo(),

// large blobs
new SqlImageTypeInfo(),

// bit
new SqlBitTypeInfo(),

// decimal
new SqlDecimalTypeInfo(),

// money types
new SqlMoneyTypeInfo(),
new SqlSmallMoneyTypeInfo(),

// float types
new SqRealTypeInfo(),
new SqFloatTypeInfo(),

// unique identifier (== guid)
new SqlUniqueIdentifierTypeInfo(),

// date/time types
new SqlDateTimeTypeInfo(),
new SqlSmallDateTimeTypeInfo(),
};

public SqlVariantTypeInfo()
: base(SqlDbType.Variant)
{
Expand All @@ -1338,7 +1381,8 @@ private static bool IsUnicodeType(SqlDbType t)

protected override object CreateRandomValueInternal(SqlRandomizer rand, SqlRandomTableColumn columnInfo)
{
SqlRandomTypeInfo subType = s_variantSubTypes[rand.NextIntInclusive(0, maxValueInclusive: s_variantSubTypes.Length - 1)];
SqlRandomTypeInfo subType = DataTestUtility.IsNotAzureSynapse() ? s_variantSubTypes[rand.NextIntInclusive(0, maxValueInclusive: s_variantSubTypes.Length - 1)] : s_variantSubTypesSynapse[rand.NextIntInclusive(0, maxValueInclusive: s_variantSubTypesSynapse.Length - 1)];

object val = subType.CreateRandomValue(rand, new SqlRandomTableColumn(subType, SqlRandomColumnOptions.None, 8000));
char[] cval = val as char[];
if (cval != null)
Expand Down
Loading

0 comments on commit 6ba4694

Please sign in to comment.