Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit f749fca

Browse files
authored
Merge pull request #34546 from Wraith2/sqltests-updates
SqlClient Manual Test fixes and documentation update
2 parents 7c50828 + fe85a32 commit f749fca

File tree

10 files changed

+248
-27
lines changed

10 files changed

+248
-27
lines changed

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,33 @@ public static bool IsDatabasePresent(string name)
6363

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

66+
public static bool IsUsingNativeSNI() => !IsUsingManagedSNI();
67+
68+
public static bool IsUTF8Supported()
69+
{
70+
bool retval = false;
71+
if (AreConnStringsSetup())
72+
{
73+
using (SqlConnection connection = new SqlConnection(DataTestUtility.TcpConnStr))
74+
using (SqlCommand command = new SqlCommand())
75+
{
76+
command.Connection = connection;
77+
command.CommandText = "SELECT CONNECTIONPROPERTY('SUPPORT_UTF8')";
78+
connection.Open();
79+
80+
using (SqlDataReader reader = command.ExecuteReader())
81+
{
82+
while (reader.Read())
83+
{
84+
// CONNECTIONPROPERTY('SUPPORT_UTF8') returns NULL in SQLServer versions that don't support UTF-8.
85+
retval = !reader.IsDBNull(0);
86+
}
87+
}
88+
}
89+
}
90+
return retval;
91+
}
92+
6693
// the name length will be no more then (16 + prefix.Length + escapeLeft.Length + escapeRight.Length)
6794
// some providers does not support names (Oracle supports up to 30)
6895
public static string GetUniqueName(string prefix, string escapeLeft, string escapeRight)
Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,39 @@
11
# SqlClient Manual Tests
22

3-
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).
3+
These tests require dedicated test servers, so they're designed to be run manually using a custom set of connection strings.
44

