Skip to content

Commit

Permalink
Merge pull request dotnet/corefx#34546 from Wraith2/sqltests-updates
Browse files Browse the repository at this point in the history
SqlClient Manual Test fixes and documentation update

Commit migrated from dotnet/corefx@f749fca
  • Loading branch information
AfsanehR-zz authored Feb 13, 2019
2 parents ce44605 + 8c629f6 commit 360f43f
Show file tree
Hide file tree
Showing 10 changed files with 248 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,33 @@ public static bool IsDatabasePresent(string name)

public static bool IsUsingManagedSNI() => (bool)(s_useManagedSNI?.GetValue(null) ?? false);

public static bool IsUsingNativeSNI() => !IsUsingManagedSNI();

public static bool IsUTF8Supported()
{
bool retval = false;
if (AreConnStringsSetup())
{
using (SqlConnection connection = new SqlConnection(DataTestUtility.TcpConnStr))
using (SqlCommand command = new SqlCommand())
{
command.Connection = connection;
command.CommandText = "SELECT CONNECTIONPROPERTY('SUPPORT_UTF8')";
connection.Open();

using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
// CONNECTIONPROPERTY('SUPPORT_UTF8') returns NULL in SQLServer versions that don't support UTF-8.
retval = !reader.IsDBNull(0);
}
}
}
}
return retval;
}

// the name length will be no more then (16 + prefix.Length + escapeLeft.Length + escapeRight.Length)
// some providers does not support names (Oracle supports up to 30)
public static string GetUniqueName(string prefix, string escapeLeft, string escapeRight)
Expand Down
39 changes: 36 additions & 3 deletions src/libraries/System.Data.SqlClient/tests/ManualTests/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,39 @@
# SqlClient Manual Tests

These tests require dedicated test servers, so they're designed to be run manually using a custom set of connection strings. These connection strings should be added as environment variables: TEST\_NP\_CONN\_STR & TEST\_TCP\_CONN\_STR. TEST\_NP\_CONN\_STR is a named pipes connection string to the test server, and TEST\_TCP\_CONN\_STR is a TCP connection string. Each protocol can be specified in the Server name parameter. These tests also assume the sample database "Northwind" exists in the target server. This sample database can be found [here](https://msdn.microsoft.com/en-us/library/mt710790.aspx).
These tests require dedicated test servers, so they're designed to be run manually using a custom set of connection strings.

