Skip to content

Commit 605486e

Browse files
authored
Cache: immediate eviction in net4 tests (#18889)
1 parent bf88205 commit 605486e

File tree

5 files changed

+23
-4
lines changed

5 files changed

+23
-4
lines changed

azure-pipelines-PR.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ stages:
321321

322322
- script: eng\CIBuildNoPublish.cmd -compressallmetadata -buildnorealsig -testDesktop -configuration Release -testBatch $(System.JobPositionInPhase)
323323
env:
324+
FSharp_CacheEvictionImmediate: true
324325
DOTNET_DbgEnableMiniDump: 1
325326
DOTNET_DbgMiniDumpType: 3 # Triage dump, 1 for mini, 2 for Heap, 3 for triage, 4 for full. Don't use 4 unless you know what you're doing.
326327
DOTNET_DbgMiniDumpName: $(Build.SourcesDirectory)\artifacts\log\Release\$(Build.BuildId)-%e-%p-%t.dmp
@@ -456,11 +457,13 @@ stages:
456457
fsharpqa_release:
457458
_configuration: Release
458459
_testKind: testFSharpQA
460+
FSharp_CacheEvictionImmediate: true
459461
transparentCompiler:
460462
vs_release:
461463
_configuration: Release
462464
_testKind: testVs
463465
setupVsHive: true
466+
FSharp_CacheEvictionImmediate: true
464467
transparentCompiler:
465468
transparent_compiler_release:
466469
_configuration: Release
@@ -559,6 +562,7 @@ stages:
559562

560563
- script: eng\CIBuildNoPublish.cmd -compressallmetadata -configuration Release -testDesktop -testBatch $(System.JobPositionInPhase)
561564
env:
565+
FSharp_CacheEvictionImmediate: true
562566
DOTNET_DbgEnableMiniDump: 1
563567
DOTNET_DbgMiniDumpType: 3 # Triage dump, 1 for mini, 2 for Heap, 3 for triage, 4 for full. Don't use 4 unless you know what you're doing.
564568
DOTNET_DbgMiniDumpName: $(Build.SourcesDirectory)\artifacts\log\Release\$(Build.BuildId)-%e-%p-%t.dmp

src/Compiler/Utilities/Caches.fs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,23 @@ type CacheOptions<'Key> =
194194
}
195195

196196
module CacheOptions =
197+
let forceImmediate =
198+
try
199+
Environment.GetEnvironmentVariable("FSharp_CacheEvictionImmediate") <> null
200+
with _ ->
201+
false
202+
203+
let defaultEvictionMode =
204+
if forceImmediate then
205+
EvictionMode.Immediate
206+
else
207+
EvictionMode.MailboxProcessor
197208

198209
let getDefault comparer =
199210
{
200211
CacheOptions.TotalCapacity = 1024
201212
CacheOptions.HeadroomPercentage = 50
202-
CacheOptions.EvictionMode = EvictionMode.MailboxProcessor
213+
CacheOptions.EvictionMode = defaultEvictionMode
203214
CacheOptions.Comparer = comparer
204215
}
205216

tests/Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<NoOptimizationData>false</NoOptimizationData>
1717
<NoInterfaceData>false</NoInterfaceData>
1818
<CompressMetadata>true</CompressMetadata>
19+
<ServerGarbageCollection>true</ServerGarbageCollection>
1920
</PropertyGroup>
2021

2122
</Project>

tests/FSharp.Test.Utilities/CompilerAssert.fs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,23 +376,25 @@ module CompilerAssertHelpers =
376376
let setup = AppDomainSetup(ApplicationBase = thisAssemblyDirectory)
377377
let testCaseDomain = AppDomain.CreateDomain($"built app {assembly}", null, setup)
378378

379-
testCaseDomain.add_AssemblyResolve(fun _ args ->
379+
let handler = ResolveEventHandler(fun _ args ->
380380
dependecies
381381
|> List.tryFind (fun path -> Path.GetFileNameWithoutExtension path = AssemblyName(args.Name).Name)
382382
|> Option.filter FileSystem.FileExistsShim
383383
|> Option.map Assembly.LoadFile
384384
|> Option.toObj
385385
)
386386

387+
testCaseDomain.add_AssemblyResolve handler
388+
387389
let worker =
388390
(testCaseDomain.CreateInstanceFromAndUnwrap(typeof<Worker>.Assembly.CodeBase, typeof<Worker>.FullName)) :?> Worker
389391

390392
let outcome, output, errors = worker.ExecuteTestCase assembly isFsx
391393
// Replay streams captured in appdomain.
392394
printf $"{output}"
393395
eprintf $"{errors}"
394-
395-
AppDomain.Unload testCaseDomain
396+
397+
testCaseDomain.remove_AssemblyResolve handler
396398

397399
outcome, output, errors
398400

tests/FSharp.Test.Utilities/XunitHelpers.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ module OneTimeSetup =
202202
log "Adding AssemblyResolver"
203203
AssemblyResolver.addResolver ()
204204
#endif
205+
log $"Server GC enabled: {System.Runtime.GCSettings.IsServerGC}"
205206
log "Installing TestConsole redirection"
206207
TestConsole.install()
207208

0 commit comments

Comments
 (0)