Skip to content

Commit 65a9f1e

Browse files
majochapsfinakivzarytovskiiKevinRansom
authored
Parallelize tests (#17872)
* rebase * orchestrate instead of Async.Sleep * xunit customizations behind conditional compilation * make console capture explicit * diff * try fix test * lazy pattern * reenable extras * test temptath * cleaup test dir * remove unneeded file * fix merge * another shot at fixing gc test * another attempt at improving Async.Parallel test * smaller diff * restore test * restore tests * diff * unblock service tests * rename attributes * fix * revert - should now work without * add comment * diff * diff Co-authored-by: Petr <[email protected]> * just exclude gc test * diff * exclude test case * try to trigger clr error in ci * try unflake test * unflake asyncmemo * ilverify * fix merge * some cleanup * Update tests/fsharp/Compiler/CodeGen/EmittedIL/DeterministicTests.fs Co-authored-by: Petr <[email protected]> * remove timeout * Make FsiTests sequential * restore ci throttling * min diff * add comment * bring down the parallelizm a notch on mac and linux --------- Co-authored-by: Petr <[email protected]> Co-authored-by: Vlad Zarytovskii <[email protected]> Co-authored-by: Kevin Ransom (msft) <[email protected]>
1 parent 143e375 commit 65a9f1e

File tree

56 files changed

+351
-165
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+351
-165
lines changed

eng/Build.ps1

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -362,14 +362,16 @@ function VerifyAssemblyVersionsAndSymbols() {
362362
}
363363
}
364364

