Skip to content

Commit d244be2

Browse files
authored
Refactor Test TDS Servers. Expand functional testing of connection pooling and transient failures. (#3488)
1 parent aa8bf73 commit d244be2

File tree

44 files changed

+2360
-1241
lines changed

Some content is hidden

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

44 files changed

+2360
-1241
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" />
@@ -220,6 +225,7 @@
220225
-p:TestTargetOS=Windows$(TargetGroup)
221226
--collect "Code coverage"
222227
--results-directory $(ResultsDirectory)
228+
--filter "category!=failing%26category!=flaky"
223229
--logger:"trx;LogFilePrefix=Unit-Windows$(TargetGroup)-$(TestSet)"
224230
</TestCommand>
225231
<TestCommand>$(TestCommand.Replace($([System.Environment]::NewLine), " "))</TestCommand>
@@ -240,8 +246,9 @@
240246
-p:TestTargetOS=Unixnetcoreapp
241247
--collect "Code coverage"
242248
--results-directory $(ResultsDirectory)
249+
--filter "category!=failing%26category!=flaky"
243250
--logger:"trx;LogFilePrefix=Unit-Unixnetcoreapp-$(TestSet)"
244-
</TestCommand>
251+
</TestCommand>
245252
<TestCommand>$(TestCommand.Replace($([System.Environment]::NewLine), " "))</TestCommand>
246253
</PropertyGroup>
247254
<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
@@ -1712,8 +1712,11 @@ private void LoginNoFailover(ServerInfo serverInfo,
17121712
continue;
17131713
}
17141714

1715+
// If state != closed, indicates that the parser encountered an error while processing the
1716+
// login response (e.g. an explicit error token). Transient network errors that impact
1717+
// connectivity will result in parser state being closed.
17151718
if (_parser == null
1716-
|| TdsParserState.Closed != _parser.State
1719+
|| _parser.State != TdsParserState.Closed
17171720
|| IsDoNotRetryConnectError(sqlex)
17181721
|| timeout.IsExpired)
17191722
{
@@ -1993,6 +1996,9 @@ TimeoutTimer timeout
19931996
throw; // Caller will call LoginFailure()
19941997
}
19951998

1999+
// TODO: It doesn't make sense to connect to an azure sql server instance with a failover partner
2000+
// specified. Azure SQL Server does not support failover partners. Other availability technologies
2001+
// like Failover Groups should be used instead.
19962002
if (!ADP.IsAzureSqlServerEndpoint(connectionOptions.DataSource) && IsConnectionDoomed)
19972003
{
19982004
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;
@@ -787,7 +788,7 @@ internal static Version GetAssemblyVersion()
787788
/// <remarks>This array includes endpoint URLs for Azure SQL in global, Germany, US Government,
788789
/// China, and Fabric environments. These endpoints are used to identify and interact with Azure SQL services
789790
/// in their respective regions or environments.</remarks>
790-
internal static readonly string[] s_azureSqlServerEndpoints = { AZURE_SQL,
791+
internal static readonly List<string> s_azureSqlServerEndpoints = new() { AZURE_SQL,
791792
AZURE_SQL_GERMANY,
792793
AZURE_SQL_USGOV,
793794
AZURE_SQL_CHINA,
@@ -827,7 +828,7 @@ internal static bool IsAzureSqlServerEndpoint(string dataSource)
827828
}
828829

829830
// This method assumes dataSource parameter is in TCP connection string format.
830-
private static bool IsEndpoint(string dataSource, string[] endpoints)
831+
private static bool IsEndpoint(string dataSource, ICollection<string> endpoints)
831832
{
832833
int length = dataSource.Length;
833834
// 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/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
@@ -36,8 +36,6 @@
3636
<Compile Include="SqlBulkCopyTest.cs" />
3737
<Compile Include="SqlClientMetaDataCollectionNamesTest.cs" />
3838
<Compile Include="SqlDataAdapterTest.cs" />
39-
<Compile Include="SqlConnectionBasicTests.cs" />
40-
<Compile Include="SqlConnectionReadOnlyRoutingTests.cs" />
4139
<Compile Include="SqlCommandTest.cs" />
4240
<Compile Include="SqlConnectionTest.cs" />
4341
<Compile Include="AADAuthenticationTests.cs" />
@@ -64,8 +62,6 @@
6462
<Compile Include="SqlConnectionStringBuilderTest.cs" />
6563
<Compile Include="SerializeSqlTypesTest.cs" />
6664
<Compile Include="TdsParserStateObject.TestHarness.cs" />
67-
<Compile Include="TestTdsServer.cs" />
68-
<Compile Include="TestRoutingTdsServer.cs" />
6965
<Compile Include="SqlHelperTest.cs" />
7066
<Compile Include="..\..\src\Microsoft\Data\Common\MultipartIdentifier.cs" />
7167
<Compile Include="..\..\src\Microsoft\Data\SqlClient\TdsParserStateObject.Multiplexer.cs" />
@@ -91,6 +87,7 @@
9187
<PackageReference Include="Microsoft.NET.Test.Sdk" />
9288
<PackageReference Include="Microsoft.SqlServer.Types" />
9389
<PackageReference Include="Newtonsoft.Json" />
90+
<PackageReference Include="System.Configuration.ConfigurationManager" />
9491
<PackageReference Include="System.Security.Cryptography.Pkcs" />
9592
</ItemGroup>
9693
<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)