Skip to content

Commit

Permalink
Native SNI Improvements (#570)
Browse files Browse the repository at this point in the history
  • Loading branch information
cheenamalhotra authored May 21, 2020
1 parent 5cb2181 commit 16faadc
Show file tree
Hide file tree
Showing 31 changed files with 986 additions and 303 deletions.
51 changes: 48 additions & 3 deletions BUILDGUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ This document provides all the necessary details to build the driver and run tes
## Visual Studio Pre-Requisites

This project should be ideally built with Visual Studio 2017+ for the best compatibility. Use either of the two environments with their required set of compoenents as mentioned below:
- **Visual Studio 2017** with imported components: [VS17Components](/tools/vsconfig/VS17Components.vsconfig)
- **Visual Studio 2019** with imported components: [VS19Components](/tools/vsconfig/VS19Components.vsconfig)

Once the environment is setup properly, execute the desired set of commands below from the _root_ folder to perform the respective operations:
Expand Down Expand Up @@ -115,6 +114,7 @@ Manual Tests require the below setup to run:
|SupportsLocalDb | (Optional) Whether or not a LocalDb instance of SQL Server is installed on the machine running the tests. |`true` OR `false`|
|SupportsIntegratedSecurity | (Optional) Whether or not the USER running tests has integrated security access to the target SQL Server.| `true` OR `false`|
|SupportsFileStream | (Optional) Whether or not FileStream is enabled on SQL Server| `true` OR `false`|
|UseManagedSNIOnWindows | (Optional) Enables testing with Managed SNI on Windows| `true` OR `false`|

Commands to run tests:

Expand All @@ -140,7 +140,53 @@ Unix (`netcoreapp`):

## Run A Single Test
```bash
> dotnet test "src\Microsoft.Data.SqlClient\tests\ManualTests\Microsoft.Data.SqlClient.ManualTesting.Tests.csproj" /p:Platform="AnyCPU" /p:Configuration="Debug" /p:TestTargetOS="Windowsnetcoreapp" --no-build -v n --filter "FullyQualifiedName=Microsoft.Data.SqlClient.ManualTesting.Tests.AlwaysEncrypted.CspProviderExt.TestKeysFromCertificatesCreatedWithMultipleCryptoProviders"
> dotnet test "src\Microsoft.Data.SqlClient\tests\ManualTests\Microsoft.Data.SqlClient.ManualTesting.Tests.csproj" /p:Platform="AnyCPU" /p:Configuration="Release" /p:TestTargetOS="Windowsnetcoreapp" --no-build -v n --filter "FullyQualifiedName=Microsoft.Data.SqlClient.ManualTesting.Tests.AlwaysEncrypted.CspProviderExt.TestKeysFromCertificatesCreatedWithMultipleCryptoProviders"
```

## Testing with Custom ReferenceType

Tests can be built and run with custom "Reference Type" property that enables different styles of testing:

- "Project" => Build and run tests with Microsoft.Data.SqlClient as Project Reference
- "Package" => Build and run tests with Microsoft.Data.SqlClient as Package Reference with configured "TestMicrosoftDataSqlClientVersion" in "Versions.props" file.
- "NetStandard" => Build and run tests with Microsoft.Data.SqlClient as Project Reference via .NET Standard Library
- "NetStandardPackage" => Build and run tests with Microsoft.Data.SqlClient as Package Reference via .NET Standard Library

> ************** IMPORTANT NOTE BEFORE PROCEEDING WITH "PACKAGE" AND "NETSTANDARDPACKAGE" REFERENCE TYPES ***************
> CREATE A NUGET PACKAGE WITH BELOW COMMAND AND ADD TO LOCAL FOLDER + UPDATE NUGET CONFIG FILE TO READ FROM THAT LOCATION
> ```
> > msbuild /p:configuration=Release
> ```
### Building Tests:
For .NET Core, all 4 reference types are supported:
```bash
> msbuild /t:BuildTestsNetCore /p:ReferenceType=Project
# Default setting uses Project Reference.
> msbuild /t:BuildTestsNetCore /p:ReferenceType=Package
> msbuild /t:BuildTestsNetCore /p:ReferenceType=NetStandard
> msbuild /t:BuildTestsNetCore /p:ReferenceType=NetStandardPackage
```
For .NET Framework, below reference types are supported:

```bash
> msbuild /t:BuildTestsNetCore /p:ReferenceType=Project
# Default setting uses Project Reference.

> msbuild /t:BuildTestsNetCore /p:ReferenceType=Package
```

### Running Tests:

Provide property to `dotnet test` commands for testing desired reference type.
```
dotnet test /p:ReferenceType=Project ...
```

## Testing with Custom TargetFramework
Expand Down Expand Up @@ -214,4 +260,3 @@ There may be times where connection cannot be made to SQL Server, we found below
<TargetsWindows>false</TargetsWindows>
<TargetsUnix>true</TargetsUnix>
```
```
216 changes: 195 additions & 21 deletions RunTests.cmd

Large diffs are not rendered by default.

65 changes: 39 additions & 26 deletions build.proj
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Latest" DefaultTargets="BuildAllConfigurations"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<?xml version="1.0" encoding="utf-8" ?>
<Project ToolsVersion="Latest" DefaultTargets="BuildAllConfigurations" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<Import Project="src/Directory.Build.props" />
<Import Project="$(ToolsDir)targets\GenerateNugetPackage.targets" />
Expand All @@ -22,18 +21,20 @@

<!-- Populate all managed projects -->
<ItemGroup>
<NetFxDriver Include="**/netfx/**/Microsoft.Data.SqlClient*.csproj" Condition="'$(IsEnabledWindows)' == 'true'"/>
<NetCoreDriver Include="**/netcore/**/Microsoft.Data.SqlClient*.csproj"/>
<AKVProvider Include="**/add-ons/**/AzureKeyVaultProvider/*.csproj"/>
<NetFxDriver Include="**/netfx/**/Microsoft.Data.SqlClient*.csproj" Condition="'$(IsEnabledWindows)' == 'true'" />
<NetCoreDriver Include="**/netcore/**/Microsoft.Data.SqlClient*.csproj" />
<AKVProvider Include="**/add-ons/**/AzureKeyVaultProvider/*.csproj" />

<FunctionalTests Include="**/NSLibrary/Microsoft.Data.SqlClient.NSLibrary.csproj" />
<FunctionalTests Include="**/tools/TDS/TDS/TDS.csproj" />
<FunctionalTests Include="**/tools/TDS/TDS.EndPoint/TDS.EndPoint.csproj" />
<FunctionalTests Include="**/tools/TDS/TDS.Servers/TDS.Servers.csproj" />
<FunctionalTests Include="**/tools/Microsoft.DotNet.XUnitExtensions/Microsoft.DotNet.XUnitExtensions.csproj" />
<FunctionalTests Include="**/tools/Microsoft.DotNet.XUnitExtensions/Microsoft.DotNet.XUnitExtensions.csproj" />
<FunctionalTests Include="**/tools/CoreFx.Private.TestUtilities/CoreFx.Private.TestUtilities.csproj" />
<FunctionalTests Include="**/ManualTests/SQL/UdtTest/UDTs/Address/Address.csproj" />
<FunctionalTests Include="**/Microsoft.Data.SqlClient.Tests.csproj" />

<ManualTests Include="**/NSLibrary/Microsoft.Data.SqlClient.NSLibrary.csproj" />
<ManualTests Include="**/ManualTests/SQL/UdtTest/UDTs/Address/Address.csproj" />
<ManualTests Include="**/ManualTests/SQL/UdtTest/UDTs/Circle/Circle.csproj" />
<ManualTests Include="**/ManualTests/SQL/UdtTest/UDTs/Shapes/Shapes.csproj" />
Expand All @@ -47,23 +48,29 @@
<Target Name="Restore" DependsOnTargets="RestoreNetCore;RestoreNetFx" />
<Target Name="BuildAll" DependsOnTargets="BuildNetFx;BuildNetCore" />
<Target Name="BuildAllConfigurations" DependsOnTargets="Restore;BuildNetFx;BuildNetCoreAllOS;GenerateNugetPackage" />
<Target Name="BuildTestsNetCore" DependsOnTargets="BuildAKVNetCore;BuildFunctionalTestsNetCore;BuildManualTestsNetCore" />
<Target Name="BuildTestsNetFx" DependsOnTargets="BuildAKVNetFx;BuildFunctionalTestsNetFx;BuildManualTestsNetFx;" />
<Target Name="BuildTestsNetCore" DependsOnTargets="RestoreTestsNetCore;BuildAKVNetCore;BuildFunctionalTestsNetCore;BuildManualTestsNetCore" />
<Target Name="BuildTestsNetFx" DependsOnTargets="RestoreTestsNetFx;BuildAKVNetFx;BuildFunctionalTestsNetFx;BuildManualTestsNetFx;" />

<Target Name="RestoreNetCore">
<MSBuild Projects="@(NetCoreDriver)" Targets="restore" Properties="TestTargetOS=$(TestOS)netcoreapp" />
</Target>

<Target Name="RestoreTestsNetCore">
<MSBuild Projects="@(ManualTests)" Targets="restore" Properties="TestTargetOS=$(TestOS)netcoreapp" />
<MSBuild Projects="@(FunctionalTests)" Targets="restore" Properties="TestTargetOS=$(TestOS)netcoreapp" />
</Target>

<Target Name="RestoreNetFx" Condition="'$(IsEnabledWindows)' == 'true'">
<MSBuild Projects="@(NetFxDriver)" Targets="restore" Properties="TestTargetOS=$(TestOS)netfx" />
</Target>

<Target Name="RestoreTestsNetFx">
<MSBuild Projects="@(ManualTests)" Targets="restore" Properties="TestTargetOS=$(TestOS)netfx" />
<MSBuild Projects="@(FunctionalTests)" Targets="restore" Properties="TestTargetOS=$(TestOS)netfx" />
</Target>

<Target Name="BuildNetFx" DependsOnTargets="RestoreNetFx" Condition="'$(IsEnabledWindows)' == 'true'">
<MSBuild Projects="@(NetFxDriver)" Properties="Platform=AnyCPU;$(ProjectProperties)" />
<MSBuild Projects="@(NetFxDriver)" Properties="Platform=AnyCPU;$(ProjectProperties)" />
</Target>

<Target Name="BuildNetCore" DependsOnTargets="RestoreNetCore">
Expand All @@ -76,45 +83,51 @@
<MSBuild Projects="@(NetCoreDriver)" Properties="$(ProjectProperties);Platform=AnyCPU;OSGroup=AnyOS;" RemoveProperties="TargetsWindows;TargetsUnix;" />
</Target>

<Target Name="BuildFunctionalTestsNetCore" DependsOnTargets="RestoreNetCore">
<MSBuild Projects="@(FunctionalTests)" Properties="TestTargetOS=$(TestOS)netcoreapp;$(TestProjectProperties);Platform=AnyCPU;" />
<Target Name="BuildFunctionalTestsNetCore" DependsOnTargets="RestoreTestsNetCore">
<!-- Only build platform specific builds for Package reference types -->
<MSBuild Projects="@(FunctionalTests)" Properties="TestTargetOS=$(TestOS)netcoreapp;$(TestProjectProperties);Platform=AnyCPU;" Condition="!$(ReferenceType.Contains('Package'))" />
<MSBuild Projects="@(FunctionalTests)" Properties="TestTargetOS=$(TestOS)netcoreapp;$(TestProjectProperties);Platform=$(Platform);" Condition="$(ReferenceType.Contains('Package'))"/>
</Target>

<Target Name="BuildManualTestsNetCore" DependsOnTargets="RestoreNetCore">
<MSBuild Projects="@(ManualTests)" Properties="TestTargetOS=$(TestOS)netcoreapp;$(TestProjectProperties);Platform=AnyCPU;" />
<Target Name="BuildManualTestsNetCore" DependsOnTargets="RestoreTestsNetCore">
<!-- Only build platform specific builds for Package reference types -->
<MSBuild Projects="@(ManualTests)" Properties="TestTargetOS=$(TestOS)netcoreapp;$(TestProjectProperties);Platform=AnyCPU;" Condition="!$(ReferenceType.Contains('Package'))"/>
<MSBuild Projects="@(ManualTests)" Properties="TestTargetOS=$(TestOS)netcoreapp;$(TestProjectProperties);Platform=$(Platform);" Condition="$(ReferenceType.Contains('Package'))"/>
</Target>

<Target Name="BuildFunctionalTestsNetFx" DependsOnTargets="RestoreNetFx" Condition="'$(IsEnabledWindows)' == 'true'">
<!-- Only build platform specific tests on Windows for .NET Framework -->
<Target Name="BuildFunctionalTestsNetFx" DependsOnTargets="RestoreTestsNetFx;BuildNetFx" Condition="'$(IsEnabledWindows)' == 'true'">
<MSBuild Projects="@(FunctionalTests)" Properties="TestTargetOS=$(TestOS)netfx;$(TestProjectProperties);Platform=$(Platform);" />
</Target>

<Target Name="BuildManualTestsNetFx" DependsOnTargets="RestoreNetFx" Condition="'$(IsEnabledWindows)' == 'true'">
<Target Name="BuildManualTestsNetFx" DependsOnTargets="RestoreTestsNetFx;BuildNetFx" Condition="'$(IsEnabledWindows)' == 'true'">
<MSBuild Projects="@(ManualTests)" Properties="TestTargetOS=$(TestOS)netfx;$(TestProjectProperties);Platform=$(Platform);" />
</Target>

<Target Name="Clean">
<RemoveDir Directories='$([System.IO.Directory]::GetDirectories(".","artifacts", SearchOption.AllDirectories))' />
<RemoveDir Directories='$([System.IO.Directory]::GetDirectories(".","bin", SearchOption.AllDirectories))' />
<RemoveDir Directories='$([System.IO.Directory]::GetDirectories(".","obj", SearchOption.AllDirectories))' />
<RemoveDir Directories='$([System.IO.Directory]::GetDirectories(".","packages", SearchOption.AllDirectories))' />
<RemoveDir Directories='$([System.IO.Directory]::GetDirectories(".",".nuget", SearchOption.AllDirectories))' />
</Target>

<Target Name="BuildAKVNetFx" Condition="'$(IsEnabledWindows)' == 'true'">
<Target Name="BuildAKVNetFx" Condition="'$(IsEnabledWindows)' == 'true' AND !$(ReferenceType.Contains('NetStandard'))">
<MSBuild Projects="@(AKVProvider)" Targets="restore" Properties="TestTargetOS=$(TestOS)netfx" />
<MSBuild Projects="@(AKVProvider)" Properties="TestTargetOS=$(TestOS)netfx;Platform=$(Platform);$(TestProjectProperties)" />
</Target>

<Target Name="BuildAKVNetCore">
<Target Name="BuildAKVNetCore" Condition="!$(ReferenceType.Contains('NetStandard'))">
<MSBuild Projects="@(AKVProvider)" Targets="restore" Properties="TestTargetOS=$(TestOS)netcoreapp" />
<MSBuild Projects="@(AKVProvider)" Properties="TestTargetOS=$(TestOS)netcoreapp;$(ProjectProperties);Platform=AnyCPU;OSGroup=Unix;" />
<!-- Only build platform specific builds for Package reference types -->
<MSBuild Projects="@(AKVProvider)" Properties="TestTargetOS=$(TestOS)netcoreapp;$(ProjectProperties);Platform=AnyCPU;" Condition="!$(ReferenceType.Contains('Package'))"/>
<MSBuild Projects="@(AKVProvider)" Properties="TestTargetOS=$(TestOS)netcoreapp;$(ProjectProperties);Platform=$(Platform);" Condition="$(ReferenceType.Contains('Package'))"/>
</Target>
<Target Name="BuildAKVNetCoreAllOS">

<Target Name="BuildAKVNetCoreAllOS" Condition="!$(ReferenceType.Contains('NetStandard'))">
<MSBuild Projects="@(AKVProvider)" Targets="restore" Properties="TestTargetOS=$(TestOS)netcoreapp" />
<MSBuild Projects="@(AKVProvider)" Properties="TestTargetOS=$(TestOS)netcoreapp;$(ProjectProperties);Platform=AnyCPU;OSGroup=Unix;" RemoveProperties="TargetsWindows;TargetsUnix;" />
<MSBuild Projects="@(AKVProvider)" Properties="TestTargetOS=$(TestOS)netcoreapp;$(ProjectProperties);Platform=AnyCPU;OSGroup=Windows_NT;" RemoveProperties="TargetsWindows;TargetsUnix;" Condition="'$(IsEnabledWindows)' == 'true'"/>
<MSBuild Projects="@(AKVProvider)" Properties="TestTargetOS=$(TestOS)netcoreapp;$(ProjectProperties);Platform=AnyCPU;OSGroup=AnyOS;" RemoveProperties="TargetsWindows;TargetsUnix;" />
<MSBuild Projects="@(AKVProvider)" Properties="TestTargetOS=$(TestOS)netcoreapp;$(ProjectProperties);Platform=AnyCPU;OSGroup=Unix;" RemoveProperties="TargetsWindows;TargetsUnix;" />
<MSBuild Projects="@(AKVProvider)" Properties="TestTargetOS=$(TestOS)netcoreapp;$(ProjectProperties);Platform=AnyCPU;OSGroup=Windows_NT;" RemoveProperties="TargetsWindows;TargetsUnix;" Condition="'$(IsEnabledWindows)' == 'true'" />
<MSBuild Projects="@(AKVProvider)" Properties="TestTargetOS=$(TestOS)netcoreapp;$(ProjectProperties);Platform=AnyCPU;OSGroup=AnyOS;" RemoveProperties="TargetsWindows;TargetsUnix;" />
</Target>

</Project>
28 changes: 19 additions & 9 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,44 @@
<TargetsUnix Condition="'$(OSGroup)' == 'Unix'">true</TargetsUnix>
<TargetsAnyOS Condition="'$(OSGroup)' == 'AnyOS'">true</TargetsAnyOS>
<IsSourceProject Condition="$([System.Text.RegularExpressions.Regex]::IsMatch($(MSBuildProjectDirectory), 'src%24'))">true</IsSourceProject>
<!--
"ReferenceType" property supports below options:
"Project" => Build and run tests with Microsoft.Data.SqlClient as Project Reference
"Package" => Build and run tests with Microsoft.Data.SqlClient as Package Reference with configured "TestMicrosoftDataSqlClientVersion" in "Versions.props" file.
"NetStandard" => Build and run tests with Microsoft.Data.SqlClient as Project Reference via .NET Standard Library
"NetStandardPackage" => Build and run tests with Microsoft.Data.SqlClient as Package Reference via .NET Standard Library
************** IMPORTANT NOTE BEFORE PROCEEDING WITH "PACKAGE" AND "NETSTANDARDPACKAGE" REFERENCE TYPES ***************
CREATE A NUGET PACKAGE WITH BELOW COMMAND AND ADD TO LOCAL FOLDER + UPDATE NUGET CONFIG FILE TO READ FROM THAT LOCATION
> msbuild /p:configuration=Release
-->
<ReferenceType Condition="$(ReferenceType) == ''">Project</ReferenceType>
</PropertyGroup>
<PropertyGroup Condition="$(Configuration.Contains('Debug'))">
<DefineConstants>$(DefineConstants);DEBUG</DefineConstants>
</PropertyGroup>
<PropertyGroup>
<ProjectDir>$(MSBuildThisFileDirectory)</ProjectDir>
<RepoRoot>$(ProjectDir)..\</RepoRoot>
<Artifacts>$(RepoRoot)artifacts\$(ReferenceType)\</Artifacts>
<ManagedSourceCode>$(ProjectDir)Microsoft.Data.SqlClient\</ManagedSourceCode>
<NetCoreSource>$(ManagedSourceCode)netcore\</NetCoreSource>
<NetFxSource>$(ManagedSourceCode)netfx\</NetFxSource>
<NetFxResources>$(ManagedSourceCode)netfx\src\Resources\</NetFxResources>
<ObjFolder>$(RepoRoot)obj\</ObjFolder>
<AddOnsPath>$(ManagedSourceCode)add-ons\</AddOnsPath>
<ObjFolder>$(Artifacts)obj\</ObjFolder>
<CommonPath>$(NetCoreSource)src\Common\src</CommonPath>
<CommonTestPath>$(NetCoreSource)src\Common\tests</CommonTestPath>
<TestsPath>$(ProjectDir)Microsoft.Data.SqlClient\tests\</TestsPath>
<BinFolder Condition="'$(TargetsWindows)' == 'true'">$(RepoRoot)bin\Windows_NT\</BinFolder>
<BinFolder Condition="'$(TargetsAnyOS)' == 'true'">$(RepoRoot)bin\AnyOS\</BinFolder>
<BinFolder Condition="'$(TargetsUnix)' == 'true'">$(RepoRoot)bin\Unix\</BinFolder>
<BinFolder Condition="'$(TargetsWindows)' == 'true'">$(Artifacts)bin\Windows_NT\</BinFolder>
<BinFolder Condition="'$(TargetsAnyOS)' == 'true'">$(Artifacts)bin\AnyOS\</BinFolder>
<BinFolder Condition="'$(TargetsUnix)' == 'true'">$(Artifacts)bin\Unix\</BinFolder>
<ToolsDir Condition="'$(ToolsDir)'==''">$(RepoRoot)tools\</ToolsDir>
<PackagesDir Condition="'$(PackagesDir)'==''">$(RepoRoot)packages\</PackagesDir>
<NuGetRoot Condition="'$(NuGetRoot)' == ''">$(RepoRoot).nuget\</NuGetRoot>
<NuGetCmd>$(NuGetRoot)nuget.exe</NuGetCmd>
<!-- Respect environment variable for the .NET install directory if set; otherwise, use the current default location -->
<DotNetRoot Condition="'$(DotNetRoot)' == ''">$(DOTNET_INSTALL_DIR)</DotNetRoot>
<DotNetRoot Condition="'$(DotNetRoot)' == ''">$(RepoRoot).dotnet\</DotNetRoot>
<DotNetRoot Condition="!HasTrailingSlash('$(DotNetRoot)')">$(DotNetRoot)\</DotNetRoot>
<DotNetCmd>$(DotNetRoot)dotnet</DotNetCmd>
<DotNetCmd Condition="'$(OS)' == 'Windows_NT'">$(DotNetCmd).exe</DotNetCmd>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<BuildSimulator Condition="'$(BuildSimulator)' != 'true'">false</BuildSimulator>
</PropertyGroup>
Expand Down
Loading

0 comments on commit 16faadc

Please sign in to comment.