365-
function TestUsingMSBuild([string] $testProject, [string] $targetFramework, [string]$testadapterpath, [boolean] $asBackgroundJob = $false) {
365+
function TestUsingMSBuild([string] $testProject, [string] $targetFramework, [string]$testadapterpath, [boolean] $asBackgroundJob = $false, [string] $settings = "") {
366366
$dotnetPath = InitializeDotNetCli
367367
$dotnetExe = Join-Path $dotnetPath "dotnet.exe"
368368
$projectName = [System.IO.Path]::GetFileNameWithoutExtension($testProject)
369-
$testLogPath = "$ArtifactsDir\TestResults\$configuration\${projectName}_$targetFramework.xml"
369+
# {assembly} and {framework} will expand respectively. See https://github.com/spekt/testlogger/wiki/Logger-Configuration#logfilepath
370+
# This is useful to deconflict log filenames when there are many test assemblies, e.g. when testing a whole solution.
371+
$testLogPath = "$ArtifactsDir\TestResults\$configuration\{assembly}_{framework}.xml"
370372
$testBinLogPath = "$LogDir\${projectName}_$targetFramework.binlog"
371373
$args = "test $testProject -c $configuration -f $targetFramework -v n --test-adapter-path $testadapterpath --logger ""xunit;LogFilePath=$testLogPath"" /bl:$testBinLogPath"
372-
$args += " --blame --results-directory $ArtifactsDir\TestResults\$configuration -p:vstestusemsbuildoutput=false"
374+
$args += " --blame --blame-hang-timeout 5minutes --results-directory $ArtifactsDir\TestResults\$configuration -p:vstestusemsbuildoutput=true"
373375

374376
if (-not $noVisualStudio -or $norestore) {
375377
$args += " --no-restore"
@@ -379,17 +381,20 @@ function TestUsingMSBuild([string] $testProject, [string] $targetFramework, [str
379381
$args += " --no-build"
380382
}
381383

384+
$args += " $settings"
385+
382386
if ($asBackgroundJob) {
387+
Write-Host
383388
Write-Host("Starting on the background: $args")
384389
Write-Host("------------------------------------")
385-
$bgJob = Start-Job -ScriptBlock {
386-
& $using:dotnetExe test $using:testProject -c $using:configuration -f $using:targetFramework -v n --test-adapter-path $using:testadapterpath --logger "xunit;LogFilePath=$using:testLogPath" /bl:$using:testBinLogPath --blame --results-directory $using:ArtifactsDir\TestResults\$using:configuration
390+
Start-Job -ScriptBlock {
391+
$argArray = $using:args -Split " "
392+
& $using:dotnetExe $argArray
387393
if ($LASTEXITCODE -ne 0) {
388394
throw "Command failed to execute with exit code $($LASTEXITCODE): $using:dotnetExe $using:args"
389395
}
390396
}
391-
return $bgJob
392-
} else{
397+
} else {
393398
Write-Host("$args")
394399
Exec-Console $dotnetExe $args
395400
}
@@ -595,21 +600,20 @@ try {
595600
$script:BuildCategory = "Test"
596601
$script:BuildMessage = "Failure running tests"
597602

598-
if ($testCoreClr) {
599-
$bgJob = TestUsingMSBuild -testProject "$RepoRoot\tests\fsharp\FSharpSuite.Tests.fsproj" -targetFramework $script:coreclrTargetFramework -testadapterpath "$ArtifactsDir\bin\FSharpSuite.Tests\" -asBackgroundJob $true
600-
601-
TestUsingMSBuild -testProject "$RepoRoot\tests\FSharp.Compiler.ComponentTests\FSharp.Compiler.ComponentTests.fsproj" -targetFramework $script:coreclrTargetFramework -testadapterpath "$ArtifactsDir\bin\FSharp.Compiler.ComponentTests\"
602-
TestUsingMSBuild -testProject "$RepoRoot\tests\FSharp.Compiler.Service.Tests\FSharp.Compiler.Service.Tests.fsproj" -targetFramework $script:coreclrTargetFramework -testadapterpath "$ArtifactsDir\bin\FSharp.Compiler.Service.Tests\"
603-
TestUsingMSBuild -testProject "$RepoRoot\tests\FSharp.Compiler.Private.Scripting.UnitTests\FSharp.Compiler.Private.Scripting.UnitTests.fsproj" -targetFramework $script:coreclrTargetFramework -testadapterpath "$ArtifactsDir\bin\FSharp.Compiler.Private.Scripting.UnitTests\"
604-
TestUsingMSBuild -testProject "$RepoRoot\tests\FSharp.Build.UnitTests\FSharp.Build.UnitTests.fsproj" -targetFramework $script:coreclrTargetFramework -testadapterpath "$ArtifactsDir\bin\FSharp.Build.UnitTests\"
605-
TestUsingMSBuild -testProject "$RepoRoot\tests\FSharp.Core.UnitTests\FSharp.Core.UnitTests.fsproj" -targetFramework $script:coreclrTargetFramework -testadapterpath "$ArtifactsDir\bin\FSharp.Core.UnitTests\"
603+
function Receive($job) {
604+
while($job.HasMoreData) {
605+
Receive-Job $job | Write-Host
606+
Start-Sleep -Seconds 1
607+
}
608+
Receive-Job $job -Wait -ErrorAction Stop
609+
}
606610

607-
# Collect output from background jobs
608-
Wait-job $bgJob | out-null
609-
Receive-Job $bgJob -ErrorAction Stop
611+
if ($testCoreClr) {
612+
$cpuLimit = if ($ci) { "-m:2 -- xUnit.MaxParallelThreads=0.25x" } else { "" }
613+
TestUsingMSBuild -testProject "$RepoRoot\FSharp.sln" -targetFramework $script:coreclrTargetFramework -testadapterpath "$ArtifactsDir\bin\FSharp.Compiler.ComponentTests\" -settings $cpuLimit
610614
}
611615

612-
if ($testDesktop) {
616+
if ($testDesktop -and $ci) {
613617
$bgJob = TestUsingMSBuild -testProject "$RepoRoot\tests\fsharp\FSharpSuite.Tests.fsproj" -targetFramework $script:desktopTargetFramework -testadapterpath "$ArtifactsDir\bin\FSharpSuite.Tests\" -asBackgroundJob $true
614618

615619
TestUsingMSBuild -testProject "$RepoRoot\tests\FSharp.Compiler.ComponentTests\FSharp.Compiler.ComponentTests.fsproj" -targetFramework $script:desktopTargetFramework -testadapterpath "$ArtifactsDir\bin\FSharp.Compiler.ComponentTests\"
@@ -618,9 +622,11 @@ try {
618622
TestUsingMSBuild -testProject "$RepoRoot\tests\FSharp.Build.UnitTests\FSharp.Build.UnitTests.fsproj" -targetFramework $script:desktopTargetFramework -testadapterpath "$ArtifactsDir\bin\FSharp.Build.UnitTests\"
619623
TestUsingMSBuild -testProject "$RepoRoot\tests\FSharp.Core.UnitTests\FSharp.Core.UnitTests.fsproj" -targetFramework $script:desktopTargetFramework -testadapterpath "$ArtifactsDir\bin\FSharp.Core.UnitTests\"
620624

621-
# Collect output from background jobs
622-
Wait-job $bgJob | out-null
623-
Receive-Job $bgJob -ErrorAction Stop
625+
Receive -job $bgJob
626+
}
627+
628+
if ($testDesktop -and -not $ci ) {
629+
TestUsingMSBuild -testProject "$RepoRoot\FSharp.sln" -targetFramework $script:desktopTargetFramework -testadapterpath "$ArtifactsDir\bin\FSharp.Compiler.ComponentTests\"
624630
}
625631

626632
if ($testFSharpQA) {

eng/build.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ function Test() {
219219
projectname=$(basename -- "$testproject")
220220
projectname="${projectname%.*}"
221221
testlogpath="$artifacts_dir/TestResults/$configuration/${projectname}_$targetframework.xml"
222-
args="test \"$testproject\" --no-restore --no-build -c $configuration -f $targetframework --test-adapter-path . --logger \"xunit;LogFilePath=$testlogpath\" --blame --results-directory $artifacts_dir/TestResults/$configuration -p:vstestusemsbuildoutput=false"
222+
args="test \"$testproject\" --no-restore --no-build -c $configuration -f $targetframework --test-adapter-path . --logger \"xunit;LogFilePath=$testlogpath\" --blame-hang-timeout 5minutes --results-directory $artifacts_dir/TestResults/$configuration -p:vstestusemsbuildoutput=false"
223+
args+=" -- xUnit.MaxParallelThreads=3"
223224
"$DOTNET_INSTALL_DIR/dotnet" $args || exit $?
224225
}
225226

tests/FSharp.Build.UnitTests/FSharp.Build.UnitTests.fsproj

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<PropertyGroup>
66
<TargetFrameworks>net472;$(FSharpNetCoreProductTargetFramework)</TargetFrameworks>
7-
<TargetFrameworks Condition="'$(OS)' == 'Unix'">$(FSharpNetCoreProductTargetFramework)</TargetFrameworks>
7+
<TargetFrameworks Condition="'$(OS)' == 'Unix' or '$(BUILDING_USING_DOTNET)' == 'true'">$(FSharpNetCoreProductTargetFramework)</TargetFrameworks>
88
<OutputType>Library</OutputType>
99
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
1010
<UnitTestType>xunit</UnitTestType>
@@ -18,6 +18,12 @@
1818
<Compile Include="MapSourceRootsTests.fs" />
1919
</ItemGroup>
2020

21+
<ItemGroup>
22+
<Content Include="xunit.runner.json">
23+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
24+
</Content>
25+
</ItemGroup>
26+
2127
<ItemGroup>
2228
<ProjectReference Include="$(FSharpSourcesRoot)\FSharp.Build\FSharp.Build.fsproj" />
2329
<ProjectReference Include="$(FSharpSourcesRoot)\FSharp.Core\FSharp.Core.fsproj" />
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"$schema": "https://xunit.net/schema/current/xunit.runner.schema.json",
3+
"appDomain": "denied",
4+
"parallelizeAssembly": true
5+
}

tests/FSharp.Compiler.ComponentTests/CompilerOptions/fsc/misc/utf8output.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ open FSharp.Test
77
open FSharp.Test.Compiler
88
open System
99

10+
[<Collection(nameof NotThreadSafeResourceCollection)>]
1011
module utf8output =
1112

1213
[<Fact>]

tests/FSharp.Compiler.ComponentTests/CompilerOptions/fsc/times/times.fs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ open FSharp.Test.Compiler
88
open System
99
open System.IO
1010

11+
// reportTime uses global state.
12+
[<Collection(nameof NotThreadSafeResourceCollection)>]
1113
module times =
1214

1315
// This test was automatically generated (moved from FSharpQA suite - CompilerOptions/fsc/times)

tests/FSharp.Compiler.ComponentTests/CompilerService/AsyncMemoize.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ let internal observe (cache: AsyncMemoize<_,_,_>) =
2828

2929
cache.Event.Add arrivals.Post
3030

31-
let next () = collected.Receive(10_000)
31+
let next () = collected.Receive()
3232

3333
next
3434

tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/AssemblyVersion04.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ let success =
1414
asm.Version.Major = 1 &&
1515
asm.Version.Minor = 2 &&
1616
asm.Version.Build = 3 &&
17-
(abs (asm.Version.Revision - (int defaultRevision))) < 10 // default value is seconds in the current day / 2. Check if within 10 sec of that.
17+
(abs (asm.Version.Revision - (int defaultRevision))) < 60 // default value is seconds in the current day / 2. Check if within 60 sec of that.
1818
if success then () else failwith "Failed: 1"

tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/Events/Basic/Basic.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ open Xunit
66
open FSharp.Test
77
open FSharp.Test.Compiler
88

9+
[<Collection(nameof NotThreadSafeResourceCollection)>]
910
module Events =
1011

1112
let verifyCompile compilation =

tests/FSharp.Compiler.ComponentTests/FSharpChecker/TransparentCompiler.fs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
module FSharpChecker.TransparentCompiler
1+
[<Xunit.Collection(nameof FSharp.Test.NotThreadSafeResourceCollection)>]
2+
module FSharpChecker.TransparentCompiler
23

34
open System.Collections.Concurrent
45
open System.Diagnostics
@@ -991,6 +992,8 @@ type private LoadClosureTestShim(currentFileSystem: IFileSystem) =
991992
?shouldShadowCopy = shouldShadowCopy
992993
)
993994

995+
// Because it is mutating FileSystem!
996+
[<Collection(nameof NotThreadSafeResourceCollection)>]
994997
module TestsMutatingFileSystem =
995998

996999
[<Theory>]

0 commit comments

Comments
 (0)