Skip to content

Commit 19f9aab

Browse files
authored
[6.1] Refactor Test TDS Servers (#3715)
* Refactor Test TDS Servers. Expand functional testing of connection pooling and transient failures. (#3488) * Fix capitalization. * Fix nullable. * Reduce layered static readonly fields. Fixes test using app context switch helper.
1 parent b1bf339 commit 19f9aab

File tree

46 files changed

+2366
-1244
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+2366
-1244
lines changed

build.proj

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,14 @@
5858
<NetStandardDriver Include="**/netcore/ref/Microsoft.Data.SqlClient*.csproj" />
5959
<AKVProvider Include="**/add-ons/**/AzureKeyVaultProvider/*.csproj" />
6060

61+
<UnitTests Include="**/Common/Common.csproj" />
62+
<UnitTests Include="**/tools/TDS/TDS/TDS.csproj" />
63+
<UnitTests Include="**/tools/TDS/TDS.EndPoint/TDS.EndPoint.csproj" />
64+
<UnitTests Include="**/tools/TDS/TDS.Servers/TDS.Servers.csproj" />
6165
<UnitTests Include="**/UnitTests/Microsoft.Data.SqlClient.UnitTests.csproj" />
6266
<UnitTestsProj Include="**/UnitTests/Microsoft.Data.SqlClient.UnitTests.csproj" />
63-
67+
68+
6469
<FunctionalTests Include="**/Common/Common.csproj" />
6570
<FunctionalTests Include="**/tools/TDS/TDS/TDS.csproj" />
6671
<FunctionalTests Include="**/tools/TDS/TDS.EndPoint/TDS.EndPoint.csproj" />
@@ -221,6 +226,7 @@
221226
-p:TestTargetOS=Windows$(TargetGroup)
222227
--collect "Code coverage"
223228
--results-directory $(ResultsDirectory)
229+
--filter "category!=failing%26category!=flaky"
224230
--logger:"trx;LogFilePrefix=Unit-Windows$(TargetGroup)-$(TestSet)"
225231
</TestCommand>
226232
<TestCommand>$(TestCommand.Replace($([System.Environment]::NewLine), " "))</TestCommand>
@@ -241,8 +247,9 @@
241247
-p:TestTargetOS=Unixnetcoreapp
242248
--collect "Code coverage"
243249
--results-directory $(ResultsDirectory)
250+
--filter "category!=failing%26category!=flaky"
244251
--logger:"trx;LogFilePrefix=Unit-Unixnetcoreapp-$(TestSet)"
245-
</TestCommand>
252+
</TestCommand>
246253
<TestCommand>$(TestCommand.Replace($([System.Environment]::NewLine), " "))</TestCommand>
247254
</PropertyGroup>
248255
<Message Text=">>> Running unit tests for Unix via command: $(TestCommand)"/>

src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1718,8 +1718,11 @@ private void LoginNoFailover(ServerInfo serverInfo,
17181718
continue;
17191719
}
17201720

1721+
// If state != closed, indicates that the parser encountered an error while processing the
1722+
// login response (e.g. an explicit error token). Transient network errors that impact
1723+
// connectivity will result in parser state being closed.
17211724
if (_parser == null
1722-
|| TdsParserState.Closed != _parser.State
1725+
|| _parser.State != TdsParserState.Closed
17231726
|| IsDoNotRetryConnectError(sqlex)
17241727
|| timeout.IsExpired)
17251728
{
@@ -1999,6 +2002,9 @@ TimeoutTimer timeout
19992002
throw; // Caller will call LoginFailure()
20002003
}
20012004

2005+
// TODO: It doesn't make sense to connect to an azure sql server instance with a failover partner
2006+
// specified. Azure SQL Server does not support failover partners. Other availability technologies
2007+
// like Failover Groups should be used instead.
20022008
if (!ADP.IsAzureSqlServerEndpoint(connectionOptions.DataSource) && IsConnectionDoomed)
20032009
{
20042010
throw;

src/Microsoft.Data.SqlClient/src/Microsoft/Data/Common/AdapterUtil.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
using Microsoft.Identity.Client;
2525
using Microsoft.SqlServer.Server;
2626
using System.Security.Authentication;
27+
using System.Collections.Generic;
2728

2829
#if NETFRAMEWORK
2930
using System.Reflection;
@@ -768,7 +769,7 @@ internal static Version GetAssemblyVersion()
768769
/// <remarks>This array includes endpoint URLs for Azure SQL in global, Germany, US Government,
769770
/// China, and Fabric environments. These endpoints are used to identify and interact with Azure SQL services
770771
/// in their respective regions or environments.</remarks>
771-
internal static readonly string[] s_azureSqlServerEndpoints = { AZURE_SQL,
772+
internal static readonly List<string> s_azureSqlServerEndpoints = new() { AZURE_SQL,
772773
AZURE_SQL_GERMANY,
773774
AZURE_SQL_USGOV,
774775
AZURE_SQL_CHINA,
@@ -808,7 +809,7 @@ internal static bool IsAzureSqlServerEndpoint(string dataSource)
808809
}
809810

810811
// This method assumes dataSource parameter is in TCP connection string format.
811-
private static bool IsEndpoint(string dataSource, string[] endpoints)
812+
private static bool IsEndpoint(string dataSource, ICollection<string> endpoints)
812813
{
813814
int length = dataSource.Length;
814815
// remove server port

src/Microsoft.Data.SqlClient/src/Microsoft/Data/Common/ConnectionString/DbConnectionStringDefaults.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ internal static class DbConnectionStringDefaults
5757

5858
#if NETFRAMEWORK
5959
internal const bool ConnectionReset = true;
60-
internal static readonly bool TransparentNetworkIPResolution = !LocalAppContextSwitches.DisableTnirByDefault;
60+
internal static bool TransparentNetworkIpResolution => !LocalAppContextSwitches.DisableTnirByDefault;
6161
internal const string NetworkLibrary = "";
6262
#endif
6363
}

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionString.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ internal static class DEFAULT
6767
internal const string FailoverPartnerSPN = DbConnectionStringDefaults.FailoverPartnerSPN;
6868
internal const bool Context_Connection = DbConnectionStringDefaults.ContextConnection;
6969
#if NETFRAMEWORK
70-
internal static readonly bool TransparentNetworkIPResolution = DbConnectionStringDefaults.TransparentNetworkIPResolution;
70+
internal static bool TransparentNetworkIPResolution => DbConnectionStringDefaults.TransparentNetworkIpResolution;
7171
internal const bool Connection_Reset = DbConnectionStringDefaults.ConnectionReset;
7272
internal const string Network_Library = DbConnectionStringDefaults.NetworkLibrary;
7373
#endif // NETFRAMEWORK

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionStringBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ private enum Keywords
130130

131131
#if NETFRAMEWORK
132132
private bool _connectionReset = DbConnectionStringDefaults.ConnectionReset;
133-
private bool _transparentNetworkIPResolution = DbConnectionStringDefaults.TransparentNetworkIPResolution;
133+
private bool _transparentNetworkIPResolution = DbConnectionStringDefaults.TransparentNetworkIpResolution;
134134
private string _networkLibrary = DbConnectionStringDefaults.NetworkLibrary;
135135
#endif
136136
#endregion //Fields
@@ -549,7 +549,7 @@ private void Reset(Keywords index)
549549
_connectionReset = DbConnectionStringDefaults.ConnectionReset;
550550
break;
551551
case Keywords.TransparentNetworkIPResolution:
552-
_transparentNetworkIPResolution = DbConnectionStringDefaults.TransparentNetworkIPResolution;
552+
_transparentNetworkIPResolution = DbConnectionStringDefaults.TransparentNetworkIpResolution;
553553
break;
554554
case Keywords.NetworkLibrary:
555555
_networkLibrary = DbConnectionStringDefaults.NetworkLibrary;

src/Microsoft.Data.SqlClient/tests/FunctionalTests/LocalizationTest.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Collections.Generic;
77
using System.Globalization;
88
using System.Threading;
9+
using Microsoft.SqlServer.TDS.Servers;
910
using Xunit;
1011

1112
namespace Microsoft.Data.SqlClient.Tests
@@ -55,9 +56,11 @@ private string GetLocalizedErrorMessage(string culture)
5556
Thread.CurrentThread.CurrentCulture = new CultureInfo(culture);
5657
Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);
5758

58-
using TestTdsServer server = TestTdsServer.StartTestServer();
59-
var connStr = server.ConnectionString;
60-
connStr = connStr.Replace("localhost", "dummy");
59+
using TdsServer server = new TdsServer(new TdsServerArguments());
60+
server.Start();
61+
var connStr = new SqlConnectionStringBuilder() {
62+
DataSource = $"dummy,{server.EndPoint.Port}"
63+
}.ConnectionString;
6164
using SqlConnection connection = new SqlConnection(connStr);
6265

6366
try

src/Microsoft.Data.SqlClient/tests/FunctionalTests/Microsoft.Data.SqlClient.FunctionalTests.csproj

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@
3939
<Compile Include="SqlBulkCopyTest.cs" />
4040
<Compile Include="SqlClientMetaDataCollectionNamesTest.cs" />
4141
<Compile Include="SqlDataAdapterTest.cs" />
42-
<Compile Include="SqlConnectionBasicTests.cs" />
43-
<Compile Include="SqlConnectionReadOnlyRoutingTests.cs" />
4442
<Compile Include="SqlCommandTest.cs" />
4543
<Compile Include="SqlConnectionTest.cs" />
4644
<Compile Include="AADAuthenticationTests.cs" />
@@ -66,8 +64,6 @@
6664
<Compile Include="SqlMetaDataTest.cs" />
6765
<Compile Include="SqlConnectionStringBuilderTest.cs" />
6866
<Compile Include="SerializeSqlTypesTest.cs" />
69-
<Compile Include="TestTdsServer.cs" />
70-
<Compile Include="TestRoutingTdsServer.cs" />
7167
<Compile Include="SqlHelperTest.cs" />
7268
<Compile Include="..\..\src\Microsoft\Data\Common\MultipartIdentifier.cs" />
7369
</ItemGroup>
@@ -96,6 +92,7 @@
9692
<PackageReference Include="Microsoft.NET.Test.Sdk" />
9793
<PackageReference Include="Microsoft.SqlServer.Types" />
9894
<PackageReference Include="Newtonsoft.Json" />
95+
<PackageReference Include="System.Configuration.ConfigurationManager" />
9996
<PackageReference Include="System.Security.Cryptography.Pkcs" />
10097
</ItemGroup>
10198
<ItemGroup Condition="'$(TargetGroup)' == 'netcoreapp'">

src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlConnectionReadOnlyRoutingTests.cs

Lines changed: 0 additions & 140 deletions
This file was deleted.

src/Microsoft.Data.SqlClient/tests/FunctionalTests/TestRoutingTdsServer.cs

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)