@@ -87,19 +87,23 @@ type TestMNISTOperations () =
8787 System.GC.Collect()
8888 System.GC.WaitForPendingFinalizers()
8989 System.GC.Collect()
90- System.Threading.Thread.Sleep( 100 ) // Small delay to allow file handles to be released
91- // Retry deletion up to 3 times
90+ System.Threading.Thread.Sleep( 250 ) // Longer delay to allow file handles to be released
91+ // Retry deletion up to 5 times with progressive backoff
9292 let mutable attempts = 0
9393 let mutable deleted = false
94- while attempts < 3 && not deleted do
94+ while attempts < 5 && not deleted do
9595 try
96+ // Additional GC before each attempt
97+ System.GC.Collect()
9698 Directory.Delete( mnistDir, true )
9799 deleted <- true
98100 with
99- | :? System.IO.IOException ->
101+ | :? System.IO.IOException when attempts < 4 ->
100102 attempts <- attempts + 1
101- System.Threading.Thread.Sleep( 100 )
102- | _ -> deleted <- true
103+ let sleepTime = 300 * ( attempts * attempts) // Progressive: 300, 1200, 2700, 4800ms
104+ System.Threading.Thread.Sleep( sleepTime)
105+ | _ ->
106+ attempts <- 5 // Stop trying on other errors
103107 with
104108 | _ -> () // Ignore cleanup errors
105109
@@ -151,19 +155,23 @@ type TestMNISTOperations () =
151155 System.GC.Collect()
152156 System.GC.WaitForPendingFinalizers()
153157 System.GC.Collect()
154- System.Threading.Thread.Sleep( 100 ) // Small delay to allow file handles to be released
155- // Retry deletion up to 3 times
158+ System.Threading.Thread.Sleep( 250 ) // Longer delay to allow file handles to be released
159+ // Retry deletion up to 5 times with progressive backoff
156160 let mutable attempts = 0
157161 let mutable deleted = false
158- while attempts < 3 && not deleted do
162+ while attempts < 5 && not deleted do
159163 try
164+ // Additional GC before each attempt
165+ System.GC.Collect()
160166 Directory.Delete( mnistDir, true )
161167 deleted <- true
162168 with
163- | :? System.IO.IOException ->
169+ | :? System.IO.IOException when attempts < 4 ->
164170 attempts <- attempts + 1
165- System.Threading.Thread.Sleep( 100 )
166- | _ -> deleted <- true
171+ let sleepTime = 300 * ( attempts * attempts) // Progressive: 300, 1200, 2700, 4800ms
172+ System.Threading.Thread.Sleep( sleepTime)
173+ | _ ->
174+ attempts <- 5 // Stop trying on other errors
167175 with
168176 | _ -> () // Ignore cleanup errors
169177
@@ -212,19 +220,23 @@ type TestMNISTOperations () =
212220 System.GC.Collect()
213221 System.GC.WaitForPendingFinalizers()
214222 System.GC.Collect()
215- System.Threading.Thread.Sleep( 100 ) // Small delay to allow file handles to be released
216- // Retry deletion up to 3 times
223+ System.Threading.Thread.Sleep( 250 ) // Longer delay to allow file handles to be released
224+ // Retry deletion up to 5 times with progressive backoff
217225 let mutable attempts = 0
218226 let mutable deleted = false
219- while attempts < 3 && not deleted do
227+ while attempts < 5 && not deleted do
220228 try
229+ // Additional GC before each attempt
230+ System.GC.Collect()
221231 Directory.Delete( mnistDir, true )
222232 deleted <- true
223233 with
224- | :? System.IO.IOException ->
234+ | :? System.IO.IOException when attempts < 4 ->
225235 attempts <- attempts + 1
226- System.Threading.Thread.Sleep( 100 )
227- | _ -> deleted <- true
236+ let sleepTime = 300 * ( attempts * attempts) // Progressive: 300, 1200, 2700, 4800ms
237+ System.Threading.Thread.Sleep( sleepTime)
238+ | _ ->
239+ attempts <- 5 // Stop trying on other errors
228240 with
229241 | _ -> () // Ignore cleanup errors
230242
@@ -268,27 +280,34 @@ type TestMNISTOperations () =
268280 System.GC.Collect()
269281 System.GC.WaitForPendingFinalizers()
270282 System.GC.Collect()
271- System.Threading.Thread.Sleep( 100 ) // Small delay to allow file handles to be released
272- // Retry deletion up to 3 times
283+ System.Threading.Thread.Sleep( 250 ) // Longer delay to allow file handles to be released
284+ // Retry deletion up to 5 times with progressive backoff
273285 let mutable attempts = 0
274286 let mutable deleted = false
275- while attempts < 3 && not deleted do
287+ while attempts < 5 && not deleted do
276288 try
289+ // Additional GC before each attempt
290+ System.GC.Collect()
277291 Directory.Delete( mnistDir, true )
278292 deleted <- true
279293 with
280- | :? System.IO.IOException ->
294+ | :? System.IO.IOException when attempts < 4 ->
281295 attempts <- attempts + 1
282- System.Threading.Thread.Sleep( 100 )
283- | _ -> deleted <- true
296+ let sleepTime = 300 * ( attempts * attempts) // Progressive: 300, 1200, 2700, 4800ms
297+ System.Threading.Thread.Sleep( sleepTime)
298+ | _ ->
299+ attempts <- 5 // Stop trying on other errors
284300 with
285301 | _ -> () // Ignore cleanup errors
286302
287303 [<Test>]
288304 member _.TestMNISTErrorHandling () =
289305 // Test error handling for invalid files
290306 let tempDir = Path.GetTempPath()
291- let uniqueId = System.Guid.NewGuid() .ToString( " N" ) + " -" + System.Environment.TickCount.ToString()
307+ let processId = System.Diagnostics.Process.GetCurrentProcess() .Id.ToString()
308+ let threadId = System.Threading.Thread.CurrentThread.ManagedThreadId.ToString()
309+ let ticks = System.DateTime.UtcNow.Ticks.ToString()
310+ let uniqueId = System.Guid.NewGuid() .ToString( " N" ) + " -" + processId + " -" + threadId + " -" + ticks
292311 let mnistDir = Path.Combine( tempDir, $" test-mnist-errors-{uniqueId}" )
293312 Directory.CreateDirectory( mnistDir) |> ignore
294313 let fullMnistDir = Path.Combine( mnistDir, " mnist" )
@@ -315,19 +334,23 @@ type TestMNISTOperations () =
315334 System.GC.Collect()
316335 System.GC.WaitForPendingFinalizers()
317336 System.GC.Collect()
318- System.Threading.Thread.Sleep( 100 ) // Small delay to allow file handles to be released
319- // Retry deletion up to 3 times
337+ System.Threading.Thread.Sleep( 250 ) // Longer delay to allow file handles to be released
338+ // Retry deletion up to 5 times with progressive backoff
320339 let mutable attempts = 0
321340 let mutable deleted = false
322- while attempts < 3 && not deleted do
341+ while attempts < 5 && not deleted do
323342 try
343+ // Additional GC before each attempt
344+ System.GC.Collect()
324345 Directory.Delete( mnistDir, true )
325346 deleted <- true
326347 with
327- | :? System.IO.IOException ->
348+ | :? System.IO.IOException when attempts < 4 ->
328349 attempts <- attempts + 1
329- System.Threading.Thread.Sleep( 100 )
330- | _ -> deleted <- true
350+ let sleepTime = 300 * ( attempts * attempts) // Progressive: 300, 1200, 2700, 4800ms
351+ System.Threading.Thread.Sleep( sleepTime)
352+ | _ ->
353+ attempts <- 5 // Stop trying on other errors
331354 with
332355 | _ -> () // Ignore cleanup errors
333356
@@ -371,19 +394,23 @@ type TestMNISTOperations () =
371394 System.GC.Collect()
372395 System.GC.WaitForPendingFinalizers()
373396 System.GC.Collect()
374- System.Threading.Thread.Sleep( 100 ) // Small delay to allow file handles to be released
375- // Retry deletion up to 3 times
397+ System.Threading.Thread.Sleep( 250 ) // Longer delay to allow file handles to be released
398+ // Retry deletion up to 5 times with progressive backoff
376399 let mutable attempts = 0
377400 let mutable deleted = false
378- while attempts < 3 && not deleted do
401+ while attempts < 5 && not deleted do
379402 try
403+ // Additional GC before each attempt
404+ System.GC.Collect()
380405 Directory.Delete( mnistDir, true )
381406 deleted <- true
382407 with
383- | :? System.IO.IOException ->
408+ | :? System.IO.IOException when attempts < 4 ->
384409 attempts <- attempts + 1
385- System.Threading.Thread.Sleep( 100 )
386- | _ -> deleted <- true
410+ let sleepTime = 300 * ( attempts * attempts) // Progressive: 300, 1200, 2700, 4800ms
411+ System.Threading.Thread.Sleep( sleepTime)
412+ | _ ->
413+ attempts <- 5 // Stop trying on other errors
387414 with
388415 | _ -> () // Ignore cleanup errors
389416
@@ -422,27 +449,34 @@ type TestMNISTOperations () =
422449 System.GC.Collect()
423450 System.GC.WaitForPendingFinalizers()
424451 System.GC.Collect()
425- System.Threading.Thread.Sleep( 100 ) // Small delay to allow file handles to be released
426- // Retry deletion up to 3 times
452+ System.Threading.Thread.Sleep( 250 ) // Longer delay to allow file handles to be released
453+ // Retry deletion up to 5 times with progressive backoff
427454 let mutable attempts = 0
428455 let mutable deleted = false
429- while attempts < 3 && not deleted do
456+ while attempts < 5 && not deleted do
430457 try
458+ // Additional GC before each attempt
459+ System.GC.Collect()
431460 Directory.Delete( mnistDir, true )
432461 deleted <- true
433462 with
434- | :? System.IO.IOException ->
463+ | :? System.IO.IOException when attempts < 4 ->
435464 attempts <- attempts + 1
436- System.Threading.Thread.Sleep( 100 )
437- | _ -> deleted <- true
465+ let sleepTime = 300 * ( attempts * attempts) // Progressive: 300, 1200, 2700, 4800ms
466+ System.Threading.Thread.Sleep( sleepTime)
467+ | _ ->
468+ attempts <- 5 // Stop trying on other errors
438469 with
439470 | _ -> () // Ignore cleanup errors
440471
441472 [<Test>]
442473 member _.TestMNISTDataNormalization () =
443474 // Test that MNIST data is properly normalized from byte values to [0,1]
444475 let tempDir = Path.GetTempPath()
445- let uniqueId = System.Guid.NewGuid() .ToString( " N" ) + " -" + System.Environment.TickCount.ToString()
476+ let processId = System.Diagnostics.Process.GetCurrentProcess() .Id.ToString()
477+ let threadId = System.Threading.Thread.CurrentThread.ManagedThreadId.ToString()
478+ let ticks = System.DateTime.UtcNow.Ticks.ToString()
479+ let uniqueId = System.Guid.NewGuid() .ToString( " N" ) + " -" + processId + " -" + threadId + " -" + ticks
446480 let mnistDir = Path.Combine( tempDir, $" test-mnist-norm-{uniqueId}" )
447481 Directory.CreateDirectory( mnistDir) |> ignore
448482 let fullMnistDir = Path.Combine( mnistDir, " mnist" )
@@ -495,18 +529,22 @@ type TestMNISTOperations () =
495529 System.GC.Collect()
496530 System.GC.WaitForPendingFinalizers()
497531 System.GC.Collect()
498- System.Threading.Thread.Sleep( 100 ) // Small delay to allow file handles to be released
499- // Retry deletion up to 3 times
532+ System.Threading.Thread.Sleep( 250 ) // Longer delay to allow file handles to be released
533+ // Retry deletion up to 5 times with progressive backoff
500534 let mutable attempts = 0
501535 let mutable deleted = false
502- while attempts < 3 && not deleted do
536+ while attempts < 5 && not deleted do
503537 try
538+ // Additional GC before each attempt
539+ System.GC.Collect()
504540 Directory.Delete( mnistDir, true )
505541 deleted <- true
506542 with
507- | :? System.IO.IOException ->
543+ | :? System.IO.IOException when attempts < 4 ->
508544 attempts <- attempts + 1
509- System.Threading.Thread.Sleep( 100 )
510- | _ -> deleted <- true
545+ let sleepTime = 300 * ( attempts * attempts) // Progressive: 300, 1200, 2700, 4800ms
546+ System.Threading.Thread.Sleep( sleepTime)
547+ | _ ->
548+ attempts <- 5 // Stop trying on other errors
511549 with
512550 | _ -> () // Ignore cleanup errors
0 commit comments