From 3114afde0ea4acfa8de907b4d5dc8f027a7fec3e Mon Sep 17 00:00:00 2001 From: Matt Kotsenas Date: Tue, 10 Jul 2018 11:49:38 -0700 Subject: [PATCH] Add workaround for in-use files The `TestBase` is not always able to delete the scratch folder in `Dispose()` because sometimes the files are still in use. This problem appears to be leaked file handles (likely due to incorrect handling of `IDisposable`). To avoid the problem for now, force a garbage collection prior to deleting the scratch folder. --- tests/SharpCompress.Test/TestBase.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/SharpCompress.Test/TestBase.cs b/tests/SharpCompress.Test/TestBase.cs index 8248e3f3..f9438673 100644 --- a/tests/SharpCompress.Test/TestBase.cs +++ b/tests/SharpCompress.Test/TestBase.cs @@ -39,6 +39,12 @@ namespace SharpCompress.Test public void Dispose() { + // WARNING: This garbage collection is needed to reclaim leaked file handles + // (likely due to improperly handled IDisposables). Without it, The following + // delete fails because files are still is use. This GC should be removed once + // all the files pass without it. + GC.Collect(2, GCCollectionMode.Forced, true, false); + Directory.Delete(SCRATCH_BASE_PATH, true); }