Skip to content

Commit

Permalink
Merge pull request #930 from paulirwin/net8-tests
Browse files Browse the repository at this point in the history
Upgrade tests and CLI to .NET 8, fix benchmark formatting issue
  • Loading branch information
paulirwin committed Apr 30, 2024
2 parents 444e6d0 + 8d553ed commit 9b74275
Show file tree
Hide file tree
Showing 66 changed files with 577 additions and 561 deletions.
4 changes: 3 additions & 1 deletion .build/azure-templates/install-dotnet-sdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,17 @@ steps:
}
}
EnsureNotNullOrEmpty('${{ parameters.sdkVersion }}', 'sdkVersion')
EnsureNotNullOrEmpty('${{ parameters.performMultiLevelLookup }}', 'performMultiLevelLookup')
displayName: 'Validate Template Parameters'

- bash: |
echo "##vso[task.setvariable variable=DOTNET_NOLOGO;]1"
echo "##vso[task.setvariable variable=DOTNET_CLI_TELEMETRY_OPTOUT;]1"
displayName: Disable Telemetry

- task: UseDotNet@2
displayName: 'Use .NET SDK ${{ parameters.sdkVersion }}'
inputs:
packageType: 'sdk'
version: '${{ parameters.sdkVersion }}'
performMultiLevelLookup: '${{ parameters.performMultiLevelLookup }}'
performMultiLevelLookup: '${{ parameters.performMultiLevelLookup }}'
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing,-with-title
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
Expand Down Expand Up @@ -81,11 +81,11 @@ steps:
testResultsArtifactName: '${{ parameters.testResultsArtifactName }}'
testResultsFileName: '${{ parameters.testResultsFileName }}'

# Special case: Only supports net7.0 and net6.0
# Special case: Only supports net8.0 and net6.0
- template: publish-test-results.yml
parameters:
testProjectName: 'Lucene.Net.Tests.Cli'
framework: 'net7.0' # Since condtions are not supported for templates, we check for the file existence within publish-test-results.yml
framework: 'net8.0' # Since condtions are not supported for templates, we check for the file existence within publish-test-results.yml
vsTestPlatform: '${{ parameters.vsTestPlatform }}'
osName: '${{ parameters.osName }}'
testResultsFormat: '${{ parameters.testResultsFormat }}'
Expand All @@ -102,12 +102,12 @@ steps:
testResultsArtifactName: '${{ parameters.testResultsArtifactName }}'
testResultsFileName: '${{ parameters.testResultsFileName }}'

# Special case: Only supports net7.0, net6.0 and net48
# Special case: Only supports net8.0, net6.0 and net48

