Skip to content

Commit c195cbf

Browse files
committed
Review changes.
1 parent fe78207 commit c195cbf

20 files changed

Lines changed: 288 additions & 309 deletions

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,12 +1712,12 @@ 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
1719+
|| _parser.State != TdsParserState.Closed
17161720
|| IsDoNotRetryConnectError(sqlex)
1717-
// If state != closed, indicates that the parser encountered an error while processing the
1718-
// login response (e.g. an explicit error token). Transient network errors that impact
1719-
// connectivity will result in parser state being closed.
1720-
|| TdsParserState.Closed != _parser.State
17211721
|| timeout.IsExpired)
17221722
{
17231723
// no more time to try again

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -816,19 +816,19 @@ internal static Version GetAssemblyVersion()
816816

817817
internal static readonly string[] s_azureSynapseOnDemandEndpoints = [.. s_azureSqlServerOnDemandEndpoints, .. s_azureSynapseEndpoints];
818818

819-
internal static bool IsAzureSynapseOnDemandEndpoint(string dataSource)
819+
internal static bool C(string dataSource)
820820
{
821821
return IsEndpoint(dataSource, s_azureSynapseOnDemandEndpoints)
822822
|| dataSource.IndexOf(AZURE_SYNAPSE, StringComparison.OrdinalIgnoreCase) >= 0;
823823
}
824824

825825
internal static bool IsAzureSqlServerEndpoint(string dataSource)
826826
{
827-
return IsEndpoint(dataSource, s_azureSqlServerEndpoints.AsReadOnly());
827+
return IsEndpoint(dataSource, s_azureSqlServerEndpoints);
828828
}
829829

830830
// This method assumes dataSource parameter is in TCP connection string format.
831-
private static bool IsEndpoint(string dataSource, IReadOnlyList<string> endpoints)
831+
private static bool IsEndpoint(string dataSource, ICollection<string> endpoints)
832832
{
833833
int length = dataSource.Length;
834834
// remove server port

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@ private string GetLocalizedErrorMessage(string culture)
5656
Thread.CurrentThread.CurrentCulture = new CultureInfo(culture);
5757
Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);
5858

59-
using TdsServer server = new TdsServer(new TdsServerArguments() { });
59+
using TdsServer server = new TdsServer(new TdsServerArguments());
6060
server.Start();
61-
var connStr = new SqlConnectionStringBuilder() { DataSource = $"dummy,{server.EndPoint.Port}" }.ConnectionString;
61+
var connStr = new SqlConnectionStringBuilder() {
62+
DataSource = $"dummy,{server.EndPoint.Port}"
63+
}.ConnectionString;
6264
using SqlConnection connection = new SqlConnection(connStr);
6365

6466
try

src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/SqlConnectionStringTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public SqlConnectionStringTest()
3434
[InlineData("my.test.server", true, Tristate.NotInitialized, true)]
3535
[InlineData("my.test.server", false, Tristate.NotInitialized, false)]
3636
[InlineData("my.test.server", null, Tristate.NotInitialized, true)]
37-
public void TestDefaultTNIR(string dataSource, bool? tnirEnabledInConnString, Tristate tnirDisabledAppContext, bool expectedValue)
37+
public void TestDefaultTnir(string dataSource, bool? tnirEnabledInConnString, Tristate tnirDisabledAppContext, bool expectedValue)
3838
{
3939
// Note: TNIR is only supported on .NET Framework.
4040
// Note: TNIR is disabled by default for Azure SQL Database servers (i.e. *.database.windows.net)

src/Microsoft.Data.SqlClient/tests/UnitTests/SimulatedServerTests/ConnectionFailoverTests.cs

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -322,15 +322,8 @@ public void NetworkError_WithUserProvidedPartner_RetryEnabled_ShouldConnectToFai
322322
Encrypt = false,
323323
};
324324
using SqlConnection connection = new(builder.ConnectionString);
325-
try
326-
{
327-
// Act
328-
connection.Open();
329-
}
330-
catch (Exception e)
331-
{
332-
Assert.Fail(e.Message);
333-
}
325+
// Act
326+
connection.Open();
334327

335328
// Assert
336329
// On the first connection attempt, failover partner information is available in the connection string,
@@ -374,15 +367,9 @@ public void TransientFault_ShouldConnectToPrimary(uint errorCode)
374367
Encrypt = false
375368
};
376369
using SqlConnection connection = new(builder.ConnectionString);
377-
try
378-
{
379-
// Act
380-
connection.Open();
381-
}
382-
catch (Exception e)
383-
{
384-
Assert.Fail(e.Message);
385-
}
370+
371+
// Act
372+
connection.Open();
386373

