From 4663a85f5549e8de988cdacbfef989a74ec0f346 Mon Sep 17 00:00:00 2001 From: Cheena Malhotra Date: Fri, 23 Oct 2020 16:10:28 -0700 Subject: [PATCH 1/2] Attempt to fix build --- .../netcore/src/Microsoft/Data/SqlClient/SqlUtil.cs | 2 -- .../netfx/src/Microsoft/Data/SqlClient/SqlUtil.cs | 2 -- .../FunctionalTests/Microsoft.Data.SqlClient.Tests.csproj | 3 ++- .../tests/FunctionalTests/SqlHelperTest.cs | 1 + 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlUtil.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlUtil.cs index 056b0fcebf..5ddd978093 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlUtil.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlUtil.cs @@ -17,8 +17,6 @@ using System.Transactions; using Microsoft.Data.Common; -[assembly: InternalsVisibleTo("FunctionalTests")] - namespace Microsoft.Data.SqlClient { internal static class AsyncHelper diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlUtil.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlUtil.cs index 0cc0276d6f..efdbe12778 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlUtil.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlUtil.cs @@ -17,8 +17,6 @@ using System.Threading.Tasks; using SysTx = System.Transactions; -[assembly: InternalsVisibleTo("FunctionalTests")] - namespace Microsoft.Data.SqlClient { using Microsoft.Data.Common; diff --git a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/Microsoft.Data.SqlClient.Tests.csproj b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/Microsoft.Data.SqlClient.Tests.csproj index e93c6c867f..491de408b3 100644 --- a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/Microsoft.Data.SqlClient.Tests.csproj +++ b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/Microsoft.Data.SqlClient.Tests.csproj @@ -42,7 +42,6 @@ - @@ -54,6 +53,8 @@ + + diff --git a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlHelperTest.cs b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlHelperTest.cs index 30152bd2c3..6851671839 100644 --- a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlHelperTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlHelperTest.cs @@ -11,6 +11,7 @@ namespace Microsoft.Data.SqlClient.Tests { public class SqlHelperTest { + // This test is skipped on .NET Framework as AsyncHelper cannot be accessed from a Strong name assembly. private void TimeOutATask() { TaskCompletionSource tcs = new TaskCompletionSource(); From eb51963102cd80dd4dba570d7a12908a9e78b3f7 Mon Sep 17 00:00:00 2001 From: Cheena Malhotra Date: Fri, 23 Oct 2020 16:41:22 -0700 Subject: [PATCH 2/2] Use reflection instead --- .../Microsoft.Data.SqlClient.Tests.csproj | 3 +-- .../tests/FunctionalTests/SqlHelperTest.cs | 10 ++++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/Microsoft.Data.SqlClient.Tests.csproj b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/Microsoft.Data.SqlClient.Tests.csproj index 491de408b3..8e4650fa4f 100644 --- a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/Microsoft.Data.SqlClient.Tests.csproj +++ b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/Microsoft.Data.SqlClient.Tests.csproj @@ -53,8 +53,7 @@ - - + diff --git a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlHelperTest.cs b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlHelperTest.cs index 6851671839..087e5b5c57 100644 --- a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlHelperTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlHelperTest.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System; +using System.Reflection; using System.Threading; using System.Threading.Tasks; using Xunit; @@ -11,11 +12,16 @@ namespace Microsoft.Data.SqlClient.Tests { public class SqlHelperTest { - // This test is skipped on .NET Framework as AsyncHelper cannot be accessed from a Strong name assembly. private void TimeOutATask() { + var sqlClientAssembly = Assembly.GetAssembly(typeof(SqlCommand)); + //We're using reflection to avoid exposing the internals + MethodInfo waitForCompletion = sqlClientAssembly.GetType("Microsoft.Data.SqlClient.AsyncHelper") + ?.GetMethod("WaitForCompletion", BindingFlags.Static | BindingFlags.NonPublic); + + Assert.False(waitForCompletion == null, "Running a test on SqlUtil.WaitForCompletion but could not find this method"); TaskCompletionSource tcs = new TaskCompletionSource(); - AsyncHelper.WaitForCompletion(tcs.Task, 1); //Will time out as task uncompleted + waitForCompletion.Invoke(null, new object[] { tcs.Task, 1, null, true }); //Will time out as task uncompleted tcs.SetException(new TimeoutException("Dummy timeout exception")); //Our task now completes with an error }