5-
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).
6-
Documentation for connection string parameters: [SqlConnection.ConnectionString](https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring.aspx).
5+
## Prerequisites
6+
7+
- 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.
8+
9+
**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.
10+
11+
- 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,
12+
13+
**N.B**. if you want to run the EFCore tests it should be a dedicated instance because they create a lot of databases.
14+
15+
- The [Northwind Sample Database](https://msdn.microsoft.com/en-us/library/mt710790.aspx)
16+
17+
- The [UDT Test Database](https://github.com/dotnet/corefx/tree/master/src/System.Data.SqlClient/tests/ManualTests/createUdtTestDb_corefx.sql)
18+
19+
- 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
20+
21+
22+
23+
## Running All Tests
24+
25+
1. set the environment variables needed for the tests you want. At the minimum you need to set
26+
`TEST_NP_CONN_STR` and `TEST_TCP_CONN_STR` to the connection strings.
27+
28+
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.
29+
30+
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.
31+
32+
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`
33+
34+
35+
36+
## Running A Specific Test
37+
38+
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:
39+
`dotnet msbuild /t:RebuildAndTest /p:XunitMethodName=System.Data.SqlClient.ManualTesting.Tests.DDDataTypesTest.MaxTypesTest`

src/System.Data.SqlClient/tests/ManualTests/SQL/ConnectionPoolTest/ConnectionPoolTest.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ public static class ConnectionPoolTest
1414
private static readonly string _tcpConnStr = (new SqlConnectionStringBuilder(DataTestUtility.TcpConnStr) { MultipleActiveResultSets = false, Pooling = true }).ConnectionString;
1515
private static readonly string _tcpMarsConnStr = (new SqlConnectionStringBuilder(DataTestUtility.TcpConnStr) { MultipleActiveResultSets = true, Pooling = true }).ConnectionString;
1616

17-
[ConditionalFact(typeof(DataTestUtility),nameof(DataTestUtility.AreConnStringsSetup))]
17+
18+
[ConditionalFact(typeof(DataTestUtility),nameof(DataTestUtility.AreConnStringsSetup), /* [ActiveIssue(33930)]: */ nameof(DataTestUtility.IsUsingNativeSNI))]
1819
public static void ConnectionPool_NonMars()
1920
{
2021
RunDataTestForSingleConnString(_tcpConnStr);
2122
}
2223

23-
[ConditionalFact(typeof(DataTestUtility),nameof(DataTestUtility.AreConnStringsSetup))]
24+
[ConditionalFact(typeof(DataTestUtility),nameof(DataTestUtility.AreConnStringsSetup), /* [ActiveIssue(33930)] */ nameof(DataTestUtility.IsUsingNativeSNI))]
2425
public static void ConnectionPool_Mars()
2526
{
2627
RunDataTestForSingleConnString(_tcpMarsConnStr);

src/System.Data.SqlClient/tests/ManualTests/SQL/ConnectionPoolTest/PoolBlockPeriodTest.netcoreapp.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ public class PoolBlockPeriodTest
2020
private const string InstanceName = "InstanceName";
2121
private const int ConnectionTimeout = 15;
2222
private const int CompareMargin = 2;
23-
private static bool AreConnectionStringsSetup() => DataTestUtility.AreConnStringsSetup();
2423

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

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

70-
[ConditionalTheory(nameof(AreConnectionStringsSetup))]
69+
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), /* [ActiveIssue(33930)] */ nameof(DataTestUtility.IsUsingNativeSNI))]
7170
[InlineData("Test policy with Auto (lowercase)", "auto")]
7271
[InlineData("Test policy with Auto (PascalCase)", "Auto")]
7372
[InlineData("Test policy with Always (lowercase)", "alwaysblock")]

src/System.Data.SqlClient/tests/ManualTests/SQL/DataStreamTest/DataStreamTest.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ private static void RunAllTestsForSingleServer(string connectionString, bool usi
6464
// These tests fail with named pipes, since they try to do DNS lookups on named pipe paths.
6565
if (!usingNamePipes)
6666
{
67-
TimeoutDuringReadAsyncWithClosedReaderTest(connectionString);
67+
//if (DataTestUtility.IsUsingNativeSNI()) /* [ActiveIssue(33930)] */
68+
//{
69+
// TimeoutDuringReadAsyncWithClosedReaderTest(connectionString);
70+
//}
6871
NonFatalTimeoutDuringRead(connectionString);
6972
}
7073
}

src/System.Data.SqlClient/tests/ManualTests/SQL/MARSTest/MARSTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static void NamedPipesMARSTest()
3333
}
3434

3535
#if DEBUG
36-
[ConditionalFact(typeof(DataTestUtility),nameof(DataTestUtility.AreConnStringsSetup))]
36+
[ConditionalFact(typeof(DataTestUtility),nameof(DataTestUtility.AreConnStringsSetup), /* [ActiveIssue(33930)] */ nameof(DataTestUtility.IsUsingNativeSNI))]
3737
public static void MARSAsyncTimeoutTest()
3838
{
3939
using (SqlConnection connection = new SqlConnection(_connStr))
@@ -73,7 +73,7 @@ public static void MARSAsyncTimeoutTest()
7373
}
7474
}
7575

76-
[ConditionalFact(typeof(DataTestUtility),nameof(DataTestUtility.AreConnStringsSetup))]
76+
[ConditionalFact(typeof(DataTestUtility),nameof(DataTestUtility.AreConnStringsSetup), /* [ActiveIssue(33930)] */ nameof(DataTestUtility.IsUsingNativeSNI))]
7777
public static void MARSSyncTimeoutTest()
7878
{
7979
using (SqlConnection connection = new SqlConnection(_connStr))

src/System.Data.SqlClient/tests/ManualTests/SQL/ParameterTest/ParametersTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static void CodeCoverageSqlClient()
2222
Assert.False(((IList)opc).IsReadOnly, "FAILED: Expected collection to NOT be read only.");
2323
Assert.False(((IList)opc).IsFixedSize, "FAILED: Expected collection to NOT be fixed size.");
2424
Assert.False(((IList)opc).IsSynchronized, "FAILED: Expected collection to NOT be synchronized.");
25-
DataTestUtility.AssertEqualsWithDescription("Object", ((IList)opc).SyncRoot.GetType().Name, "FAILED: Incorrect SyncRoot Name");
25+
DataTestUtility.AssertEqualsWithDescription("List`1", ((IList)opc).SyncRoot.GetType().Name, "FAILED: Incorrect SyncRoot Name");
2626

2727
{
2828
string failValue;

src/System.Data.SqlClient/tests/ManualTests/SQL/SqlCredentialTest/SqlCredentialTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace System.Data.SqlClient.ManualTesting.Tests
1717
public static class SqlCredentialTest
1818
{
1919

20-
[ConditionalFact(typeof(DataTestUtility),nameof(DataTestUtility.AreConnStringsSetup))]
20+
[ConditionalFact(typeof(DataTestUtility),nameof(DataTestUtility.AreConnStringsSetup), /* [ActiveIssue(33930)] */ nameof(DataTestUtility.IsUsingNativeSNI))]
2121
public static void CreateSqlConnectionWithCredential()
2222
{
2323
var user = "u" + Guid.NewGuid().ToString().Replace("-", "");
@@ -49,7 +49,7 @@ public static void CreateSqlConnectionWithCredential()
4949
}
5050
}
5151

52-
[ConditionalFact(typeof(DataTestUtility),nameof(DataTestUtility.AreConnStringsSetup))]
52+
[ConditionalFact(typeof(DataTestUtility),nameof(DataTestUtility.AreConnStringsSetup), /* [ActiveIssue(33930)] */ nameof(DataTestUtility.IsUsingNativeSNI))]
5353
public static void SqlConnectionChangePasswordPlaintext()
5454
{
5555
var user = "u" + Guid.NewGuid().ToString().Replace("-", "");
@@ -82,7 +82,7 @@ public static void SqlConnectionChangePasswordPlaintext()
8282
}
8383
}
8484

85-
[ConditionalFact(typeof(DataTestUtility),nameof(DataTestUtility.AreConnStringsSetup))]
85+
[ConditionalFact(typeof(DataTestUtility),nameof(DataTestUtility.AreConnStringsSetup), /* [ActiveIssue(33930)] */ nameof(DataTestUtility.IsUsingNativeSNI))]
8686
public static void SqlConnectionChangePasswordSecureString()
8787
{
8888
var user = "u" + Guid.NewGuid().ToString().Replace("-", "");
@@ -122,7 +122,7 @@ public static void SqlConnectionChangePasswordSecureString()
122122
}
123123
}
124124

125-
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))]
125+
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), /* [ActiveIssue(33930)] */ nameof(DataTestUtility.IsUsingNativeSNI))]
126126
public static void OldCredentialsShouldFail()
127127
{
128128
String user = "u" + Guid.NewGuid().ToString().Replace("-", "");

src/System.Data.SqlClient/tests/ManualTests/SQL/Utf8SupportTest/Utf8SupportTest.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace System.Data.SqlClient.ManualTesting.Tests
44
{
55
public static class Utf8SupportTest
66
{
7-
[ConditionalFact(typeof(DataTestUtility),nameof(DataTestUtility.AreConnStringsSetup))]
7+
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsUTF8Supported))]
88
public static void CheckSupportUtf8ConnectionProperty()
99
{
1010
using (SqlConnection connection = new SqlConnection(DataTestUtility.TcpConnStr))
@@ -18,15 +18,7 @@ public static void CheckSupportUtf8ConnectionProperty()
1818
{
1919
while (reader.Read())
2020
{
21-
// CONNECTIONPROPERTY('SUPPORT_UTF8') returns NULL in SQLServer versions that don't support UTF-8.
22-
if (!reader.IsDBNull(0))
23-
{
24-
Assert.Equal(1, reader.GetInt32(0));
25-
}
26-
else
27-
{
28-
Console.WriteLine("CONNECTIONPROPERTY('SUPPORT_UTF8') is not supported on this SQLServer");
29-
}
21+
Assert.Equal(1, reader.GetInt32(0));
3022
}
3123
}
3224
}

0 commit comments

Comments
 (0)