Skip to content

Commit

Permalink
Merge net9 into master.
Browse files Browse the repository at this point in the history
Signed-off-by: Bradley Grainger <[email protected]>
  • Loading branch information
bgrainger committed Oct 5, 2024
2 parents 9d17f7f + 3ae8fc1 commit c2240ff
Show file tree
Hide file tree
Showing 29 changed files with 142 additions and 101 deletions.
34 changes: 17 additions & 17 deletions .ci/build-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,58 +27,58 @@ steps:
displayName: 'Publish MySqlConnector.Tests'
inputs:
command: 'publish'
arguments: '-c Release -f net8.0 --no-build tests/MySqlConnector.Tests/MySqlConnector.Tests.csproj'
arguments: '-c Release -f net9.0 --no-build tests/MySqlConnector.Tests/MySqlConnector.Tests.csproj'
publishWebProjects: false
zipAfterPublish: false
- task: PublishPipelineArtifact@0
inputs:
artifactName: 'MySqlConnector.Tests-8.0-$(Agent.OS)'
targetPath: 'artifacts/publish/MySqlConnector.Tests/release_net8.0'
artifactName: 'MySqlConnector.Tests-9.0-$(Agent.OS)'
targetPath: 'artifacts/publish/MySqlConnector.Tests/release_net9.0'

- task: DotNetCoreCLI@2
displayName: 'Publish Conformance.Tests'
inputs:
command: 'publish'
arguments: '-c Release -f net8.0 --no-build tests/Conformance.Tests/Conformance.Tests.csproj'
arguments: '-c Release -f net9.0 --no-build tests/Conformance.Tests/Conformance.Tests.csproj'
publishWebProjects: false
zipAfterPublish: false
- task: PublishPipelineArtifact@0
inputs:
artifactName: 'Conformance.Tests-8.0-$(Agent.OS)'
targetPath: 'artifacts/publish/Conformance.Tests/release_net8.0'
artifactName: 'Conformance.Tests-9.0-$(Agent.OS)'
targetPath: 'artifacts/publish/Conformance.Tests/release_net9.0'

- task: DotNetCoreCLI@2
displayName: 'Publish MySqlConnector.DependencyInjection.Tests'
inputs:
command: 'publish'
arguments: '-c Release -f net8.0 --no-build tests/MySqlConnector.DependencyInjection.Tests/MySqlConnector.DependencyInjection.Tests.csproj'
arguments: '-c Release -f net9.0 --no-build tests/MySqlConnector.DependencyInjection.Tests/MySqlConnector.DependencyInjection.Tests.csproj'
publishWebProjects: false
zipAfterPublish: false
- task: PublishPipelineArtifact@0
inputs:
artifactName: 'MySqlConnector.DependencyInjection.Tests-8.0-$(Agent.OS)'
targetPath: 'artifacts/publish/MySqlConnector.DependencyInjection.Tests/release_net8.0'
artifactName: 'MySqlConnector.DependencyInjection.Tests-9.0-$(Agent.OS)'
targetPath: 'artifacts/publish/MySqlConnector.DependencyInjection.Tests/release_net9.0'

- task: DotNetCoreCLI@2
displayName: 'Publish IntegrationTests (7.0)'
displayName: 'Publish IntegrationTests (9.0)'
inputs:
command: 'publish'
arguments: '-c Release -f net8.0 --no-build tests/IntegrationTests/IntegrationTests.csproj'
arguments: '-c Release -f net9.0 --no-build tests/IntegrationTests/IntegrationTests.csproj'
publishWebProjects: false
zipAfterPublish: false
- task: PublishPipelineArtifact@0
inputs:
artifactName: 'IntegrationTests-net8.0-$(Agent.OS)'
targetPath: 'artifacts/publish/IntegrationTests/release_net8.0'
artifactName: 'IntegrationTests-net9.0-$(Agent.OS)'
targetPath: 'artifacts/publish/IntegrationTests/release_net9.0'