- template: publish-test-results.yml
parameters:
testProjectName: 'Lucene.Net.Tests.Analysis.OpenNLP'
framework: 'net7.0' # Since condtions are not supported for templates, we check for the file existence within publish-test-results.yml
framework: 'net8.0' # Since condtions are not supported for templates, we check for the file existence within publish-test-results.yml
vsTestPlatform: '${{ parameters.vsTestPlatform }}'
osName: '${{ parameters.osName }}'
testResultsFormat: '${{ parameters.testResultsFormat }}'
Expand Down
8 changes: 6 additions & 2 deletions .build/azure-templates/publish-test-results.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ steps:
if ($inRunInfos -and !$crashed -and $reader.Name -eq 'Text') {
$innerXml = $reader.ReadInnerXml()
# Test for specific error messages - we may need to adjust this, as needed
if ($innerXml -and ($innerXml.Contains('Test host process crashed') -or $innerXml.Contains('Could not load file or assembly'))) {
if ($innerXml -and ($innerXml.Contains('Test host process crashed') `
-or $innerXml.Contains('Could not load file or assembly') `
-or $innerXml.Contains("Could not find `'dotnet.exe`' host") `
-or $innerXml.Contains('No test is available') `
-or $innerXml.Contains('exited with error'))) {
Write-Host "##vso[task.setvariable variable=HostCrashed;]true"
# Report all of the test projects that crashed
$crashedRuns = "$env:CRASHEDRUNS,$testProjectName".TrimStart(',')
Expand Down Expand Up @@ -104,4 +108,4 @@ steps:
testResultsFormat: ${{ parameters.testResultsFormat }}
testResultsFiles: '$(Build.ArtifactStagingDirectory)/${{ parameters.testResultsArtifactName }}/${{ parameters.osName }}/${{ parameters.framework }}/${{ parameters.vsTestPlatform }}/${{ parameters.testProjectName }}/${{ parameters.testResultsFileName }}'
testRunTitle: '${{ parameters.testProjectName }} - ${{ parameters.framework }} - ${{ parameters.vsTestPlatform }} - ${{ parameters.osName }} | $(TestResults)'
condition: and(succeeded(), eq(variables['TestResultsFileExists'], 'true'))
condition: and(succeeded(), eq(variables['TestResultsFileExists'], 'true'))
105 changes: 75 additions & 30 deletions .build/azure-templates/run-tests-on-os.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
Expand All @@ -34,7 +34,7 @@ parameters:
maximumAllowedFailures: 0
where: '' # A test filter expression, as defined by dotnet test
dotNetSdkVersion: '' # The .NET SDK version to install

steps:
- checkout: none # self represents the repo where the initial Pipelines YAML file was found

Expand Down Expand Up @@ -83,34 +83,79 @@ steps:
$performMulitLevelLookup = if ($IsWindows -and $testPlatform.Equals('x86')) { 'true' } else { 'false' }
Write-Host "##vso[task.setvariable variable=PerformMultiLevelLookup;]$performMulitLevelLookup"
#- template: 'show-all-environment-variables.yml' # Uncomment for debugging

- template: 'install-dotnet-sdk.yml'
parameters:
sdkVersion: '${{ parameters.dotNetSdkVersion }}'
performMultiLevelLookup: '${{ variables.PerformMultiLevelLookup }}'

# Hack: .NET 8 no longer installs the x86 bits and they must be installed separately. However, it is not
# trivial to get it into the path and to get it to pass the minimum SDK version check in runbuild.ps1.
# So, we install it afterward and set the environment variable so the above SDK can delegate to it.
# This code only works on Windows.
- pwsh: |
$sdkVersion = '${{ parameters.dotNetSdkVersion }}'
$architecture = '${{ parameters.vsTestPlatform }}'
$installScriptPath = "${env:AGENT_TEMPDIRECTORY}/dotnet-install.ps1"
$installScriptUrl = "https://raw.githubusercontent.com/dotnet/install-scripts/main/src/dotnet-install.ps1"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest $installScriptUrl -OutFile $installScriptPath -TimeoutSec 60
$installPath = "${env:ProgramFiles(x86)}/dotnet"
& $installScriptPath -Version $sdkVersion -Architecture $architecture -InstallDir $installPath
Write-Host "##vso[task.setvariable variable=DOTNET_ROOT_X86;]$installPath"
displayName: 'Use .NET SDK ${{ parameters.dotNetSdkVersion }} (x86)'
condition: and(succeeded(), contains('${{ parameters.framework }}', 'net8.'), eq('${{ parameters.vsTestPlatform }}', 'x86'))

- task: UseDotNet@2
displayName: 'Use .NET Core sdk 3.1.412'
displayName: 'Use .NET SDK 6.0.421'
inputs:
packageType: 'sdk'
version: '3.1.412'
version: '6.0.421'
performMultiLevelLookup: '${{ variables.PerformMultiLevelLookup }}'
condition: and(succeeded(), contains('${{ parameters.framework }}', 'netcoreapp3.'))
condition: and(succeeded(), contains('${{ parameters.framework }}', 'net6.'))

# Hack: .NET 8 no longer installs the x86 bits and they must be installed separately. However, it is not
# trivial to get it into the path and to get it to pass the minimum SDK version check in runbuild.ps1.
# So, we install it afterward and set the environment variable so the above SDK can delegate to it.
# This code only works on Windows.
- pwsh: |
$sdkVersion = '6.0.421'
$architecture = '${{ parameters.vsTestPlatform }}'
$installScriptPath = "${env:AGENT_TEMPDIRECTORY}/dotnet-install.ps1"
$installScriptUrl = "https://raw.githubusercontent.com/dotnet/install-scripts/main/src/dotnet-install.ps1"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest $installScriptUrl -OutFile $installScriptPath -TimeoutSec 60
$installPath = "${env:ProgramFiles(x86)}/dotnet"
& $installScriptPath -Version $sdkVersion -Architecture $architecture -InstallDir $installPath
Write-Host "##vso[task.setvariable variable=DOTNET_ROOT_X86;]$installPath"
displayName: 'Use .NET SDK 6.0.421 (x86)'
condition: and(succeeded(), contains('${{ parameters.framework }}', 'net6.'), eq('${{ parameters.vsTestPlatform }}', 'x86'))

- task: UseDotNet@2
displayName: 'Use .NET sdk 5.0.400'
displayName: 'Use .NET SDK 5.0.408'
inputs:
packageType: 'sdk'
version: '5.0.400'
version: '5.0.408'
performMultiLevelLookup: '${{ variables.PerformMultiLevelLookup }}'
condition: and(succeeded(), contains('${{ parameters.framework }}', 'net5.'))

- task: UseDotNet@2
displayName: 'Use .NET sdk 6.0.403'
inputs:
packageType: 'sdk'
version: '5.0.403'
performMultiLevelLookup: '${{ variables.PerformMultiLevelLookup }}'
condition: and(succeeded(), contains('${{ parameters.framework }}', 'net6.'))
# Hack: .NET 8 no longer installs the x86 bits and they must be installed separately. However, it is not
# trivial to get it into the path and to get it to pass the minimum SDK version check in runbuild.ps1.
# So, we install it afterward and set the environment variable so the above SDK can delegate to it.
# This code only works on Windows.
- pwsh: |
$sdkVersion = '5.0.408'
$architecture = '${{ parameters.vsTestPlatform }}'
$installScriptPath = "${env:AGENT_TEMPDIRECTORY}/dotnet-install.ps1"
$installScriptUrl = "https://raw.githubusercontent.com/dotnet/install-scripts/main/src/dotnet-install.ps1"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest $installScriptUrl -OutFile $installScriptPath -TimeoutSec 60
$installPath = "${env:ProgramFiles(x86)}/dotnet"
& $installScriptPath -Version $sdkVersion -Architecture $architecture -InstallDir $installPath
Write-Host "##vso[task.setvariable variable=DOTNET_ROOT_X86;]$installPath"
displayName: 'Use .NET SDK 5.0.408 (x86)'
condition: and(succeeded(), contains('${{ parameters.framework }}', 'net5.'), eq('${{ parameters.vsTestPlatform }}', 'x86'))

#- template: 'show-all-files.yml' # Uncomment for debugging
- pwsh: |
Expand All @@ -126,7 +171,7 @@ steps:
$tempDirectory = "$(Agent.TempDirectory)"
$isNightly = if ($env:ISNIGHTLY -eq 'true') { 'true' } else { 'false' }
$isWeekly = if ($env:ISWEEKLY -eq 'true') { 'true' } else { 'false' }
function IsSupportedFramework([string]$framework) {
if ($IsWindows -eq $null) {
$IsWindows = $env:OS.StartsWith('Win')
Expand All @@ -136,15 +181,15 @@ steps:
}
return $true
}
function RunTests([string]$framework, [string]$fileRegexPattern) {
if (!(IsSupportedFramework($framework))) { continue }
$testBinaries = Get-ChildItem -Path "$testBinaryRootDirectory" -File -Recurse | Where-Object {$_.FullName -match "$framework" -and $_.FullName -match "$fileRegexPattern" -and !$_.Name.EndsWith('.resources.dll') } | Sort-Object -Property FullName
Write-Host $testBinaries
foreach ($testBinary in $testBinaries) {
$testName = [System.IO.Path]::GetFileNameWithoutExtension($testBinary.FullName)
if ($maximumParalellJobs -gt 1) {
# Pause if we have queued too many parallel jobs
$running = @(Get-Job | Where-Object { $_.State -eq 'Running' })
Expand All @@ -155,7 +200,7 @@ steps:
$running | Wait-Job -Any | Out-Null
}
}
$testResultDirectory = "$testResultsArtifactDirectory/$testOSName/$framework/$testPlatform/$testName"
if (!(Test-Path "$testResultDirectory")) {
New-Item "$testResultDirectory" -ItemType Directory -Force
Expand Down Expand Up @@ -186,32 +231,32 @@ steps:
if (![string]::IsNullOrEmpty($where)) {
$testExpression = "$testExpression --filter ""$where"""
}
$testExpression = "$testExpression -- RunConfiguration.TargetPlatform=$testPlatform"
Write-Host "Testing '$($testBinary.FullName)' on framework '$framework' and outputting test results to '$testResultDirectory/$testResultsFileName'..."
Write-Host $testExpression -ForegroundColor Magenta
if ($maximumParalellJobs -le 1) {
Invoke-Expression $testExpression # For running in the foreground
} else {
$testExpression += " > ""$testResultDirectory/dotnet-test.log"" 2> ""$testResultDirectory/dotnet-test-error.log"""
$scriptBlock = {
param([string]$testExpression)
Invoke-Expression $testExpression
}
# Avoid dotnet test collisions by delaying for 500ms
Start-Sleep -Milliseconds 500
# Execute the jobs in parallel
Start-Job -Name "$testName,$framework,$testPlatform" -ScriptBlock $scriptBlock -ArgumentList $testExpression
}
}
}
RunTests -Framework "$framework" -FileRegexPattern "$testBinaryFilesPattern"
if ($maximumParalellJobs -gt 1) {
# Wait for it all to complete
do {
Expand All @@ -229,7 +274,7 @@ steps:
}
} until ($running.Count -eq 0)
}
$global:LASTEXITCODE = 0 # Force the script to continue on error
displayName: 'dotnet test ${{ parameters.framework }},${{ parameters.vsTestPlatform }}'
ignoreLASTEXITCODE: true
Expand All @@ -247,7 +292,7 @@ steps:
# it would be a ton of work to make a replacement for the
# Publish Test Results task or the (deprecated) TfsPublisher
# our only other option is to make a task for every supported
# platform and project and update it whenever a new platform
# platform and project and update it whenever a new platform
# is targeted or test project is created in Lucene.Net.

- template: 'publish-test-results-for-test-projects.yml'
Expand All @@ -270,4 +315,4 @@ steps:
}
if ($failed) {
Write-Host "##vso[task.complete result=Failed;]"
}
}
8 changes: 4 additions & 4 deletions .build/dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@
<MicrosoftExtensionsDependencyInjectionPackageVersion>$(MicrosoftExtensionsDependencyInjectionAbstractionsPackageVersion)</MicrosoftExtensionsDependencyInjectionPackageVersion>
<MicrosoftExtensionsOptionsPackageVersion>2.0.0</MicrosoftExtensionsOptionsPackageVersion>
<MicrosoftNETFrameworkReferenceAssembliesPackageReferenceVersion>1.0.2</MicrosoftNETFrameworkReferenceAssembliesPackageReferenceVersion>
<MicrosoftNETTestSdkPackageVersion>16.6.1</MicrosoftNETTestSdkPackageVersion>
<MicrosoftNETTestSdkPackageVersion>17.9.0</MicrosoftNETTestSdkPackageVersion>
<MicrosoftSourceLinkAzureReposGitPackageReferenceVersion>1.1.1</MicrosoftSourceLinkAzureReposGitPackageReferenceVersion>
<MicrosoftSourceLinkGitHubPackageReferenceVersion>$(MicrosoftSourceLinkAzureReposGitPackageReferenceVersion)</MicrosoftSourceLinkGitHubPackageReferenceVersion>
<MorfologikFsaPackageVersion>2.1.7</MorfologikFsaPackageVersion>
<MorfologikPolishPackageVersion>$(MorfologikFsaPackageVersion)</MorfologikPolishPackageVersion>
<MorfologikStemmingPackageVersion>$(MorfologikFsaPackageVersion)</MorfologikStemmingPackageVersion>
<NETStandardLibrary20PackageVersion>2.0.3</NETStandardLibrary20PackageVersion>
<NewtonsoftJsonPackageVersion>13.0.1</NewtonsoftJsonPackageVersion>
<NUnit3TestAdapterPackageVersion>3.17.0</NUnit3TestAdapterPackageVersion>
<NUnit3TestAdapterPackageVersion>4.5.0</NUnit3TestAdapterPackageVersion>
<NUnitPackageVersion>3.13.1</NUnitPackageVersion>
<RandomizedTestingGeneratorsPackageVersion>2.7.8</RandomizedTestingGeneratorsPackageVersion>
<SharpZipLibPackageVersion>1.4.2</SharpZipLibPackageVersion>
Expand All @@ -81,12 +81,12 @@
<SystemRuntimeInteropServicesRuntimeInformationPackageVersion>4.3.0</SystemRuntimeInteropServicesRuntimeInformationPackageVersion>
<SystemSecurityCryptographyXmlPackageVersion>6.0.1</SystemSecurityCryptographyXmlPackageVersion>
<SystemTextEncodingCodePagesPackageVersion>4.3.0</SystemTextEncodingCodePagesPackageVersion>
<SystemTextEncodingCodePagesPackageVersion Condition=" '$(TargetFramework)' == 'net461' ">5.0.0</SystemTextEncodingCodePagesPackageVersion>
<SystemTextEncodingCodePagesPackageVersion Condition=" '$(TargetFramework)' == 'net472' ">5.0.0</SystemTextEncodingCodePagesPackageVersion>
<SystemTextJsonPackageVersion>6.0.6</SystemTextJsonPackageVersion>
<TimeZoneConverterPackageVersion>6.1.0</TimeZoneConverterPackageVersion>
</PropertyGroup>
<PropertyGroup Label="Maven Package Reference Versions">
<OpenNLPToolsMavenReferenceVersion>1.9.1</OpenNLPToolsMavenReferenceVersion>
<OSGICoreMavenReferenceVersion>4.2.0</OSGICoreMavenReferenceVersion>
</PropertyGroup>
</Project>
</Project>

0 comments on commit 9b74275

Please sign in to comment.