Skip to content

Commit 6e4eb0a

Browse files
caleblloydbgrainger
authored andcommitted
Support netstandard2.0 preview.
1 parent f109f0c commit 6e4eb0a

File tree

16 files changed

+131
-54
lines changed

16 files changed

+131
-54
lines changed

.ci/build.ps1

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function DownloadWithRetry([string] $url, [string] $downloadLocation, [int] $ret
3131
$repoFolder = Join-Path $PSScriptRoot ..
3232
$env:REPO_FOLDER = $repoFolder
3333

34-
$koreBuildZip="https://github.com/aspnet/KoreBuild/archive/rel/1.0.0-msbuild-rtm.zip"
34+
$koreBuildZip="https://github.com/aspnet/KoreBuild/archive/rel/2.0.0-preview1.zip"
3535
if ($env:KOREBUILD_ZIP)
3636
{
3737
$koreBuildZip=$env:KOREBUILD_ZIP
@@ -61,21 +61,31 @@ if (!(Test-Path $buildFolder)) {
6161
}
6262
}
6363

64-
$dotnetVersion = "1.0.3"
65-
$dotnetChannel = "rel-1.0.0"
66-
$dotnetSharedRuntimeVersion = "1.1.1"
67-
$dotnetSharedRuntimeChannel = "rel-1.0.0"
64+
$dotnetArch = 'x64'
65+
$dotnetChannel = "preview"
66+
$dotnetVersion = "2.0.0-preview1-005957"
6867

6968
$dotnetLocalInstallFolder = $env:DOTNET_INSTALL_DIR
7069
if (!$dotnetLocalInstallFolder)
7170
{
7271
$dotnetLocalInstallFolder = "$env:LOCALAPPDATA\Microsoft\dotnet\"
7372
}
7473

75-
& "$buildFolder\dotnet\dotnet-install.ps1" -Channel $dotnetChannel -Version $dotnetVersion -Architecture x64
76-
# Avoid redownloading the CLI if it's already installed.
77-
$sharedRuntimePath = [IO.Path]::Combine($dotnetLocalInstallFolder, 'shared', 'Microsoft.NETCore.App', $dotnetSharedRuntimeVersion)
78-
if (!(Test-Path $sharedRuntimePath))
74+
function InstallSharedRuntime([string] $version, [string] $channel)
7975
{
80-
& "$buildFolder\dotnet\dotnet-install.ps1" -Channel $dotnetSharedRuntimeChannel -SharedRuntime -Version $dotnetSharedRuntimeVersion -Architecture x64
76+
$sharedRuntimePath = [IO.Path]::Combine($dotnetLocalInstallFolder, 'shared', 'Microsoft.NETCore.App', $version)
77+
# Avoid redownloading the CLI if it's already installed.
78+
if (!(Test-Path $sharedRuntimePath))
79+
{
80+
& "$buildFolder\dotnet\dotnet-install.ps1" -Channel $channel `
81+
-SharedRuntime `
82+
-Version $version `
83+
-Architecture $dotnetArch `
84+
-InstallDir $dotnetLocalInstallFolder
85+
}
8186
}
87+
88+
& "$buildFolder\dotnet\dotnet-install.ps1" -Channel $dotnetChannel -Version $dotnetVersion -Architecture $dotnetArch
89+
InstallSharedRuntime -version "1.1.2" -channel "release/1.1.0"
90+
91+
dotnet --info

.ci/test.ps1

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
$ErrorActionPreference = "Stop"
2-
31
# restore
42
dotnet restore
53
if ($LASTEXITCODE -ne 0){

.travis.yml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,20 @@ before_install:
1111
- sudo sh -c 'echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet-release/ trusty main" > /etc/apt/sources.list.d/dotnetdev.list'
1212
- sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 417A0893
1313
- sudo apt-get update
14-
- sudo apt-get install -y dotnet-dev-1.0.1
14+
- sudo apt-get install -y dotnet-dev-2.0.0-preview1-005977 dotnet-sharedframework-microsoft.netcore.app-1.1.2
1515

1616
script:
1717
- dotnet restore
18-
- dotnet test tests/MySqlConnector.Tests/MySqlConnector.Tests.csproj -c Release -f netcoreapp1.1.1
19-
- dotnet build tests/SideBySide/SideBySide.csproj -c Release -f netcoreapp1.1.1
20-
- echo 'Executing tests with No Compression, No SSL' && ./.ci/use-config.sh config.json 172.17.0.1 3307 && time dotnet test tests/SideBySide/SideBySide.csproj -c Release -f netcoreapp1.1.1
21-
- echo 'Executing Debug Only tests' && time dotnet test tests/SideBySide/SideBySide.csproj -c Debug -f netcoreapp1.1.1 --filter "FullyQualifiedName~SideBySide.DebugOnlyTests"
22-
- echo 'Executing tests with Compression, No SSL' && ./.ci/use-config.sh config.compression.json 172.17.0.1 3307 && time dotnet test tests/SideBySide/SideBySide.csproj -c Release -f netcoreapp1.1.1
23-
- echo 'Executing tests with No Compression, SSL' && ./.ci/use-config.sh config.ssl.json 172.17.0.1 3307 && time dotnet test tests/SideBySide/SideBySide.csproj -c Release -f netcoreapp1.1.1
24-
- echo 'Executing tests with Compression, SSL' && ./.ci/use-config.sh config.compression+ssl.json 172.17.0.1 3307 && time dotnet test tests/SideBySide/SideBySide.csproj -c Release -f netcoreapp1.1.1
25-
- echo 'Executing tests with Unix Domain Socket, No Compression, No SSL' && ./.ci/use-config.sh config.uds.json && time dotnet test tests/SideBySide/SideBySide.csproj -c Release -f netcoreapp1.1.1
26-
- echo 'Executing tests with Buffering, No Compression, No SSL' && ./.ci/use-config.sh config.buffer.json 172.17.0.1 3307 && time dotnet test tests/SideBySide/SideBySide.csproj -c Release -f netcoreapp1.1.1
18+
- dotnet test tests/MySqlConnector.Tests/MySqlConnector.Tests.csproj -c Release -f netcoreapp2.0
19+
- dotnet build tests/SideBySide/SideBySide.csproj -c Release -f netcoreapp2.0
20+
- echo 'Executing netcoreapp1.1.2 tests with No Compression, No SSL' && ./.ci/use-config.sh config.json 172.17.0.1 3307 && time dotnet test tests/SideBySide/SideBySide.csproj -c Release -f netcoreapp1.1.2
21+
- echo 'Executing netcoreapp2.0 tests with No Compression, No SSL' && ./.ci/use-config.sh config.json 172.17.0.1 3307 && time dotnet test tests/SideBySide/SideBySide.csproj -c Release -f netcoreapp2.0
22+
- echo 'Executing netcoreapp2.0 Debug Only tests' && time dotnet test tests/SideBySide/SideBySide.csproj -c Debug -f netcoreapp2.0 --filter "FullyQualifiedName~SideBySide.DebugOnlyTests"
23+
- echo 'Executing netcoreapp2.0 tests with Compression, No SSL' && ./.ci/use-config.sh config.compression.json 172.17.0.1 3307 && time dotnet test tests/SideBySide/SideBySide.csproj -c Release -f netcoreapp2.0
24+
- echo 'Executing netcoreapp2.0 tests with No Compression, SSL' && ./.ci/use-config.sh config.ssl.json 172.17.0.1 3307 && time dotnet test tests/SideBySide/SideBySide.csproj -c Release -f netcoreapp2.0
25+
- echo 'Executing netcoreapp2.0 tests with Compression, SSL' && ./.ci/use-config.sh config.compression+ssl.json 172.17.0.1 3307 && time dotnet test tests/SideBySide/SideBySide.csproj -c Release -f netcoreapp2.0
26+
- echo 'Executing netcoreapp2.0 tests with Unix Domain Socket, No Compression, No SSL' && ./.ci/use-config.sh config.uds.json && time dotnet test tests/SideBySide/SideBySide.csproj -c Release -f netcoreapp2.0
27+
- echo 'Executing netcoreapp2.0 tests with Buffering, No Compression, No SSL' && ./.ci/use-config.sh config.buffer.json 172.17.0.1 3307 && time dotnet test tests/SideBySide/SideBySide.csproj -c Release -f netcoreapp2.0
2728

2829
after_script:
2930
- chmod +x .ci/build-docs.sh && ./.ci/build-docs.sh

src/MySqlConnector/MySqlClient/MySqlConnection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ internal async Task<CachedProcedure> GetCachedProcedure(IOBehavior ioBehavior, s
300300

301301
private async Task<MySqlSession> CreateSessionAsync(IOBehavior ioBehavior, CancellationToken cancellationToken)
302302
{
303-
var connectTimeout = m_connectionSettings.ConnectionTimeout == 0 ? Timeout.InfiniteTimeSpan : TimeSpan.FromSeconds(checked((int) m_connectionSettings.ConnectionTimeout));
303+
var connectTimeout = m_connectionSettings.ConnectionTimeout == 0 ? Timeout.InfiniteTimeSpan : TimeSpan.FromMilliseconds(m_connectionSettings.ConnectionTimeoutMilliseconds);
304304
using (var timeoutSource = new CancellationTokenSource(connectTimeout))
305305
using (var linkedSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, timeoutSource.Token))
306306
{

src/MySqlConnector/MySqlConnector.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<AssemblyTitle>Async MySQL Connector</AssemblyTitle>
88
<VersionPrefix>0.20.1</VersionPrefix>
99
<Authors>Bradley Grainger;Caleb Lloyd</Authors>
10-
<TargetFrameworks>net451;netstandard1.3</TargetFrameworks>
10+
<TargetFrameworks>net451;netstandard1.3;netstandard2.0</TargetFrameworks>
1111
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
1212
<AssemblyName>MySqlConnector</AssemblyName>
1313
<PackageId>MySqlConnector</PackageId>
@@ -28,7 +28,7 @@
2828
<Reference Include="System.Transactions" />
2929
</ItemGroup>
3030

31-
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
31+
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' OR '$(TargetFramework)' == 'netstandard2.0' ">
3232
<PackageReference Include="System.Buffers" Version="4.3.0" />
3333
<PackageReference Include="System.Data.Common" Version="4.3.0" />
3434
<PackageReference Include="System.Net.NameResolution" Version="4.3.0" />

src/MySqlConnector/Serialization/ConnectionSettings.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,30 @@ public ConnectionSettings(MySqlConnectionStringBuilder csb)
9595
public bool TreatTinyAsBoolean { get; }
9696
public bool UseAffectedRows { get; }
9797
public bool UseCompression { get; }
98+
99+
// Helper Functions
100+
private int? _connectionTimeoutMilliseconds;
101+
public int ConnectionTimeoutMilliseconds
102+
{
103+
get
104+
{
105+
if (!_connectionTimeoutMilliseconds.HasValue)
106+
{
107+
try
108+
{
109+
checked
110+
{
111+
_connectionTimeoutMilliseconds = ConnectionTimeout * 1000;
112+
}
113+
}
114+
catch (OverflowException)
115+
{
116+
_connectionTimeoutMilliseconds = Int32.MaxValue;
117+
}
118+
}
119+
return _connectionTimeoutMilliseconds.Value;
120+
}
121+
}
122+
98123
}
99124
}

src/MySqlConnector/Serialization/MySqlSession.cs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,12 @@ public async Task ConnectAsync(ConnectionSettings cs, IOBehavior ioBehavior, Can
203203
throw new MySqlException("Unable to connect to any of the specified MySQL hosts.");
204204
}
205205

206-
var socketByteHandler = new SocketByteHandler(m_socket);
207-
m_payloadHandler = new StandardPayloadHandler(socketByteHandler);
206+
#if NETSTANDARD2_0
207+
var byteHandler = new StreamByteHandler(m_networkStream);
208+
#else
209+
var byteHandler = new SocketByteHandler(m_socket);
210+
#endif
211+
m_payloadHandler = new StandardPayloadHandler(byteHandler);
208212

209213
var payload = await ReceiveAsync(ioBehavior, cancellationToken).ConfigureAwait(false);
210214
var reader = new ByteArrayReader(payload.ArraySegment.Array, payload.ArraySegment.Offset, payload.ArraySegment.Count);
@@ -321,6 +325,9 @@ public async Task<bool> TryPingAsync(IOBehavior ioBehavior, CancellationToken ca
321325
catch (EndOfStreamException)
322326
{
323327
}
328+
catch (IOException)
329+
{
330+
}
324331
catch (SocketException)
325332
{
326333
}
@@ -435,6 +442,7 @@ private async Task<bool> OpenTcpSocketAsync(ConnectionSettings cs, IOBehavior io
435442
try
436443
{
437444
tcpClient = new TcpClient(ipAddress.AddressFamily);
445+
438446
using (cancellationToken.Register(() => tcpClient?.Client?.Dispose()))
439447
{
440448
try
@@ -448,7 +456,21 @@ private async Task<bool> OpenTcpSocketAsync(ConnectionSettings cs, IOBehavior io
448456
#if NETSTANDARD1_3
449457
await tcpClient.ConnectAsync(ipAddress, cs.Port).ConfigureAwait(false);
450458
#else
451-
tcpClient.Connect(ipAddress, cs.Port);
459+
if (Utility.IsWindows())
460+
{
461+
tcpClient.Connect(ipAddress, cs.Port);
462+
}
463+
else
464+
{
465+
// non-windows platforms block on synchronous connect, use send/receive timeouts: https://github.com/dotnet/corefx/issues/20954
466+
var originalSendTimeout = tcpClient.Client.SendTimeout;
467+
var originalReceiveTimeout = tcpClient.Client.ReceiveTimeout;
468+
tcpClient.Client.SendTimeout = cs.ConnectionTimeoutMilliseconds;
469+
tcpClient.Client.ReceiveTimeout = cs.ConnectionTimeoutMilliseconds;
470+
tcpClient.Connect(ipAddress, cs.Port);
471+
tcpClient.Client.SendTimeout = originalSendTimeout;
472+
tcpClient.Client.ReceiveTimeout = originalReceiveTimeout;
473+
}
452474
#endif
453475
}
454476
}

tests/Benchmark/Benchmark.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<OutputType>Exe</OutputType>
4-
<TargetFrameworks>netcoreapp1.1;net462</TargetFrameworks>
4+
<TargetFrameworks>netcoreapp1.1;net462;netcoreapp2.0</TargetFrameworks>
55
</PropertyGroup>
66
<ItemGroup>
77
<PackageReference Include="BenchmarkDotNet" Version="0.10.8" />

tests/Benchmark/Program.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ static void Main()
2424
.With(JitOptimizationsValidator.FailOnError)
2525
.With(MemoryDiagnoser.Default)
2626
.With(StatisticColumn.AllStatistics)
27-
.With(Job.Default.With(Runtime.Clr).With(Jit.RyuJit).With(Platform.X64).With(CsProjClassicNetToolchain.Net462))
28-
.With(Job.Default.With(Runtime.Core).With(CsProjCoreToolchain.NetCoreApp11))
27+
.With(Job.Default.With(Runtime.Clr).With(Jit.RyuJit).With(Platform.X64).With(CsProjClassicNetToolchain.Net462).WithId("net462"))
28+
.With(Job.Default.With(Runtime.Core).With(CsProjCoreToolchain.NetCoreApp11).WithId("netcore11"))
29+
.With(Job.Default.With(Runtime.Core).With(CsProjCoreToolchain.NetCoreApp20).WithId("netcore20"))
2930
.With(DefaultExporters.Csv);
3031

3132
var summary = BenchmarkRunner.Run<MySqlClient>(customConfig);

tests/MySqlConnector.Performance/MySqlConnector.Performance.csproj

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp1.1.1</TargetFramework>
4+
<TargetFrameworks>netcoreapp2.0</TargetFrameworks>
55
<PreserveCompilationContext>true</PreserveCompilationContext>
66
<AssemblyName>MySqlConnector.Performance</AssemblyName>
77
<OutputType>Exe</OutputType>
@@ -12,16 +12,16 @@
1212
</PropertyGroup>
1313

1414
<ItemGroup>
15-
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
16-
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.1" />
17-
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.1.1" />
18-
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="1.1.1" />
19-
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.1" />
20-
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="1.1.1" />
21-
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.1" />
22-
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.1" />
23-
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
24-
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.1" />
15+
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0-*" />
16+
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.0.0-*" />
17+
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.0.0-*" />
18+
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.0.0-*" />
19+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.0-*" />
20+
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="2.0.0-*" />
21+
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.0.0-*" />
22+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.0.0-*" />
23+
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.0-*" />
24+
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.0.0-*" />
2525
</ItemGroup>
2626

2727
<ItemGroup Condition=" '$(Configuration)' != 'Baseline' ">

0 commit comments

Comments
 (0)