|
| 1 | +namespace FSharpy.Tests |
| 2 | + |
| 3 | +open System |
| 4 | +open System.Threading.Tasks |
| 5 | +open System.Reflection |
| 6 | + |
| 7 | +open Xunit |
| 8 | +open FsUnit.Xunit |
| 9 | +open FsToolkit.ErrorHandling |
| 10 | + |
| 11 | +open FSharpy |
| 12 | +open Xunit.Abstractions |
| 13 | + |
| 14 | + |
| 15 | +type AllTests(output: ITestOutputHelper) = |
| 16 | + let createParallelRunner () = |
| 17 | + let myAsm = Assembly.GetExecutingAssembly() |
| 18 | + |
| 19 | + let allMethods = [ |
| 20 | + for ty in myAsm.DefinedTypes do |
| 21 | + for mem in ty.DeclaredMembers do |
| 22 | + match mem.MemberType with |
| 23 | + | MemberTypes.Method -> |
| 24 | + if mem.Name.StartsWith("TaskSeq") || mem.Name.StartsWith("CE") then |
| 25 | + yield ty, mem :?> MethodInfo |
| 26 | + | _ -> () |
| 27 | + ] |
| 28 | + |
| 29 | + let all = seq { |
| 30 | + for (ty, method) in allMethods do |
| 31 | + let ctor = ty.GetConstructor [| typeof<ITestOutputHelper> |] |
| 32 | + |
| 33 | + if isNull ctor then |
| 34 | + failwith "Constructor for test not found" |
| 35 | + |
| 36 | + let testObj = ctor.Invoke([| output |]) |
| 37 | + |
| 38 | + if method.ReturnType.Name.Contains "Task" then |
| 39 | + //task { |
| 40 | + // let! x = Async.StartChildAsTask (Async.ofTask (method.Invoke(testObj, null) :?> Task<unit>)) |
| 41 | + // return! x |
| 42 | + //} |
| 43 | + async { |
| 44 | + return! |
| 45 | + method.Invoke(testObj, null) :?> Task<unit> |
| 46 | + |> Async.AwaitTask |
| 47 | + } |
| 48 | + else |
| 49 | + async { return method.Invoke(testObj, null) |> ignore } |
| 50 | + } |
| 51 | + |
| 52 | + all |> Async.Parallel |> Async.map ignore |
| 53 | + |
| 54 | + let multiply f x = |
| 55 | + seq { |
| 56 | + for i in [ 0..x ] do |
| 57 | + yield f () |
| 58 | + } |
| 59 | + |> Async.Parallel |
| 60 | + |> Async.map ignore |
| 61 | + |
| 62 | + [<Fact>] |
| 63 | + let ``Run all tests 1 times in parallel`` () = task { do! multiply createParallelRunner 1 } |
| 64 | + |
| 65 | + [<Theory>] |
| 66 | + [<InlineData 1; InlineData 2; InlineData 3; InlineData 4; InlineData 5; InlineData 6; InlineData 7; InlineData 8>] |
| 67 | + let ``Run all tests X times in parallel`` i = task { do! multiply createParallelRunner i } |
| 68 | + |
| 69 | + [<Theory>] |
| 70 | + [<InlineData 1; InlineData 2; InlineData 3; InlineData 4; InlineData 5; InlineData 6; InlineData 7; InlineData 8>] |
| 71 | + let ``Run all tests again X times in parallel`` i = task { do! multiply createParallelRunner i } |
| 72 | + |
| 73 | + [<Theory>] |
| 74 | + [<InlineData 1; InlineData 2; InlineData 3; InlineData 4; InlineData 5; InlineData 6; InlineData 7; InlineData 8>] |
| 75 | + let ``Run all tests and once more, X times in parallel`` i = task { do! multiply createParallelRunner i } |
| 76 | + |
| 77 | + |
| 78 | +//[<Fact>] |
| 79 | +//let ``Run all tests 3 times in parallel`` () = |
| 80 | +// multiply createParallelRunner 15 |
| 81 | +// |> Async.RunSynchronously |
| 82 | + |
| 83 | + |
| 84 | +//[<Fact>] |
| 85 | +//let ``Run all tests 4 times in parallel`` () = |
| 86 | +// multiply createParallelRunner 15 |
| 87 | +// |> Async.RunSynchronously |
| 88 | + |
| 89 | + |
| 90 | +//[<Fact>] |
| 91 | +//let ``Run all tests 5 times in parallel`` () = |
| 92 | +// multiply createParallelRunner 15 |
| 93 | +// |> Async.RunSynchronously |
| 94 | + |
| 95 | + |
| 96 | +//[<Fact>] |
| 97 | +//let ``Run all tests 6 times in parallel`` () = |
| 98 | +// multiply createParallelRunner 15 |
| 99 | +// |> Async.RunSynchronously |
| 100 | + |
| 101 | + |
| 102 | +//[<Fact>] |
| 103 | +//let ``Run all tests 7 times in parallel`` () = |
| 104 | +// multiply createParallelRunner 15 |
| 105 | +// |> Async.RunSynchronously |
| 106 | + |
| 107 | + |
| 108 | +//[<Fact>] |
| 109 | +//let ``Run all tests 8 times in parallel`` () = |
| 110 | +// multiply createParallelRunner 15 |
| 111 | +// |> Async.RunSynchronously |
| 112 | + |
| 113 | + |
| 114 | +//[<Fact>] |
| 115 | +//let ``Run all tests 9 times in parallel`` () = |
| 116 | +// multiply createParallelRunner 15 |
| 117 | +// |> Async.RunSynchronously |
| 118 | + |
| 119 | + |
| 120 | +//[<Fact>] |
| 121 | +//let ``Run all tests 10 times in parallel`` () = |
| 122 | +// multiply createParallelRunner 15 |
| 123 | +// |> Async.RunSynchronously |
| 124 | + |
| 125 | + |
| 126 | +//[<Fact>] |
| 127 | +//let ``Run all tests 11 times in parallel`` () = |
| 128 | +// multiply createParallelRunner 15 |
| 129 | +// |> Async.RunSynchronously |
| 130 | + |
| 131 | + |
| 132 | +//[<Fact>] |
| 133 | +//let ``Run all tests 12 times in parallel`` () = |
| 134 | +// multiply createParallelRunner 15 |
| 135 | +// |> Async.RunSynchronously |
| 136 | + |
| 137 | + |
| 138 | +//[<Fact>] |
| 139 | +//let ``Run all tests 13 times in parallel`` () = |
| 140 | +// multiply createParallelRunner 15 |
| 141 | +// |> Async.RunSynchronously |
| 142 | + |
| 143 | + |
| 144 | +//[<Fact>] |
| 145 | +//let ``Run all tests 14 times in parallel`` () = |
| 146 | +// multiply createParallelRunner 15 |
| 147 | +// |> Async.RunSynchronously |
| 148 | + |
| 149 | + |
| 150 | +//[<Fact>] |
| 151 | +//let ``Run all tests 15 times in parallel`` () = |
| 152 | +// multiply createParallelRunner 15 |
| 153 | +// |> Async.RunSynchronously |
0 commit comments