- task: DotNetCoreCLI@2
displayName: 'Publish IntegrationTests (6.0)'
displayName: 'Publish IntegrationTests (8.0)'
inputs:
command: 'publish'
arguments: '-c Release -f net6.0 --no-build tests/IntegrationTests/IntegrationTests.csproj'
arguments: '-c Release -f net8.0 --no-build tests/IntegrationTests/IntegrationTests.csproj'
publishWebProjects: false
zipAfterPublish: false
- task: PublishPipelineArtifact@0
inputs:
artifactName: 'IntegrationTests-net6.0-$(Agent.OS)'
targetPath: 'artifacts/publish/IntegrationTests/release_net6.0'
artifactName: 'IntegrationTests-net8.0-$(Agent.OS)'
targetPath: 'artifacts/publish/IntegrationTests/release_net8.0'
6 changes: 3 additions & 3 deletions .ci/conformance-test-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ steps:
- task: DownloadPipelineArtifact@0
condition: always()
inputs:
artifactName: 'Conformance.Tests-8.0-$(Agent.OS)'
targetPath: '$(Build.BinariesDirectory)/8.0'
artifactName: 'Conformance.Tests-9.0-$(Agent.OS)'
targetPath: '$(Build.BinariesDirectory)/9.0'
- task: DotNetCoreCLI@2
displayName: 'Conformance Tests'
inputs:
command: 'custom'
custom: 'vstest'
arguments: '$(Build.BinariesDirectory)/8.0/Conformance.Tests.dll /logger:trx'
arguments: '$(Build.BinariesDirectory)/9.0/Conformance.Tests.dll /logger:trx'
env:
CONNECTION_STRING: ${{ parameters.connectionString }}
- task: PublishTestResults@2
Expand Down
10 changes: 5 additions & 5 deletions .ci/integration-tests-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ steps:
- bash: ${{ format('.ci/docker-run.sh {0} 3300 {1}', parameters.image, parameters.unsupportedFeatures) }}
displayName: 'Start Docker container'
- task: UseDotNet@2
displayName: 'Install .NET 6.0'
displayName: 'Install .NET 8.0'
inputs:
version: 6.0.x
version: 8.0.x
packageType: runtime
- task: UseDotNet@2
displayName: 'Install .NET'
Expand All @@ -33,19 +33,19 @@ steps:
image: ${{ parameters.image }}
unsupportedFeatures: ${{ parameters.unsupportedFeatures }}
connectionString: 'server=localhost;port=3300;user id=mysqltest;password=test;database=mysqltest;ssl mode=none;UseCompression=True;DefaultCommandTimeout=3600;${{ parameters.connectionStringExtra }}'
platform: 'net6.0'
platform: 'net8.0'
description: 'Compression'
- template: 'integration-test-steps.yml'
parameters:
image: ${{ parameters.image }}
unsupportedFeatures: ${{ parameters.unsupportedFeatures }}
connectionString: 'server=localhost;port=3300;user id=mysqltest;password=test;database=mysqltest;ssl mode=none;DefaultCommandTimeout=3600;${{ parameters.connectionStringExtra }}'
platform: 'net6.0'
platform: 'net9.0'
description: 'No SSL'
- template: 'integration-test-steps.yml'
parameters:
image: ${{ parameters.image }}
unsupportedFeatures: ${{ parameters.unsupportedFeatures }}
connectionString: server=localhost;port=3300;user id=mysqltest;password=test;database=mysqltest;ssl mode=required;DefaultCommandTimeout=3600;certificate file=$(Build.Repository.LocalPath)/.ci/server/certs/ssl-client.pfx;${{ parameters.connectionStringExtra }}
platform: 'net6.0'
platform: 'net9.0'
description: 'SSL'
6 changes: 3 additions & 3 deletions .ci/mysqlconnector-tests-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ steps:
includePreviewVersions: true
- task: DownloadPipelineArtifact@0
inputs:
artifactName: 'MySqlConnector.Tests-8.0-$(Agent.OS)'
artifactName: 'MySqlConnector.Tests-9.0-$(Agent.OS)'
targetPath: $(System.DefaultWorkingDirectory)
- task: DotNetCoreCLI@2
displayName: 'Run MySqlConnector.Tests'
Expand All @@ -16,7 +16,7 @@ steps:
arguments: 'MySqlConnector.Tests.dll /logger:trx'
- task: DownloadPipelineArtifact@0
inputs:
artifactName: 'MySqlConnector.DependencyInjection.Tests-8.0-$(Agent.OS)'
artifactName: 'MySqlConnector.DependencyInjection.Tests-9.0-$(Agent.OS)'
targetPath: $(System.DefaultWorkingDirectory)
- task: DotNetCoreCLI@2
displayName: 'Run MySqlConnector.DependencyInjection.Tests'
Expand All @@ -28,4 +28,4 @@ steps:
inputs:
testResultsFormat: VSTest
testResultsFiles: '**/*.trx'
testRunTitle: 'MySqlConnector.Tests-8.0-$(Agent.OS)'
testRunTitle: 'MySqlConnector.Tests-9.0-$(Agent.OS)'
4 changes: 2 additions & 2 deletions .ci/test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ dotnet test -c Release -f net462
if ($LASTEXITCODE -ne 0){
exit $LASTEXITCODE;
}
dotnet test -c Release -f net7.0
dotnet test -c Release -f net9.0
if ($LASTEXITCODE -ne 0){
exit $LASTEXITCODE;
}

