From 21b35259332877ef60730971a8d1a28b99e63475 Mon Sep 17 00:00:00 2001 From: Victor Hurdugaci Date: Tue, 5 Jul 2016 09:57:11 -0700 Subject: [PATCH] Make MultipleTriggers more stable --- .../FileWatcherTests.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/test/Microsoft.DotNet.Watcher.Tools.FunctionalTests/FileWatcherTests.cs b/test/Microsoft.DotNet.Watcher.Tools.FunctionalTests/FileWatcherTests.cs index dc696e6c93..e9be4869a1 100644 --- a/test/Microsoft.DotNet.Watcher.Tools.FunctionalTests/FileWatcherTests.cs +++ b/test/Microsoft.DotNet.Watcher.Tools.FunctionalTests/FileWatcherTests.cs @@ -288,7 +288,21 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests handler = (_, f) => { filesChanged.Add(f); - changedEv.Set(); + try + { + changedEv.Set(); + } + catch(ObjectDisposedException) + { + // There's a known race condition here: + // even though we tell the watcher to stop raising events and we unsubscribe the handler + // there might be in-flight events that will still process. Since we dispose the reset + // event, this code will fail if the handler executes after Dispose happens. There's no + // better way to guard against it than catch because we cannot check if the object is + // disposed nor can we check if there are any in-flight events. + // This is actually a known issue in the corefx file watcher. It can trigger multiple + // times for the same item. + } }; watcher.OnFileChange += handler;