Skip to content

Commit 643039a

Browse files
authored
improve handling of many tests cases (#10)
fix: many tests in single file If there are more than 400 tests in a single file vstest will split up the discovery results
1 parent 4d991d5 commit 643039a

File tree

1 file changed

+28
-29
lines changed

1 file changed

+28
-29
lines changed

scripts/run_tests.fsx

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ type NeotestResult =
3838
errors: NeoTestResultError array }
3939

4040
module TestDiscovery =
41+
open System.Collections.Concurrent
42+
4143
let parseArgs (args: string) =
4244
args.Split(" ", StringSplitOptions.TrimEntries &&& StringSplitOptions.RemoveEmptyEntries)
4345
|> Array.tail
@@ -89,50 +91,46 @@ module TestDiscovery =
8991
else
9092
Console.WriteLine(message)
9193

92-
let mutable discoveredTests = Map.empty<string, TestCase seq>
93-
94-
let getTestCases ids =
95-
let idMap =
96-
discoveredTests
97-
|> Map.values
98-
|> Seq.collect (Seq.map (fun testCase -> testCase.Id, testCase))
99-
|> Map
94+
let discoveredTests = ConcurrentDictionary<Guid, TestCase>()
10095

101-
ids |> Array.choose (fun id -> Map.tryFind id idMap)
96+
let getTestCases (ids: Guid seq) =
97+
discoveredTests
98+
|> Seq.choose (fun kv -> if ids |> Seq.contains kv.Key then Some kv.Value else None)
10299

103100
type PlaygroundTestDiscoveryHandler(waitFile: string, outputFile: string) =
104101
interface ITestDiscoveryEventsHandler2 with
105102
member _.HandleDiscoveredTests(discoveredTestCases: IEnumerable<TestCase>) =
106103
Console.WriteLine($"Discovered tests: {Seq.length discoveredTestCases}")
107104

108105
discoveredTestCases
109-
|> Seq.groupBy (fun testCase ->
106+
|> Seq.iter (fun testCase ->
110107
if String.IsNullOrWhiteSpace testCase.CodeFilePath then
111-
testCase.Source
112-
else
113-
testCase.CodeFilePath)
114-
|> Seq.iter (fun (file, testCases) ->
115-
Console.WriteLine($"Discovered {Seq.length testCases} tests for: {file}")
116-
discoveredTests <- Map.add file testCases discoveredTests)
108+
testCase.CodeFilePath <- testCase.Source
109+
110+
discoveredTests.TryAdd(testCase.Id, testCase) |> ignore)
117111

118112
member _.HandleDiscoveryComplete(_, _) =
119113
use testsWriter = new StreamWriter(outputFile, append = false)
120114

121-
let testFiles = discoveredTests.Keys |> Seq.toArray |> String.concat ", "
115+
let testFiles =
116+
discoveredTests.Values
117+
|> Seq.map (fun test -> test.CodeFilePath)
118+
|> Seq.distinct
119+
|> String.concat ", "
122120

123121
Console.WriteLine($"Discovered tests for: {testFiles}")
124122

125-
for file, tests in discoveredTests |> Seq.map (|KeyValue|) do
126-
for test in tests do
127-
{ File = file
128-
Test =
129-
{ Id = test.Id
130-
CodeFilePath = test.CodeFilePath
131-
DisplayName = test.DisplayName
132-
LineNumber = test.LineNumber
133-
FullyQualifiedName = test.FullyQualifiedName } }
134-
|> JsonConvert.SerializeObject
135-
|> testsWriter.WriteLine
123+
discoveredTests.Values
124+
|> Seq.sortBy (fun testCase -> testCase.CodeFilePath, testCase.LineNumber)
125+
|> Seq.map (fun testCase ->
126+
{ File = testCase.CodeFilePath
127+
Test =
128+
{ Id = testCase.Id
129+
CodeFilePath = testCase.CodeFilePath
130+
DisplayName = testCase.DisplayName
131+
LineNumber = testCase.LineNumber
132+
FullyQualifiedName = testCase.FullyQualifiedName } })
133+
|> Seq.iter (JsonConvert.SerializeObject >> testsWriter.WriteLine)
136134

137135
use waitFileWriter = new StreamWriter(waitFile, append = false)
138136
waitFileWriter.WriteLine("1")
@@ -296,6 +294,7 @@ module TestDiscovery =
296294

297295
Console.WriteLine($"Discovering tests for: {sourcesStr}")
298296
r.DiscoverTests(args.Sources, sourceSettings, options, testSession, discoveryHandler)
297+
Console.WriteLine($"Discovering tests for: {sourcesStr}")
299298
with e ->
300299
Console.WriteLine($"failed to discovery tests for {sourcesStr}. Exception: {e}")
301300

@@ -323,7 +322,7 @@ module TestDiscovery =
323322
new PlaygroundTestRunHandler(args.StreamPath, args.OutputPath, args.ProcessOutput)
324323

325324
let debugLauncher = DebugLauncher(args.PidPath, args.AttachedPath)
326-
Console.WriteLine($"Starting {testCases.Length} tests in debug-mode")
325+
Console.WriteLine($"Starting {Seq.length testCases} tests in debug-mode")
327326

328327
do! Task.Yield()
329328
r.RunTestsWithCustomTestHost(testCases, sourceSettings, testHandler, debugLauncher)

0 commit comments

Comments
 (0)