From 9506b1d7ad9d27eb29d6ba194c50359c774db4f7 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Thu, 25 May 2017 10:39:55 +0300 Subject: [PATCH] [tests] unwanted event filtering for file watcher tests --- .../openapi/vfs/impl/local/FileWatcher.java | 36 +++++++++---------- .../openapi/vfs/local/FileWatcherTest.kt | 13 ++++--- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/FileWatcher.java b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/FileWatcher.java index da2537bab6c0..05d2cef811b7 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/FileWatcher.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/FileWatcher.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -183,7 +183,7 @@ public class FileWatcher { @Override public void notifyManualWatchRoots(@NotNull Collection roots) { myManualWatchRoots.add(roots.isEmpty() ? Collections.emptySet() : ContainerUtil.newHashSet(roots)); - notifyOnAnyEvent(); + notifyOnEvent(OTHER); } @Override @@ -191,7 +191,7 @@ public class FileWatcher { if (!mapping.isEmpty()) { myPathMap.addMapping(mapping); } - notifyOnAnyEvent(); + notifyOnEvent(OTHER); } @Override @@ -204,7 +204,7 @@ public class FileWatcher { } } } - notifyOnAnyEvent(); + notifyOnEvent(path); } @Override @@ -221,7 +221,7 @@ public class FileWatcher { } } } - notifyOnAnyEvent(); + notifyOnEvent(path); } @Override @@ -232,7 +232,7 @@ public class FileWatcher { myDirtyPaths.dirtyDirectories.addAll(paths); } } - notifyOnAnyEvent(); + notifyOnEvent(path); } @Override @@ -245,7 +245,7 @@ public class FileWatcher { } } } - notifyOnAnyEvent(); + notifyOnEvent(path); } @Override @@ -263,7 +263,7 @@ public class FileWatcher { } } } - notifyOnReset(); + notifyOnEvent(RESET); } @Override @@ -272,22 +272,19 @@ public class FileWatcher { } } - /* test data and methods */ + // + public static final String RESET = "(reset)"; + public static final String OTHER = "(other)"; - private volatile Consumer myTestNotifier = null; + private volatile Consumer myTestNotifier = null; - private void notifyOnAnyEvent() { - Consumer notifier = myTestNotifier; - if (notifier != null) notifier.accept(Boolean.FALSE); - } - - private void notifyOnReset() { - Consumer notifier = myTestNotifier; - if (notifier != null) notifier.accept(Boolean.TRUE); + private void notifyOnEvent(String path) { + Consumer notifier = myTestNotifier; + if (notifier != null) notifier.accept(path); } @TestOnly - public void startup(@Nullable Consumer notifier) throws IOException { + public void startup(@Nullable Consumer notifier) throws IOException { myTestNotifier = notifier; for (PluggableFileWatcher watcher : myWatchers) { watcher.startup(); @@ -301,4 +298,5 @@ public class FileWatcher { } myTestNotifier = null; } + // } \ No newline at end of file diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/FileWatcherTest.kt b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/FileWatcherTest.kt index b49d38c781db..4b352318ad46 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/FileWatcherTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/FileWatcherTest.kt @@ -70,6 +70,7 @@ class FileWatcherTest : BareTestFixtureTestCase() { private lateinit var watcher: FileWatcher private lateinit var alarm: Alarm + private val watchedPaths = mutableListOf() private val watcherEvents = Semaphore() private val resetHappened = AtomicBoolean() @@ -85,10 +86,13 @@ class FileWatcherTest : BareTestFixtureTestCase() { watcher = (fs as LocalFileSystemImpl).fileWatcher assertFalse(watcher.isOperational) - watcher.startup { reset -> - alarm.cancelAllRequests() - alarm.addRequest({ watcherEvents.up() }, INTER_RESPONSE_DELAY) - if (reset) resetHappened.set(true) + watchedPaths += tempDir.root.path + watcher.startup { path -> + if (path == FileWatcher.RESET || path == FileWatcher.OTHER || watchedPaths.any { path.startsWith(it) }) { + alarm.cancelAllRequests() + alarm.addRequest({ watcherEvents.up() }, INTER_RESPONSE_DELAY) + if (path == FileWatcher.RESET) resetHappened.set(true) + } } wait { !watcher.isOperational } @@ -322,6 +326,7 @@ class FileWatcherTest : BareTestFixtureTestCase() { val substRoot = IoTestUtil.createSubst(target.path) VfsRootAccess.allowRootAccess(testRootDisposable, substRoot.path) val vfsRoot = fs.findFileByIoFile(substRoot)!! + watchedPaths += substRoot.path val substFile = File(substRoot, "sub/test.txt") refresh(target)