echo "Executing integration tests with Compression, No SSL"
Copy-Item -Force ..\..\.ci\config\config.compression.json config.json
dotnet test -c Release -f net6.0
dotnet test -c Release -f net8.0
if ($LASTEXITCODE -ne 0){
exit $LASTEXITCODE;
}
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up .NET 8.0
- name: Set up .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.x

- name: Restore
run: dotnet restore
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ jobs:
- name: Check out
uses: actions/checkout@v4

- name: Set up .NET 8.0
- name: Set up .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.x

- name: Initialize CodeQL
uses: github/codeql-action/init@v3
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ cache:
install:
- ps: Invoke-WebRequest -Uri "https://dot.net/v1/dotnet-install.ps1" -OutFile "install-dotnet.ps1"
- ps: .\install-dotnet.ps1 -Channel 6.0 -InstallDir "dotnetcli"
- ps: .\install-dotnet.ps1 -Channel 7.0 -InstallDir "dotnetcli"
- ps: .\install-dotnet.ps1 -Channel 8.0 -InstallDir "dotnetcli"
- ps: .\install-dotnet.ps1 -Channel 9.0 -InstallDir "dotnetcli"
build_script:
- dotnet --info
before_test:
Expand Down
42 changes: 13 additions & 29 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
variables:
DotNetCoreSdkVersion: '8.x'
DotNetCoreSdkVersion: '9.x'
NUGET_PACKAGES: '$(Pipeline.Workspace)/.nuget/packages'

jobs:
Expand All @@ -16,17 +16,6 @@ jobs:
vmimage: 'windows-latest'
steps:
- template: '.ci/build-steps.yml'
- task: DotNetCoreCLI@2
displayName: 'Publish IntegrationTests (net472)'
inputs:
command: 'publish'
arguments: '-c Release -f net472 tests/IntegrationTests/IntegrationTests.csproj'
publishWebProjects: false
zipAfterPublish: false
- task: PublishPipelineArtifact@0
inputs:
artifactName: 'IntegrationTests-net472-$(Agent.OS)'
targetPath: 'artifacts/publish/IntegrationTests/release_net472'

