From f9ba5539a6837db5c447e326644c63e040f6084f Mon Sep 17 00:00:00 2001 From: "Maxim.Mossienko" Date: Tue, 6 Dec 2016 12:44:51 +0100 Subject: [PATCH] fix test: avoid possible interference with background indexing thread by running the code in write action --- .../openapi/vfs/local/PersistentFsTest.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/PersistentFsTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/PersistentFsTest.java index c44e33d4ce4d..118729f989bd 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/PersistentFsTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/PersistentFsTest.java @@ -197,17 +197,20 @@ public class PersistentFsTest extends PlatformTestCase { ++globalModCount; ++inSessionModCount; - final long timestamp = vFile.getTimeStamp(); + int finalGlobalModCount = globalModCount; + int finalInSessionModCount = inSessionModCount; WriteAction.run(() -> { + final long timestamp = vFile.getTimeStamp(); vFile.setWritable(true); // 1 change vFile.setBinaryContent("foo".getBytes(Charset.defaultCharset())); // content change + length change + maybe timestamp change - }); - final int changesCount = timestamp == vFile.getTimeStamp() ? 3 : 4; - assertEquals(globalModCount + changesCount, managingFS.getModificationCount(vFile)); - assertEquals(globalModCount + changesCount, managingFS.getFilesystemModificationCount()); - assertEquals(inSessionModCount + changesCount, managingFS.getModificationCount()); - assertEquals(parentModCount, managingFS.getModificationCount(vFile.getParent())); + // we check in write action to avoid observing background thread to index stuff + final int changesCount = timestamp == vFile.getTimeStamp() ? 3 : 4; + assertEquals(finalGlobalModCount + changesCount, managingFS.getModificationCount(vFile)); + assertEquals(finalGlobalModCount + changesCount, managingFS.getFilesystemModificationCount()); + assertEquals(finalInSessionModCount + changesCount, managingFS.getModificationCount()); + assertEquals(parentModCount, managingFS.getModificationCount(vFile.getParent())); + }); } @NotNull