Skip to content

Commit a2641f5

Browse files
committed
test MultipleDiagnosticsLoggers
1 parent f711156 commit a2641f5

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

tests/FSharp.Compiler.UnitTests/BuildGraphTests.fs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ open FSharp.Compiler.BuildGraph
1111
open FSharp.Compiler.DiagnosticsLogger
1212
open Internal.Utilities.Library
1313
open FSharp.Compiler.Diagnostics
14+
open FSharp.Compiler.Tokenization.FSharpTokenTag
1415

1516
module BuildGraphTests =
1617

@@ -338,6 +339,45 @@ module BuildGraphTests =
338339

339340
Tasks.Parallel.Invoke(task1, task2)
340341

342+
343+
type internal DiagnosticsLoggerWithCallback(callback) =
344+
inherit CapturingDiagnosticsLogger("test")
345+
override _.DiagnosticSink(e, s) =
346+
base.DiagnosticSink(e, s)
347+
callback e.Exception.Message |> ignore
348+
349+
[<Fact>]
350+
let ``MultipleDiagnosticsLoggers capture diagnostics in correct order`` () =
351+
352+
let mutable prevError = "000."
353+
354+
let errorCommitted msg =
355+
// errors come in correct order
356+
Assert.shouldBeTrue (msg > prevError)
357+
prevError <- msg
358+
359+
let work i = async {
360+
for c in 'A' .. 'F' do
361+
do! Async.SwitchToThreadPool()
362+
errorR (ExampleException $"%03d{i}{c}")
363+
}
364+
365+
let tasks = Seq.init 100 work
366+
367+
let logger = DiagnosticsLoggerWithCallback errorCommitted
368+
use _ = UseDiagnosticsLogger logger
369+
tasks |> Seq.take 50 |> MultipleDiagnosticsLoggers.Parallel |> Async.Ignore |> Async.RunImmediate
370+
371+
// all errors committed
372+
errorCountShouldBe 300
373+
374+
tasks |> Seq.skip 50 |> MultipleDiagnosticsLoggers.Sequential |> Async.Ignore |> Async.RunImmediate
375+
376+
errorCountShouldBe 600
377+
378+
379+
380+
341381
[<Fact>]
342382
let ``AsyncLocal diagnostics context flows correctly`` () =
343383

0 commit comments

Comments
 (0)