- job: windows_mysql_data
displayName: 'MySql.Data Tests'
Expand All @@ -41,9 +30,9 @@ jobs:
contents: 'config.json'
targetFolder: 'tests/IntegrationTests'
- task: UseDotNet@2
displayName: 'Install .NET 7.0'
displayName: 'Install .NET 8.0'
inputs:
version: '7.0.x'
version: '8.0.x'
- task: UseDotNet@2
displayName: 'Install .NET'
inputs:
Expand Down Expand Up @@ -91,11 +80,6 @@ jobs:
vmimage: 'windows-2019'
steps:
- template: '.ci/install-mysql-windows.yml'
- task: UseDotNet@2
displayName: 'Install .NET Core 3.1'
inputs:
version: 3.1.x
packageType: runtime
- template: '.ci/mysqlconnector-tests-steps.yml'
- template: '.ci/conformance-test-steps.yml'
parameters:
Expand Down Expand Up @@ -123,18 +107,18 @@ jobs:
displayName: 'Remove target frameworks'
inputs:
targetType: 'inline'
script: '((Get-Content .\tests\IntegrationTests\IntegrationTests.csproj -Raw) -replace(''<TargetFrameworks>.*</TargetFrameworks>'', ''<TargetFrameworks>net472;net8.0</TargetFrameworks>'')) | Set-Content .\tests\IntegrationTests\IntegrationTests.csproj'
script: '((Get-Content .\tests\IntegrationTests\IntegrationTests.csproj -Raw) -replace(''<TargetFrameworks>.*</TargetFrameworks>'', ''<TargetFrameworks>net481;net9.0</TargetFrameworks>'')) | Set-Content .\tests\IntegrationTests\IntegrationTests.csproj'
- task: DotNetCoreCLI@2
displayName: 'Restore packages'
inputs:
command: 'restore'
- task: DotNetCoreCLI@2
displayName: 'Integration tests (net472/net8.0)'
displayName: 'Integration tests (net481/net9.0)'
inputs:
command: 'test'
projects: 'tests/IntegrationTests/IntegrationTests.csproj'
arguments: '-c Release --no-restore'
testRunTitle: ${{ format('{0}, $(Agent.OS), {1}, {2}', 'mysql:8.0', 'net472/net8.0', 'No SSL') }}
arguments: '-c Release --no-restore -p:TestTfmsInParallel=false'
testRunTitle: ${{ format('{0}, $(Agent.OS), {1}, {2}', 'mysql:8.0', 'net481/net9.0', 'No SSL') }}
env:
DATA__UNSUPPORTEDFEATURES: 'Ed25519,QueryAttributes,Redirection,StreamingResults,Tls11,TlsFingerprintValidation,UnixDomainSocket'
DATA__CONNECTIONSTRING: 'server=localhost;port=3306;user id=mysqltest;password=test;database=mysqltest;ssl mode=none;DefaultCommandTimeout=3600;AllowPublicKeyRetrieval=True;UseCompression=True'
Expand All @@ -146,9 +130,9 @@ jobs:
steps:
- template: '.ci/install-mysql-windows.yml'
- task: UseDotNet@2
displayName: 'Install .NET 6.0'
displayName: 'Install .NET 8.0'
inputs:
version: 6.0.x
version: 8.0.x
packageType: runtime
- task: UseDotNet@2
displayName: 'Install .NET'
Expand All @@ -161,18 +145,18 @@ jobs:
displayName: 'Remove target frameworks'
inputs:
targetType: 'inline'
script: '((Get-Content .\tests\IntegrationTests\IntegrationTests.csproj -Raw) -replace(''<TargetFrameworks>.*</TargetFrameworks>'', ''<TargetFrameworks>net6.0</TargetFrameworks>'')) | Set-Content .\tests\IntegrationTests\IntegrationTests.csproj'
script: '((Get-Content .\tests\IntegrationTests\IntegrationTests.csproj -Raw) -replace(''<TargetFrameworks>.*</TargetFrameworks>'', ''<TargetFrameworks>net8.0</TargetFrameworks>'')) | Set-Content .\tests\IntegrationTests\IntegrationTests.csproj'
- task: DotNetCoreCLI@2
displayName: 'Restore packages'
inputs:
command: 'restore'
- task: DotNetCoreCLI@2
displayName: 'Integration tests (net6.0)'
displayName: 'Integration tests (net8.0)'
inputs:
command: 'test'
projects: 'tests/IntegrationTests/IntegrationTests.csproj'
arguments: '-c Release --no-restore'
testRunTitle: ${{ format('{0}, $(Agent.OS), {1}, {2}', 'mysql:8.0', 'net6.0', 'No SSL') }}
arguments: '-c Release --no-restore -p:TestTfmsInParallel=false'
testRunTitle: ${{ format('{0}, $(Agent.OS), {1}, {2}', 'mysql:8.0', 'net8.0', 'No SSL') }}
env:
DATA__UNSUPPORTEDFEATURES: 'Ed25519,QueryAttributes,Redirection,StreamingResults,Tls11,TlsFingerprintValidation,UnixDomainSocket'
DATA__CONNECTIONSTRING: 'server=localhost;port=3306;user id=mysqltest;password=test;database=mysqltest;ssl mode=none;DefaultCommandTimeout=3600;AllowPublicKeyRetrieval=True'
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sdk": {
"version": "8.0"
"version": "9.0"
}
}
4 changes: 4 additions & 0 deletions src/MySqlConnector/Authentication/AuthenticationPlugins.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ internal static bool TryGetPlugin(string name, [NotNullWhen(true)] out IAuthenti
return s_plugins.TryGetValue(name, out plugin);
}