387374
// Assert
388375
Assert.Equal(ConnectionState.Open, connection.State);
@@ -474,15 +461,9 @@ public void TransientFault_WithUserProvidedPartner_ShouldConnectToPrimary(uint e
474461
FailoverPartner = $"localhost:{failoverServer.EndPoint.Port}", // User provided failover partner
475462
};
476463
using SqlConnection connection = new(builder.ConnectionString);
477-
try
478-
{
479-
// Act
480-
connection.Open();
481-
}
482-
catch (Exception e)
483-
{
484-
Assert.Fail(e.Message);
485-
}
464+
465+
// Act
466+
connection.Open();
486467

487468
// Assert
488469
Assert.Equal(ConnectionState.Open, connection.State);

src/Microsoft.Data.SqlClient/tests/UnitTests/SimulatedServerTests/ConnectionReadOnlyRoutingTests.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,10 @@ public async Task NonRoutedAsyncConnection()
4343
}
4444

4545
[Fact]
46-
public void RoutedConnection()
47-
=> RecursivelyRoutedConnection(1);
46+
public void RoutedConnection() => RecursivelyRoutedConnection(1);
4847

4948
[Fact]
50-
public async Task RoutedAsyncConnection()
51-
=> await RecursivelyRoutedAsyncConnection(1);
49+
public async Task RoutedAsyncConnection() => await RecursivelyRoutedAsyncConnection(1);
5250

5351
[Theory]
5452
[InlineData(11)] // 11 layers of routing should succeed, 12 should fail

src/Microsoft.Data.SqlClient/tests/UnitTests/SimulatedServerTests/ConnectionRoutingTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ public void TransientFaultAtRoutedLocation_RetryDisabled_ShouldFail(uint errorCo
103103
Encrypt = false,
104104
};
105105
using SqlConnection connection = new(builder.ConnectionString);
106-
//TODO validate exception type
106+
107+
//Act and Assert
107108
Assert.Throws<SqlException>(() => connection.Open());
108109
}
109110

src/Microsoft.Data.SqlClient/tests/UnitTests/SimulatedServerTests/ConnectionRoutingTestsAzure.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ public void TransientFaultAtRoutedLocation_ShouldReturnToGateway(uint errorCode)
4646
using RoutingTdsServer router = new(
4747
new RoutingTdsServerArguments()
4848
{
49-
//RoutingTCPHost = server.EndPoint.Address.ToString() == IPAddress.Any.ToString() ? IPAddress.Loopback.ToString() : server.EndPoint.Address.ToString(),
5049
RoutingTCPHost = "localhost",
5150
RoutingTCPPort = (ushort)server.EndPoint.Port,
5251
});
@@ -100,7 +99,6 @@ public void TransientFaultAtRoutedLocation_RetryDisabled_ShouldFail(uint errorCo
10099
using RoutingTdsServer router = new(
101100
new RoutingTdsServerArguments()
102101
{
103-
//RoutingTCPHost = server.EndPoint.Address.ToString() == IPAddress.Any.ToString() ? IPAddress.Loopback.ToString() : server.EndPoint.Address.ToString(),
104102
RoutingTCPHost = "localhost",
105103
RoutingTCPPort = (ushort)server.EndPoint.Port,
106104
});
@@ -116,7 +114,6 @@ public void TransientFaultAtRoutedLocation_RetryDisabled_ShouldFail(uint errorCo
116114
Encrypt = false,
117115
};
118116
using SqlConnection connection = new(builder.ConnectionString);
119-
//TODO validate exception type
120117
Assert.Throws<SqlException>(() => connection.Open());
121118
}
122119

src/Microsoft.Data.SqlClient/tests/tools/TDS/TDS.EndPoint/TDSServerEndPointConnection.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,14 @@ public void Dispose()
140140
{
141141
Connection.Close();
142142
Connection.Dispose();
143+
Connection = null;
144+
}
145+
146+
// TODO: there's a deadlock condition when awaiting the processor task
147+
// only dispose of it if it's already completed
148+
if (ProcessorTask.Status == TaskStatus.RanToCompletion)
149+
{
150+
ProcessorTask.Dispose();
143151
}
144152
}
145153

0 commit comments

Comments
 (0)