Skip to content

Commit

Permalink
Fix | Minor fixes to support different test environments (#2045) (#2325)
Browse files Browse the repository at this point in the history
  • Loading branch information
Javad authored Jan 27, 2024
1 parent f8520c7 commit 759dc69
Show file tree
Hide file tree
Showing 13 changed files with 114 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,14 @@ internal static int GetPortByInstanceName(string browserHostName, string instanc
}
catch (SocketException se)
{
// A SocketException is possible for an instance name that doesn't exist.
// If there are multiple IP addresses and one of them fails with a SocketException but
// others simply don't respond because the instance name is invalid, we want to return
// the same error as if the response was empty. The higher error suits all scenarios.
// But log it, just in case there is a different, underlying issue that support needs
// to troubleshoot.
SqlClientEventSource.Log.TrySNITraceEvent(nameof(SSRP), EventType.ERR, "SocketException Message = {0}", args0: se?.Message);
throw new Exception(SQLMessage.SqlServerBrowserNotAccessible(), se);
throw;
}

const byte SvrResp = 0x05;
Expand Down Expand Up @@ -321,9 +327,37 @@ private static SsrpResult SendUDPRequest(IPEndPoint endPoint, byte[] requestPack
}
}
}
catch (AggregateException ae)
{
if (ae.InnerExceptions.Count > 0)
{
// Log all errors
foreach (Exception e in ae.InnerExceptions)
{
// Favor SocketException for returned error
if (e is SocketException)
{
result.Error = e;
}
SqlClientEventSource.Log.TrySNITraceEvent(nameof(SSRP), EventType.INFO,
"SendUDPRequest ({0}) resulted in exception: {1}", args0: endPoint.ToString(), args1: e.Message);
}

// Return first error if we didn't find a SocketException
result.Error = result.Error == null ? ae.InnerExceptions[0] : result.Error;
}
else
{
result.Error = ae;
SqlClientEventSource.Log.TrySNITraceEvent(nameof(SSRP), EventType.INFO,
"SendUDPRequest ({0}) resulted in exception: {1}", args0: endPoint.ToString(), args1: ae.Message);
}
}
catch (Exception e)
{
result.Error = e;
SqlClientEventSource.Log.TrySNITraceEvent(nameof(SSRP), EventType.INFO,
"SendUDPRequest ({0}) resulted in exception: {1}", args0: endPoint.ToString(), args1: e.Message);
}

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1984,10 +1984,6 @@ internal static string SSPIGenerateError()
{
return StringsHelper.GetString(Strings.SQL_SSPIGenerateError);
}
internal static string SqlServerBrowserNotAccessible()
{
return StringsHelper.GetString(Strings.SQL_SqlServerBrowserNotAccessible);
}
internal static string KerberosTicketMissingError()
{
return StringsHelper.GetString(Strings.SQL_KerberosTicketMissingError);
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -537,9 +537,6 @@
<data name="SQL_KerberosTicketMissingError" xml:space="preserve">
<value>Cannot authenticate using Kerberos. Ensure Kerberos has been initialized on the client with 'kinit' and a Service Principal Name has been registered for the SQL Server to allow Kerberos authentication.</value>
</data>
<data name="SQL_SqlServerBrowserNotAccessible" xml:space="preserve">
<value>Cannot connect to SQL Server Browser. Ensure SQL Server Browser has been started.</value>
</data>
<data name="SQL_InvalidSSPIPacketSize" xml:space="preserve">
<value>Invalid SSPI packet size.</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public ApiShould(PlatformSpecificTestContext context)
DummyKeyStoreProvider.Name, _lastTenBytesCek);
}

[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringSetupForAE))]
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsTargetReadyForAeWithKeyStore))]
[ClassData(typeof(AEConnectionStringProviderWithBooleanVariable))]
public void TestSqlTransactionCommitRollbackWithTransparentInsert(string connection, bool isCommitted)
{
Expand Down Expand Up @@ -94,7 +94,7 @@ public void TestSqlTransactionCommitRollbackWithTransparentInsert(string connect
}
}

[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringSetupForAE))]
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsTargetReadyForAeWithKeyStore))]
[ClassData(typeof(AEConnectionStringProvider))]
public void TestSqlTransactionRollbackToSavePoint(string connection)
{
Expand Down Expand Up @@ -140,7 +140,7 @@ public void TestSqlTransactionRollbackToSavePoint(string connection)
}
}

[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringSetupForAE))]
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsTargetReadyForAeWithKeyStore))]
[ClassData(typeof(AEConnectionStringProvider))]
public void SqlParameterProperties(string connection)
{
Expand Down Expand Up @@ -351,7 +351,7 @@ public void SqlParameterProperties(string connection)
}
}

[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringSetupForAE))]
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsTargetReadyForAeWithKeyStore))]
[ClassData(typeof(AEConnectionStringProvider))]
public void TestSqlDataAdapterFillDataTable(string connection)
{
Expand Down Expand Up @@ -424,7 +424,7 @@ public void TestSqlDataAdapterFillDataTable(string connection)
}
}