#if NET9_0_OR_GREATER
private static readonly Lock s_lock = new();
#else
private static readonly object s_lock = new();
#endif
private static readonly Dictionary<string, IAuthenticationPlugin> s_plugins = [];
}
4 changes: 3 additions & 1 deletion src/MySqlConnector/ColumnReaders/BinaryTimeColumnReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ public override object ReadValue(ReadOnlySpan<byte> data, ColumnDefinitionPayloa
microseconds = -microseconds;
}

#if NET7_0_OR_GREATER
#if NET9_0_OR_GREATER
return TimeSpan.FromDays(days, hours, minutes, seconds, microseconds: microseconds);
#elif NET7_0_OR_GREATER
return new TimeSpan(days, hours, minutes, seconds, microseconds / 1000, microseconds % 1000);
#else
return new TimeSpan(days, hours, minutes, seconds) + TimeSpan.FromTicks(microseconds * 10);
Expand Down
26 changes: 23 additions & 3 deletions src/MySqlConnector/Core/ILoadBalancer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,38 @@ internal sealed class RandomLoadBalancer : ILoadBalancer
public IReadOnlyList<string> LoadBalance(IReadOnlyList<string> hosts)
{
#pragma warning disable CA5394 // Do not use insecure randomness
// from https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#The_modern_algorithm
#if NET8_0_OR_GREATER
var shuffled = hosts.ToArray();
lock (m_lock)
m_random.Shuffle(shuffled);
return shuffled;
#else
var shuffled = new List<string>(hosts);
// from https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#The_modern_algorithm
for (var i = hosts.Count - 1; i >= 1; i--)
{
int j;
lock (m_random)
lock (m_lock)
j = m_random.Next(i + 1);
if (i != j)
(shuffled[j], shuffled[i]) = (shuffled[i], shuffled[j]);
}
return shuffled;
#endif
}

private RandomLoadBalancer() => m_random = new();
private RandomLoadBalancer()
{
m_random = new();
m_lock = new();
}

private readonly Random m_random;
#if NET9_0_OR_GREATER
private readonly Lock m_lock;
#else
private readonly object m_lock;
#endif
}

internal sealed class RoundRobinLoadBalancer : ILoadBalancer
Expand All @@ -63,6 +79,10 @@ public IReadOnlyList<string> LoadBalance(IReadOnlyList<string> hosts)
return shuffled;
}

#if NET9_0_OR_GREATER
private readonly Lock m_lock;
#else
private readonly object m_lock;
#endif
private uint m_counter;
}
Loading

0 comments on commit c2240ff

Please sign in to comment.