Introduce support for "Command Timeout" connection property (#1765)

This commit is contained in:
Cheena Malhotra
2023-01-03 21:42:32 -08:00
committed by GitHub
parent 376f6e6008
commit a8f9219f09
6 changed files with 90 additions and 4 deletions

View File

@@ -41,6 +41,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
Assert.AreEqual(details.ConnectRetryInterval, expectedForInt);
Assert.AreEqual(details.ConnectRetryCount, expectedForInt);
Assert.AreEqual(details.ConnectTimeout, expectedForInt);
Assert.AreEqual(details.CommandTimeout, expectedForInt);
Assert.AreEqual(details.LoadBalanceTimeout, expectedForInt);
Assert.AreEqual(details.MaxPoolSize, expectedForInt);
Assert.AreEqual(details.MinPoolSize, expectedForInt);
@@ -82,6 +83,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
details.ConnectRetryInterval = expectedForInt + index++;
details.ConnectRetryCount = expectedForInt + index++;
details.ConnectTimeout = expectedForInt + index++;
details.CommandTimeout = expectedForInt + index++;
details.LoadBalanceTimeout = expectedForInt + index++;
details.MaxPoolSize = expectedForInt + index++;
details.MinPoolSize = expectedForInt + index++;
@@ -115,6 +117,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
Assert.AreEqual(details.ConnectRetryInterval, expectedForInt + index++);
Assert.AreEqual(details.ConnectRetryCount, expectedForInt + index++);
Assert.AreEqual(details.ConnectTimeout, expectedForInt + index++);
Assert.AreEqual(details.CommandTimeout, expectedForInt + index++);
Assert.AreEqual(details.LoadBalanceTimeout, expectedForInt + index++);
Assert.AreEqual(details.MaxPoolSize, expectedForInt + index++);
Assert.AreEqual(details.MinPoolSize, expectedForInt + index++);
@@ -157,6 +160,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
details.ConnectRetryInterval = expectedForInt + index++;
details.ConnectRetryCount = expectedForInt + index++;
details.ConnectTimeout = expectedForInt + index++;
details.CommandTimeout = expectedForInt + index++;
details.LoadBalanceTimeout = expectedForInt + index++;
details.MaxPoolSize = expectedForInt + index++;
details.MinPoolSize = expectedForInt + index++;
@@ -199,7 +203,6 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
}
}
[Test]
public void SettingConnectiomTimeoutToLongShouldStillReturnInt()
{
@@ -229,6 +232,35 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
Assert.AreEqual(details.ConnectTimeout, expectedValue);
}
[Test]
public void SettingCommandTimeoutToLongShouldStillReturnInt()
{
ConnectionDetails details = new ConnectionDetails();
long timeout = 30;
int? expectedValue = 30;
details.Options["commandTimeout"] = timeout;
Assert.AreEqual(details.CommandTimeout, expectedValue);
}
[Test]
public void CommandTimeoutShouldReturnNullIfNotSet()
{
ConnectionDetails details = new ConnectionDetails();
int? expectedValue = null;
Assert.AreEqual(details.CommandTimeout, expectedValue);
}
[Test]
public void CommandTimeoutShouldReturnNullIfSetToNull()
{
ConnectionDetails details = new ConnectionDetails();
details.Options["commandTimeout"] = null;
int? expectedValue = null;
Assert.AreEqual(details.CommandTimeout, expectedValue);
}
[Test]
public void SettingEncrypShouldReturnExpectedEncryptOption()
{
@@ -262,6 +294,21 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
Assert.That(details.Encrypt, Is.EqualTo("Mandatory"), "Encrypt should be mandatory.");
}
[Test]
public void SettingCommandTimeoutToLongWhichCannotBeConvertedToIntShouldNotCrash()
{
ConnectionDetails details = new ConnectionDetails();
long timeout = long.MaxValue;
int? expectedValue = null;
string? expectedEncryptValue = "Strict";
details.Options["commandTimeout"] = timeout;
details.Options["encrypt"] = expectedEncryptValue;
Assert.That(details.CommandTimeout, Is.EqualTo(expectedValue), "Command Timeout not as expected");
Assert.That(details.Encrypt, Is.EqualTo("Strict"), "Encrypt should be strict.");
}
[Test]
public void ConnectionSettingsComparableShouldConsiderAdvancedOptions()
{

View File

@@ -538,6 +538,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
new object[] {"PersistSecurityInfo", true, "Persist Security Info"},
new object[] {"PersistSecurityInfo", false, "Persist Security Info"},
new object[] {"ConnectTimeout", 15, "Connect Timeout"},
new object[] {"CommandTimeout", 30, "Command Timeout"},
new object[] {"ConnectRetryCount", 1, "Connect Retry Count"},
new object[] {"ConnectRetryInterval", 10, "Connect Retry Interval"},
new object[] {"ApplicationName", "vscode-mssql", "Application Name"},
@@ -1687,7 +1688,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
// If we make a connection to a live database
ConnectionService service = ConnectionService.Instance;
var connectionString = "Server=tcp:{servername},1433;Initial Catalog={databasename};Persist Security Info=False;User ID={your_username};Password={your_password};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;HostNameInCertificate={servername}";
var connectionString = "Server=tcp:{servername},1433;Initial Catalog={databasename};Persist Security Info=False;User ID={your_username};Password={your_password};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;Command Timeout=30;HostNameInCertificate={servername}";
var details = service.ParseConnectionString(connectionString);
Assert.That(details.ServerName, Is.EqualTo("tcp:{servername},1433"), "Unexpected server name");
@@ -1700,6 +1701,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
Assert.That(details.TrustServerCertificate, Is.False, "Unexpected database name value");
Assert.That(details.HostNameInCertificate, Is.EqualTo("{servername}"), "Unexpected Host Name in Certificate value");
Assert.That(details.ConnectTimeout, Is.EqualTo(30), "Unexpected Connect Timeout value");
Assert.That(details.CommandTimeout, Is.EqualTo(30), "Unexpected CommandTimeout Timeout value");
}
/// <summary>
@@ -1711,7 +1713,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
// If we make a connection to a live database
ConnectionService service = ConnectionService.Instance;
var connectionString = "Server=tcp:{servername},1433;Initial Catalog={databasename};Persist Security Info=False;User ID={your_username};Password={your_password};MultipleActiveResultSets=False;Encrypt=Strict;TrustServerCertificate=False;Connection Timeout=30;HostNameInCertificate={servername}";
var connectionString = "Server=tcp:{servername},1433;Initial Catalog={databasename};Persist Security Info=False;User ID={your_username};Password={your_password};MultipleActiveResultSets=False;Encrypt=Strict;TrustServerCertificate=False;Connection Timeout=30;Command Timeout=30;HostNameInCertificate={servername}";
var details = service.ParseConnectionString(connectionString);
Assert.That(details.ServerName, Is.EqualTo("tcp:{servername},1433"), "Unexpected server name");
@@ -1724,6 +1726,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
Assert.That(details.TrustServerCertificate, Is.False, "Unexpected database name value");
Assert.That(details.HostNameInCertificate, Is.EqualTo("{servername}"), "Unexpected Host Name in Certificate value");
Assert.That(details.ConnectTimeout, Is.EqualTo(30), "Unexpected Connect Timeout value");
Assert.That(details.CommandTimeout, Is.EqualTo(30), "Unexpected Command Timeout value");
}
[Test]