File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -35,19 +35,22 @@ module internal Utils =
3535 if Directory.Exists tempPath then ()
3636 else Directory.CreateDirectory tempPath |> ignore
3737
38- /// Returns the filename part of a temp file name created with Path.GetTempFileName().
38+ /// Returns the filename part of a temp file name created with Path.GetTempFileName()
39+ /// and an added process id and thread id to ensure uniqueness between threads.
3940 let getTempFileName () =
4041 let tempFileName = Path.GetTempFileName()
4142 try
42- let tempFileName = Path.GetFileName( tempFileName)
43- tempFileName
43+ let tempFile , tempExt = Path.GetFileNameWithoutExtension tempFileName, Path.GetExtension tempFileName
44+ let procId , threadId = System.Diagnostics.Process.GetCurrentProcess() .Id, System.Threading.Thread.CurrentThread.ManagedThreadId
45+ String.concat " " [ tempFile; " _" ; string procId; " _" ; string threadId; tempExt] // ext includes dot
4446 finally
4547 try
46- // since Path.GetTempFileName() creates a *.tmp file in the %TEMP% folder, we want to clean it up
48+ // Since Path.GetTempFileName() creates a *.tmp file in the %TEMP% folder, we want to clean it up.
49+ // This also prevents a system to run out of available randomized temp files (the pool is only 64k large).
4750 File.Delete tempFileName
4851 with _ -> ()
4952
50- /// Clean up after a test is run. If you need to inspect the create * .fs files, change this function to do nothing.
53+ /// Clean up after a test is run. If you need to inspect the create * .fs files, change this function to do nothing, or just break here .
5154 let cleanupTempFiles files =
5255 for fileName in files do
5356 try
You can’t perform that action at this time.
0 commit comments