From d53a38c019b361a1f5b72362f199c86e829adc7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Chassaing?= Date: Tue, 23 Jul 2019 00:57:02 +0200 Subject: [PATCH] Moving Libraries Control tests to NUnit (#7234) * Moving Libraries Control tests to NUnit * Names tests as Async instead of Control --- tests/fsharp/FSharpSuite.Tests.fsproj | 1 + tests/fsharp/Libraries/Async/AsyncTests.fs | 168 ++++++++++++++++++ .../Control/ExecuteAsyncMultipleTimes01.fs | 17 -- .../Libraries/Control/JoiningStartChild01.fs | 25 --- .../Control/MailboxAsyncNoStackOverflow01.fs | 78 -------- .../StartChildNoObjectDisposedException01.fs | 12 -- .../StartChildTestTrampolineHijackLimit01.fs | 19 -- .../fsharpqa/Source/Libraries/Control/env.lst | 6 - 8 files changed, 169 insertions(+), 157 deletions(-) create mode 100644 tests/fsharp/Libraries/Async/AsyncTests.fs delete mode 100644 tests/fsharpqa/Source/Libraries/Control/ExecuteAsyncMultipleTimes01.fs delete mode 100644 tests/fsharpqa/Source/Libraries/Control/JoiningStartChild01.fs delete mode 100644 tests/fsharpqa/Source/Libraries/Control/MailboxAsyncNoStackOverflow01.fs delete mode 100644 tests/fsharpqa/Source/Libraries/Control/StartChildNoObjectDisposedException01.fs delete mode 100644 tests/fsharpqa/Source/Libraries/Control/StartChildTestTrampolineHijackLimit01.fs delete mode 100644 tests/fsharpqa/Source/Libraries/Control/env.lst diff --git a/tests/fsharp/FSharpSuite.Tests.fsproj b/tests/fsharp/FSharpSuite.Tests.fsproj index 9d80400c401..9291db2f740 100644 --- a/tests/fsharp/FSharpSuite.Tests.fsproj +++ b/tests/fsharp/FSharpSuite.Tests.fsproj @@ -48,6 +48,7 @@ + diff --git a/tests/fsharp/Libraries/Async/AsyncTests.fs b/tests/fsharp/Libraries/Async/AsyncTests.fs new file mode 100644 index 00000000000..04a82a97160 --- /dev/null +++ b/tests/fsharp/Libraries/Async/AsyncTests.fs @@ -0,0 +1,168 @@ +namespace FSharp.Libraries.UnitTests + +open System +open NUnit.Framework +open FSharp.Compiler.UnitTests + +[] +module AsyncTests = + // Regression for FSHARP1.0:5969 + // Async.StartChild: error when wait async is executed more than once + [] + let ``Execute Async multiple times``() = + CompilerAssert.CompileExeAndRun + """ +module M + +let a = async { + let! a = Async.StartChild( + async { + do! Async.Sleep(1) + return 27 + }) + let! result = Async.Parallel [ a; a; a; a ] + return result + } |> Async.RunSynchronously + +exit 0 + """ + + + // Regression for FSHARP1.0:5970 + // Async.StartChild: race in implementation of ResultCell in FSharp.Core + [] + let ``Joining StartChild``() = + CompilerAssert.CompileExeAndRun + """ +module M + +let Join (a1: Async<'a>) (a2: Async<'b>) = async { + let! task1 = a1 |> Async.StartChild + let! task2 = a2 |> Async.StartChild + + let! res1 = task1 + let! res2 = task2 + return (res1,res2) } + +let r = + try + Async.RunSynchronously (Join (async { do! Async.Sleep(30) + failwith "fail" + return 3+3 }) + (async { do! Async.Sleep(30) + return 2 + 2 } )) + with _ -> + (0,0) + +exit 0 + + """ + + // Regression test for FSHARP1.0:6086 + [] + let ``Mailbox Async dot not StackOverflow``() = + CompilerAssert.CompileExeAndRun + """ +open Microsoft.FSharp.Control + +type Color = Blue | Red | Yellow +let complement = function + | (Red, Yellow) | (Yellow, Red) -> Blue + | (Red, Blue) | (Blue, Red) -> Yellow + | (Yellow, Blue) | (Blue, Yellow) -> Red + | (Blue, Blue) -> Blue + | (Red, Red) -> Red + | (Yellow, Yellow) -> Yellow + +type Message = Color * AsyncReplyChannel + +let chameleon (meetingPlace : MailboxProcessor) initial = + let rec loop c meets = async { + let replyMessage = meetingPlace.PostAndReply(fun reply -> c, reply) + match replyMessage with + | Some(newColor) -> return! loop newColor (meets + 1) + | None -> return meets + } + loop initial 0 + +let meetingPlace chams n = MailboxProcessor.Start(fun (processor : MailboxProcessor)-> + let rec fadingLoop total = + async { + if total <> 0 then + let! (_, reply) = processor.Receive() + reply.Reply None + return! fadingLoop (total - 1) + else + printfn "Done" + } + let rec mainLoop curr = + async { + if (curr > 0) then + let! (color1, reply1) = processor.Receive() + let! (color2, reply2) = processor.Receive() + let newColor = complement (color1, color2) + reply1.Reply <| Some(newColor) + reply2.Reply <| Some(newColor) + return! mainLoop (curr - 1) + else + return! fadingLoop chams + } + mainLoop n + ) + +open System +open System.Diagnostics + +let meetings = 100000 + +let colors = [Blue; Red; Yellow; Blue] +let mp = meetingPlace (colors.Length) meetings +let watch = Stopwatch.StartNew() +let meets = + colors + |> List.map (chameleon mp) + |> Async.Parallel + |> Async.RunSynchronously +watch.Stop() +for meet in meets do + printfn "%d" meet +printfn "Total: %d in %O" (Seq.sum meets) (watch.Elapsed) + +exit 0 + """ + + // Regression for FSHARP1.0:5971 + [] + let ``StartChild do not throw ObjectDisposedException``() = + CompilerAssert.CompileExeAndRun + """ +module M + +let b = async {return 5} |> Async.StartChild +printfn "%A" (b |> Async.RunSynchronously |> Async.RunSynchronously) + +exit 0 + """ + + + [] + let ``StartChild test Trampoline HijackLimit``() = + CompilerAssert.CompileExeAndRun + """ +module M + +let r = + async { + let! a = Async.StartChild( + async { + do! Async.Sleep(1) + return 5 + } + ) + let! _ = a + for __ in 1..10000 do // 10000 > bindHijackLimit + () + } |> Async.RunSynchronously + +exit 0 + """ diff --git a/tests/fsharpqa/Source/Libraries/Control/ExecuteAsyncMultipleTimes01.fs b/tests/fsharpqa/Source/Libraries/Control/ExecuteAsyncMultipleTimes01.fs deleted file mode 100644 index e042c6f02df..00000000000 --- a/tests/fsharpqa/Source/Libraries/Control/ExecuteAsyncMultipleTimes01.fs +++ /dev/null @@ -1,17 +0,0 @@ -// #Regression #Libraries #Async -// Regression for FSHARP1.0:5969 -// Async.StartChild: error when wait async is executed more than once - -module M - -let a = async { - let! a = Async.StartChild( - async { - do! Async.Sleep(500) - return 27 - }) - let! result = Async.Parallel [ a; a; a; a ] - return result - } |> Async.RunSynchronously - -exit 0 diff --git a/tests/fsharpqa/Source/Libraries/Control/JoiningStartChild01.fs b/tests/fsharpqa/Source/Libraries/Control/JoiningStartChild01.fs deleted file mode 100644 index 692bb583844..00000000000 --- a/tests/fsharpqa/Source/Libraries/Control/JoiningStartChild01.fs +++ /dev/null @@ -1,25 +0,0 @@ -// #Regression #Libraries #Async -// Regression for FSHARP1.0:5970 -// Async.StartChild: race in implementation of ResultCell in FSharp.Core - -module M - -let Join (a1: Async<'a>) (a2: Async<'b>) = async { - let! task1 = a1 |> Async.StartChild - let! task2 = a2 |> Async.StartChild - - let! res1 = task1 - let! res2 = task2 - return (res1,res2) } - -let r = - try - Async.RunSynchronously (Join (async { do! Async.Sleep(30) - failwith "fail" - return 3+3 }) - (async { do! Async.Sleep(30) - return 2 + 2 } )) - with _ -> - (0,0) - -exit 0 diff --git a/tests/fsharpqa/Source/Libraries/Control/MailboxAsyncNoStackOverflow01.fs b/tests/fsharpqa/Source/Libraries/Control/MailboxAsyncNoStackOverflow01.fs deleted file mode 100644 index 33e0e590a7b..00000000000 --- a/tests/fsharpqa/Source/Libraries/Control/MailboxAsyncNoStackOverflow01.fs +++ /dev/null @@ -1,78 +0,0 @@ -// #Regression #Libraries #Async -// Regression test for FSHARP1.0:6086 -// This is a bit of duplication because the same/similar test -// can also be found under the FSHARP suite. Yet, I like to have -// it here... - -// The interesting thing about this test is that is used to throw -// an exception when executed on 64bit (FSharp.Core 2.0) - -open Microsoft.FSharp.Control - -type Color = Blue | Red | Yellow -let complement = function - | (Red, Yellow) | (Yellow, Red) -> Blue - | (Red, Blue) | (Blue, Red) -> Yellow - | (Yellow, Blue) | (Blue, Yellow) -> Red - | (Blue, Blue) -> Blue - | (Red, Red) -> Red - | (Yellow, Yellow) -> Yellow - -type Message = Color * AsyncReplyChannel - -let chameleon (meetingPlace : MailboxProcessor) initial = - let rec loop c meets = async { - let replyMessage = meetingPlace.PostAndReply(fun reply -> c, reply) - match replyMessage with - | Some(newColor) -> return! loop newColor (meets + 1) - | None -> return meets - } - loop initial 0 - -let meetingPlace chams n = MailboxProcessor.Start(fun (processor : MailboxProcessor)-> - let rec fadingLoop total = - async { - if total <> 0 then - let! (_, reply) = processor.Receive() - reply.Reply None - return! fadingLoop (total - 1) - else - printfn "Done" - } - let rec mainLoop curr = - async { - if (curr > 0) then - let! (color1, reply1) = processor.Receive() - let! (color2, reply2) = processor.Receive() - let newColor = complement (color1, color2) - reply1.Reply <| Some(newColor) - reply2.Reply <| Some(newColor) - return! mainLoop (curr - 1) - else - return! fadingLoop chams - } - mainLoop n - ) - -open System -open System.Diagnostics - -[] -let main(args : string[]) = - printfn "CommandLine : %s" (String.concat ", " args) - let meetings = if args.Length > 0 then Int32.Parse(args.[0]) else 100000 - - let colors = [Blue; Red; Yellow; Blue] - let mp = meetingPlace (colors.Length) meetings - let watch = Stopwatch.StartNew() - let meets = - colors - |> List.map (chameleon mp) - |> Async.Parallel - |> Async.RunSynchronously - watch.Stop() - for meet in meets do - printfn "%d" meet - printfn "Total: %d in %O" (Seq.sum meets) (watch.Elapsed) - 0 - diff --git a/tests/fsharpqa/Source/Libraries/Control/StartChildNoObjectDisposedException01.fs b/tests/fsharpqa/Source/Libraries/Control/StartChildNoObjectDisposedException01.fs deleted file mode 100644 index 5186548c79a..00000000000 --- a/tests/fsharpqa/Source/Libraries/Control/StartChildNoObjectDisposedException01.fs +++ /dev/null @@ -1,12 +0,0 @@ -// #Regression #Libraries #Async -// Regression for FSHARP1.0:5971 -// Async.StartChild: ObjectDisposedException - -module M - -let shortVersion(args: string []) = - let b = async {return 5} |> Async.StartChild - printfn "%A" (b |> Async.RunSynchronously |> Async.RunSynchronously) - (0) - -exit 0 diff --git a/tests/fsharpqa/Source/Libraries/Control/StartChildTestTrampolineHijackLimit01.fs b/tests/fsharpqa/Source/Libraries/Control/StartChildTestTrampolineHijackLimit01.fs deleted file mode 100644 index 46cfeb59376..00000000000 --- a/tests/fsharpqa/Source/Libraries/Control/StartChildTestTrampolineHijackLimit01.fs +++ /dev/null @@ -1,19 +0,0 @@ -// #Regression #Libraries #Async -// Regression for FSHARP1.0:5972 -// Async.StartChild: fails to install trampolines properly -module M - -let r = - async { - let! a = Async.StartChild( - async { - do! Async.Sleep(500) - return 5 - } - ) - let! b = a - for i in 1..10000 do // 10000 > bindHijackLimit - () - } |> Async.RunSynchronously - -exit 0 diff --git a/tests/fsharpqa/Source/Libraries/Control/env.lst b/tests/fsharpqa/Source/Libraries/Control/env.lst deleted file mode 100644 index 6c034ca5b46..00000000000 --- a/tests/fsharpqa/Source/Libraries/Control/env.lst +++ /dev/null @@ -1,6 +0,0 @@ - SOURCE=MailboxAsyncNoStackOverflow01.fs # MailboxAsyncNoStackOverflow01.fs - - SOURCE=ExecuteAsyncMultipleTimes01.fs # ExecuteAsyncMultipleTimes01.fs - SOURCE=JoiningStartChild01.fs # JoiningStartChild01.fs - SOURCE=StartChildNoObjectDisposedException01.fs # StartChildNoObjectDisposedException01.fs - SOURCE=StartChildTestTrampolineHijackLimit01.fs # StartChildTestTrampolineHijackLimit01.fs \ No newline at end of file