Instructions for running tests: [Unix](https://github.com/dotnet/corefx/blob/master/Documentation/building/cross-platform-testing.md) and [Windows](https://github.com/dotnet/corefx/blob/master/Documentation/building/windows-instructions.md).
Documentation for connection string parameters: [SqlConnection.ConnectionString](https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring.aspx).
## Prerequisites

- CoreFX building. you need to be able to do a successful build and run the standard tests, [Unix](https://github.com/dotnet/corefx/blob/master/Documentation/building/cross-platform-testing.md) or [Windows](https://github.com/dotnet/corefx/blob/master/Documentation/building/windows-instructions.md) Use build.cmd for windows and build.sh for Linux to build CoreFX.

**N.B.** if you want to run the EFCore tests later you will need to build -allconfigurations to generate the NuGet packages, build -allconfigurations works only on windows.

- an [MS SQL Server](https://www.microsoft.com/en-us/sql-server/sql-server-editions-express) (any edition) 2012 or later that you can connect to with tcp and named pipes,

**N.B**. if you want to run the EFCore tests it should be a dedicated instance because they create a lot of databases.

- The [Northwind Sample Database](https://msdn.microsoft.com/en-us/library/mt710790.aspx)

- The [UDT Test Database](https://github.com/dotnet/corefx/tree/master/src/System.Data.SqlClient/tests/ManualTests/createUdtTestDb_corefx.sql)

- TCP and Named Pipe [connection strings](https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring.aspx) to your instance with Northwind set as the initial catalog



## Running All Tests

1. set the environment variables needed for the tests you want. At the minimum you need to set
`TEST_NP_CONN_STR` and `TEST_TCP_CONN_STR` to the connection strings.

2. Optionally you may also want to setup other environment variables to test specific optional features such as [TEST_LOCALDB_INSTALLED](https://github.com/dotnet/corefx/blob/8f7b490ca874ee2a9f11f0163412f7c95811298b/src/System.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs#L96) or [TEST_INTEGRATEDSECURITY_SETUP](https://github.com/dotnet/corefx/blob/8f7b490ca874ee2a9f11f0163412f7c95811298b/src/System.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs#L98). Other scenarios lke azure tests may need configuration so if you see those being skipped and you want to run them invesigate the skipped test code to identify how to configure it.

3. run `dotnet msbuild .\src\System.Data.SqlClient\tests\ManualTests\System.Data.SqlClient.ManualTesting.Tests.csproj /t:Rebuild` to build the debug version with all the assertions and run the tests.

4. If you need to re-run the test suite without having changed the build (e.g. if you've changed the exnvironment variables) you can use `dotnet msbuild .\src\System.Data.SqlClient\tests\ManualTests\System.Data.SqlClient.ManualTesting.Tests.csproj /t:Test`


## Running A Specific Test

Once you have all tests running you may need to debug a single failing test. To do this navigate into the manual tests project directory `cd src\System.Data.SqlClient\tests\ManualTests` then run dotnet msbuild and specify the name of the test you want to execute, like this:
`dotnet msbuild /t:RebuildAndTest /p:XunitMethodName=System.Data.SqlClient.ManualTesting.Tests.DDDataTypesTest.MaxTypesTest`
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ public static class ConnectionPoolTest
private static readonly string _tcpConnStr = (new SqlConnectionStringBuilder(DataTestUtility.TcpConnStr) { MultipleActiveResultSets = false, Pooling = true }).ConnectionString;
private static readonly string _tcpMarsConnStr = (new SqlConnectionStringBuilder(DataTestUtility.TcpConnStr) { MultipleActiveResultSets = true, Pooling = true }).ConnectionString;

[ConditionalFact(typeof(DataTestUtility),nameof(DataTestUtility.AreConnStringsSetup))]

[ConditionalFact(typeof(DataTestUtility),nameof(DataTestUtility.AreConnStringsSetup), /* [ActiveIssue(33930)]: */ nameof(DataTestUtility.IsUsingNativeSNI))]
public static void ConnectionPool_NonMars()
{
RunDataTestForSingleConnString(_tcpConnStr);
}

[ConditionalFact(typeof(DataTestUtility),nameof(DataTestUtility.AreConnStringsSetup))]
[ConditionalFact(typeof(DataTestUtility),nameof(DataTestUtility.AreConnStringsSetup), /* [ActiveIssue(33930)] */ nameof(DataTestUtility.IsUsingNativeSNI))]
public static void ConnectionPool_Mars()
{
RunDataTestForSingleConnString(_tcpMarsConnStr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ public class PoolBlockPeriodTest
private const string InstanceName = "InstanceName";
private const int ConnectionTimeout = 15;
private const int CompareMargin = 2;
private static bool AreConnectionStringsSetup() => DataTestUtility.AreConnStringsSetup();

[ConditionalTheory(nameof(AreConnectionStringsSetup))]
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), /* [ActiveIssue(33930)] */ nameof(DataTestUtility.IsUsingNativeSNI))]
[InlineData("Azure with Default Policy must Disable blocking (*.database.windows.net)", new object[] { AzureEndpointSample })]
[InlineData("Azure with Default Policy must Disable blocking (*.database.chinacloudapi.cn)", new object[] { AzureChinaEnpointSample })]
[InlineData("Azure with Default Policy must Disable blocking (*.database.usgovcloudapi.net)", new object[] { AzureUSGovernmentEndpointSample })]
Expand All @@ -46,7 +45,7 @@ public void TestAzureBlockingPeriod(string description, object[] Params)
PoolBlockingPeriodAzureTest(connString, policy);
}

[ConditionalTheory(nameof(AreConnectionStringsSetup))]
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), /* [ActiveIssue(33930)] */ nameof(DataTestUtility.IsUsingNativeSNI))]
[InlineData("NonAzure with Default Policy must Enable blocking", new object[] { NonExistentServer })]
[InlineData("NonAzure with Auto Policy must Enable Blocking", new object[] { NonExistentServer, PoolBlockingPeriod.Auto })]
[InlineData("NonAzure with Always Policy must Enable Blocking", new object[] { NonExistentServer, PoolBlockingPeriod.AlwaysBlock })]
Expand All @@ -67,7 +66,7 @@ public void TestNonAzureBlockingPeriod(string description, object[] Params)
PoolBlockingPeriodNonAzureTest(connString, policy);
}

[ConditionalTheory(nameof(AreConnectionStringsSetup))]
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), /* [ActiveIssue(33930)] */ nameof(DataTestUtility.IsUsingNativeSNI))]
[InlineData("Test policy with Auto (lowercase)", "auto")]
[InlineData("Test policy with Auto (PascalCase)", "Auto")]
[InlineData("Test policy with Always (lowercase)", "alwaysblock")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ private static void RunAllTestsForSingleServer(string connectionString, bool usi
// These tests fail with named pipes, since they try to do DNS lookups on named pipe paths.
if (!usingNamePipes)
{
TimeoutDuringReadAsyncWithClosedReaderTest(connectionString);
//if (DataTestUtility.IsUsingNativeSNI()) /* [ActiveIssue(33930)] */
//{
// TimeoutDuringReadAsyncWithClosedReaderTest(connectionString);
//}
NonFatalTimeoutDuringRead(connectionString);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static void NamedPipesMARSTest()
}

#if DEBUG
[ConditionalFact(typeof(DataTestUtility),nameof(DataTestUtility.AreConnStringsSetup))]
[ConditionalFact(typeof(DataTestUtility),nameof(DataTestUtility.AreConnStringsSetup), /* [ActiveIssue(33930)] */ nameof(DataTestUtility.IsUsingNativeSNI))]
public static void MARSAsyncTimeoutTest()
{
using (SqlConnection connection = new SqlConnection(_connStr))
Expand Down Expand Up @@ -73,7 +73,7 @@ public static void MARSAsyncTimeoutTest()
}
}

[ConditionalFact(typeof(DataTestUtility),nameof(DataTestUtility.AreConnStringsSetup))]
[ConditionalFact(typeof(DataTestUtility),nameof(DataTestUtility.AreConnStringsSetup), /* [ActiveIssue(33930)] */ nameof(DataTestUtility.IsUsingNativeSNI))]
public static void MARSSyncTimeoutTest()
{
using (SqlConnection connection = new SqlConnection(_connStr))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static void CodeCoverageSqlClient()
Assert.False(((IList)opc).IsReadOnly, "FAILED: Expected collection to NOT be read only.");
Assert.False(((IList)opc).IsFixedSize, "FAILED: Expected collection to NOT be fixed size.");
Assert.False(((IList)opc).IsSynchronized, "FAILED: Expected collection to NOT be synchronized.");
DataTestUtility.AssertEqualsWithDescription("Object", ((IList)opc).SyncRoot.GetType().Name, "FAILED: Incorrect SyncRoot Name");
DataTestUtility.AssertEqualsWithDescription("List`1", ((IList)opc).SyncRoot.GetType().Name, "FAILED: Incorrect SyncRoot Name");

{
string failValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace System.Data.SqlClient.ManualTesting.Tests
public static class SqlCredentialTest
{

[ConditionalFact(typeof(DataTestUtility),nameof(DataTestUtility.AreConnStringsSetup))]
[ConditionalFact(typeof(DataTestUtility),nameof(DataTestUtility.AreConnStringsSetup), /* [ActiveIssue(33930)] */ nameof(DataTestUtility.IsUsingNativeSNI))]
public static void CreateSqlConnectionWithCredential()
{
var user = "u" + Guid.NewGuid().ToString().Replace("-", "");
Expand Down Expand Up @@ -49,7 +49,7 @@ public static void CreateSqlConnectionWithCredential()
}
}

[ConditionalFact(typeof(DataTestUtility),nameof(DataTestUtility.AreConnStringsSetup))]
[ConditionalFact(typeof(DataTestUtility),nameof(DataTestUtility.AreConnStringsSetup), /* [ActiveIssue(33930)] */ nameof(DataTestUtility.IsUsingNativeSNI))]
public static void SqlConnectionChangePasswordPlaintext()
{
var user = "u" + Guid.NewGuid().ToString().Replace("-", "");
Expand Down Expand Up @@ -82,7 +82,7 @@ public static void SqlConnectionChangePasswordPlaintext()
}
}

[ConditionalFact(typeof(DataTestUtility),nameof(DataTestUtility.AreConnStringsSetup))]
[ConditionalFact(typeof(DataTestUtility),nameof(DataTestUtility.AreConnStringsSetup), /* [ActiveIssue(33930)] */ nameof(DataTestUtility.IsUsingNativeSNI))]
public static void SqlConnectionChangePasswordSecureString()
{
var user = "u" + Guid.NewGuid().ToString().Replace("-", "");
Expand Down Expand Up @@ -122,7 +122,7 @@ public static void SqlConnectionChangePasswordSecureString()
}
}

[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))]
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), /* [ActiveIssue(33930)] */ nameof(DataTestUtility.IsUsingNativeSNI))]
public static void OldCredentialsShouldFail()
{
String user = "u" + Guid.NewGuid().ToString().Replace("-", "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace System.Data.SqlClient.ManualTesting.Tests
{
public static class Utf8SupportTest
{
[ConditionalFact(typeof(DataTestUtility),nameof(DataTestUtility.AreConnStringsSetup))]
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsUTF8Supported))]
public static void CheckSupportUtf8ConnectionProperty()
{
using (SqlConnection connection = new SqlConnection(DataTestUtility.TcpConnStr))
Expand All @@ -18,15 +18,7 @@ public static void CheckSupportUtf8ConnectionProperty()
{
while (reader.Read())
{
// CONNECTIONPROPERTY('SUPPORT_UTF8') returns NULL in SQLServer versions that don't support UTF-8.
if (!reader.IsDBNull(0))
{
Assert.Equal(1, reader.GetInt32(0));
}
else
{
Console.WriteLine("CONNECTIONPROPERTY('SUPPORT_UTF8') is not supported on this SQLServer");
}
Assert.Equal(1, reader.GetInt32(0));
}
}
}
Expand Down
Loading

0 comments on commit 360f43f

Please sign in to comment.