Skip to content

Fix GC test that is flaky on Linux #18408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions tests/FSharp.Compiler.Service.Tests/ProjectAnalysisTests.fs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module FSharp.Compiler.Service.Tests.ProjectAnalysisTests

open System.Threading.Tasks

#nowarn "57" // Experimental stuff

let runningOnMono = try System.Type.GetType("Mono.Runtime") <> null with e -> false
Expand Down Expand Up @@ -128,8 +130,20 @@ module ClearLanguageServiceRootCachesTest =
let weakTcImports = test ()
checker.InvalidateConfiguration Project1.options
checker.ClearLanguageServiceRootCachesAndCollectAndFinalizeAllTransients()
GC.Collect()
System.Threading.SpinWait.SpinUntil(fun () -> not weakTcImports.IsAlive)

task {
GC.Collect()
GC.WaitForPendingFinalizers()
// Try collecting many times, because GC has some problems, especially on Linux.
// See for example: https://github.com/dotnet/runtime/discussions/108081
let mutable attempt = 1
while weakTcImports.IsAlive && attempt < 10 do
GC.Collect()
GC.WaitForPendingFinalizers()
attempt <- attempt + 1
do! Task.Delay(attempt * 1000)
Assert.False weakTcImports.IsAlive
}

[<Fact>]
let ``Test Project1 should have protected FullName and TryFullName return same results`` () =
Expand Down