[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringSetupForAE))]
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsTargetReadyForAeWithKeyStore))]
[ClassData(typeof(AEConnectionStringProviderWithSchemaType))]
public void TestSqlDataAdapterFillSchema(string connection, SchemaType schemaType)
{
Expand Down Expand Up @@ -471,7 +471,7 @@ private void ValidateSchema(DataColumnCollection dataColumns)
Assert.Equal(typeof(string), dataColumns[2].DataType);
}

[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringSetupForAE))]
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsTargetReadyForAeWithKeyStore))]
[ClassData(typeof(AEConnectionStringProviderWithBooleanVariable))]
public void TestExecuteNonQuery(string connection, bool isAsync)
{
Expand Down Expand Up @@ -539,7 +539,7 @@ public void TestExecuteNonQuery(string connection, bool isAsync)
});
}

[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringSetupForAE))]
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsTargetReadyForAeWithKeyStore))]
[ClassData(typeof(AEConnectionStringProviderWithBooleanVariable))]
public void TestExecuteScalar(string connection, bool isAsync)
{
Expand Down Expand Up @@ -591,7 +591,7 @@ public void TestExecuteScalar(string connection, bool isAsync)
});
}

[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringSetupForAE))]
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsTargetReadyForAeWithKeyStore))]
[ClassData(typeof(AEConnectionStringProviderWithIntegers))]
public void TestSqlDataAdapterBatchUpdate(string connection, int numberofRows)
{
Expand Down Expand Up @@ -636,7 +636,7 @@ public void TestSqlDataAdapterBatchUpdate(string connection, int numberofRows)
}
}

[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringSetupForAE))]
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsTargetReadyForAeWithKeyStore))]
[ClassData(typeof(AEConnectionStringProvider))]
public void TestExecuteReader(string connection)
{
Expand Down Expand Up @@ -690,7 +690,7 @@ public void TestExecuteReader(string connection)
});
}

[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringSetupForAE))]
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsTargetReadyForAeWithKeyStore))]
[ClassData(typeof(AEConnectionStringProvider))]
public async void TestExecuteReaderAsyncWithLargeQuery(string connectionString)
{
Expand Down Expand Up @@ -743,7 +743,7 @@ public async void TestExecuteReaderAsyncWithLargeQuery(string connectionString)
}
}

[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringSetupForAE))]
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsTargetReadyForAeWithKeyStore))]
[ClassData(typeof(AEConnectionStringProviderWithCommandBehaviorSet1))]
public void TestExecuteReaderWithCommandBehavior(string connection, CommandBehavior commandBehavior)
{
Expand Down Expand Up @@ -868,7 +868,7 @@ public void TestExecuteReaderWithCommandBehavior(string connection, CommandBehav
});
}

[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringSetupForAE))]
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsTargetReadyForAeWithKeyStore))]
[ClassData(typeof(AEConnectionStringProvider))]
public void TestEnclaveStoredProceduresWithAndWithoutParameters(string connectionString)
{
Expand Down Expand Up @@ -915,7 +915,7 @@ public void TestEnclaveStoredProceduresWithAndWithoutParameters(string connectio
}
}

[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringSetupForAE))]
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsTargetReadyForAeWithKeyStore))]
[ClassData(typeof(AEConnectionStringProvider))]
public void TestPrepareWithExecuteNonQuery(string connection)
{
Expand Down Expand Up @@ -964,7 +964,7 @@ public void TestPrepareWithExecuteNonQuery(string connection)
}
}

[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringSetupForAE))]
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsTargetReadyForAeWithKeyStore))]
[ClassData(typeof(AEConnectionStringProvider))]
public void TestAsyncWriteDelayWithExecuteNonQueryAsync(string connection)
{
Expand Down Expand Up @@ -1018,7 +1018,7 @@ public void TestAsyncWriteDelayWithExecuteNonQueryAsync(string connection)
}
}

[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringSetupForAE))]
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsTargetReadyForAeWithKeyStore))]
[ClassData(typeof(AEConnectionStringProvider))]
public void TestAsyncWriteDelayWithExecuteReaderAsync(string connection)
{
Expand Down Expand Up @@ -1085,7 +1085,7 @@ public void TestAsyncWriteDelayWithExecuteReaderAsync(string connection)
}
}

[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringSetupForAE))]
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsTargetReadyForAeWithKeyStore))]
[ClassData(typeof(AEConnectionStringProvider))]
public void TestPrepareWithExecuteNonQueryAsync(string connection)
{
Expand Down Expand Up @@ -1140,7 +1140,7 @@ public void TestPrepareWithExecuteNonQueryAsync(string connection)
}
}

[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringSetupForAE))]
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsTargetReadyForAeWithKeyStore))]
[ClassData(typeof(AEConnectionStringProviderWithCommandBehaviorSet2))]
public void TestPrepareWithExecuteReaderAsync(string connection, CommandBehavior commandBehavior)
{
Expand Down Expand Up @@ -1202,7 +1202,7 @@ public void TestPrepareWithExecuteReaderAsync(string connection, CommandBehavior
}
}

[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringSetupForAE))]
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsTargetReadyForAeWithKeyStore))]
[ClassData(typeof(AEConnectionStringProvider))]
public void TestSqlDataReaderAPIs(string connection)
{
Expand Down Expand Up @@ -1399,7 +1399,7 @@ public void TestSqlDataReaderAPIs(string connection)
}
}

[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringSetupForAE))]
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsTargetReadyForAeWithKeyStore))]
[ClassData(typeof(AEConnectionStringProvider))]
public void TestSqlDataReaderAPIsWithSequentialAccess(string connection)
{
Expand Down Expand Up @@ -1827,7 +1827,7 @@ public void TestSqlDataReaderAPIsWithSequentialAccess(string connection)
}
}

[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringSetupForAE))]
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsTargetReadyForAeWithKeyStore))]
[ClassData(typeof(AEConnectionStringProviderWithCommandBehaviorSet2))]
public void TestSqlCommandSequentialAccessCodePaths(string connection, CommandBehavior value)
{
Expand Down Expand Up @@ -1871,7 +1871,7 @@ public void TestSqlCommandSequentialAccessCodePaths(string connection, CommandBe
}
}

[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringSetupForAE))]
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsTargetReadyForAeWithKeyStore))]
[ClassData(typeof(AEConnectionStringProvider))]
public void TestExecuteXmlReader(string connection)
{
Expand Down Expand Up @@ -2126,7 +2126,7 @@ public void TestSqlCommandCancel(string connection, string value, int number)
}
}

[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringSetupForAE))]
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsTargetReadyForAeWithKeyStore))]
[ClassData(typeof(AEConnectionStringProviderWithCancellationTime))]
public void TestSqlCommandCancellationToken(string connection, int initalValue, int cancellationTime)
{
Expand Down Expand Up @@ -2194,7 +2194,7 @@ public void TestNoneAttestationProtocolWithSGXEnclave()
}
}

[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringSetupForAE))]
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsTargetReadyForAeWithKeyStore))]
[ClassData(typeof(AEConnectionStringProvider))]
public void TestConnectionCustomKeyStoreProviderDuringAeQuery(string connectionString)
{
Expand Down Expand Up @@ -2249,7 +2249,7 @@ public void TestConnectionCustomKeyStoreProviderDuringAeQuery(string connectionS
}
}

[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringSetupForAE))]
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringSetupForAE), nameof(DataTestUtility.IsAKVSetupAvailable))]
[ClassData(typeof(AEConnectionStringProvider))]
public void TestCommandCustomKeyStoreProviderDuringAeQuery(string connectionString)
{
Expand Down Expand Up @@ -2300,7 +2300,7 @@ public void TestCommandCustomKeyStoreProviderDuringAeQuery(string connectionStri
// On Windows, "_fixture" will be type SQLSetupStrategyCertStoreProvider
// On non-Windows, "_fixture" will be type SQLSetupStrategyAzureKeyVault
// Test will pass on both but only SQLSetupStrategyCertStoreProvider is a system provider
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringSetupForAE))]
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsTargetReadyForAeWithKeyStore))]
[ClassData(typeof(AEConnectionStringProvider))]
public void TestSystemProvidersHavePrecedenceOverInstanceLevelProviders(string connectionString)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public BulkCopyAE(PlatformSpecificTestContext context)
tableName = fixture.BulkCopyAETestTable.Name;
}

[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringSetupForAE))]
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsTargetReadyForAeWithKeyStore))]
[ClassData(typeof(AEConnectionStringProvider))]
public void TestBulkCopyString(string connectionString)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public BulkCopyAEErrorMessage(PlatformSpecificTestContext context)
_columnName = "c1";
}

[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringSetupForAE))]
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsTargetReadyForAeWithKeyStore))]
[ClassData(typeof(AEConnectionStringProvider))]
public void TextToIntErrorMessageTest(string connectionString)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public End2EndSmokeTests(PlatformSpecificTestContext context)
}

// tests
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringSetupForAE))]
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsTargetReadyForAeWithKeyStore))]
[ClassData(typeof(TestSelectOnEncryptedNonEncryptedColumnsData))]
public void TestSelectOnEncryptedNonEncryptedColumns(string connString, string selectQuery, int totalColumnsInSelect, string[] types)
{
Expand Down Expand Up @@ -58,7 +58,7 @@ public void TestSelectOnEncryptedNonEncryptedColumns(string connString, string s
}
}

[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringSetupForAE))]
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsTargetReadyForAeWithKeyStore))]
[ClassData(typeof(TestSelectOnEncryptedNonEncryptedColumnsWithEncryptedParametersData))]
public void TestSelectOnEncryptedNonEncryptedColumnsWithEncryptedParameters(string connString,
bool sync,
Expand Down
Loading

0 comments on commit 759dc69

Please sign in to comment.