From 15f0784b2db8457c493ee6ef3715f02489ea2309 Mon Sep 17 00:00:00 2001 From: Nadya Zabrodina Date: Tue, 4 Apr 2017 12:16:46 +0300 Subject: [PATCH] [lvcs]: flaky tests fixed * always consider test root creation as a LVCS event and always record it into the storage; * flaky reason: if somethings calls getChildren method for entire tmp test directory (async) a.e. PuppetProjectManager class, then entire test dir will be marked as All_CHILDERN_LOADED and all next child direcory creations will generate VFS events (after real file creation, during get VF for this file request); these events will be handled by subscribers (including lvcs handler); --- .../intellij/history/integration/BasicsTest.java | 12 ++++++------ .../history/integration/FileListeningTest.java | 8 ++++---- .../history/integration/IntegrationTestCase.java | 5 ++++- .../intellij/history/integration/PurgingTest.java | 8 +++++++- .../history/integration/RevisionsAndDiffsTest.java | 4 ++-- .../intellij/history/integration/VisitingTest.java | 14 +++++++------- .../DirectoryHistoryDialogPatchCreationTest.java | 3 +-- 7 files changed, 31 insertions(+), 23 deletions(-) diff --git a/platform/platform-tests/testSrc/com/intellij/history/integration/BasicsTest.java b/platform/platform-tests/testSrc/com/intellij/history/integration/BasicsTest.java index 820b09256a88..3168475375c4 100644 --- a/platform/platform-tests/testSrc/com/intellij/history/integration/BasicsTest.java +++ b/platform/platform-tests/testSrc/com/intellij/history/integration/BasicsTest.java @@ -57,7 +57,7 @@ public class BasicsTest extends IntegrationTestCase { LocalHistory.getInstance().putUserLabel(myProject, "global"); assertEquals(3, getRevisionsFor(f).size()); - assertEquals(3, getRevisionsFor(myRoot).size()); + assertEquals(4, getRevisionsFor(myRoot).size()); LocalHistory.getInstance().putUserLabel(myProject, "file"); @@ -73,7 +73,7 @@ public class BasicsTest extends IntegrationTestCase { VirtualFile f = createChildData(myRoot, "file.txt"); assertEquals(2, getRevisionsFor(f).size()); - assertEquals(2, getRevisionsFor(myRoot).size()); + assertEquals(3, getRevisionsFor(myRoot).size()); LocalHistory.getInstance().putSystemLabel(myProject, "label"); @@ -82,7 +82,7 @@ public class BasicsTest extends IntegrationTestCase { assertEquals("label", rr.get(1).getLabel()); rr = getRevisionsFor(myRoot); - assertEquals(3, rr.size()); + assertEquals(4, rr.size()); assertEquals("label", rr.get(1).getLabel()); } @@ -157,7 +157,7 @@ public class BasicsTest extends IntegrationTestCase { VirtualFile jarRoot = JarFileSystem.getInstance().getJarRootForLocalFile(vfile); assertEquals(1, jarRoot.findChild("file.txt").contentsToByteArray()[0]); - assertEquals(2, getRevisionsFor(myRoot).size()); + assertEquals(3, getRevisionsFor(myRoot).size()); ApplicationManager.getApplication().runWriteAction(new ThrowableComputable() { @Override @@ -181,7 +181,7 @@ public class BasicsTest extends IntegrationTestCase { jarRoot = JarFileSystem.getInstance().getJarRootForLocalFile(vfile); assertEquals(2, jarRoot.findChild("file.txt").contentsToByteArray()[0]); - assertEquals(2, getRevisionsFor(myRoot).size()); - assertEquals(1, getRevisionsFor(jarRoot).size()); + assertEquals(3, getRevisionsFor(myRoot).size()); + assertEquals(2, getRevisionsFor(jarRoot).size()); } } diff --git a/platform/platform-tests/testSrc/com/intellij/history/integration/FileListeningTest.java b/platform/platform-tests/testSrc/com/intellij/history/integration/FileListeningTest.java index 02bdb68606d2..5476e15e21d2 100644 --- a/platform/platform-tests/testSrc/com/intellij/history/integration/FileListeningTest.java +++ b/platform/platform-tests/testSrc/com/intellij/history/integration/FileListeningTest.java @@ -167,7 +167,7 @@ public class FileListeningTest extends IntegrationTestCase { rename(f, "file.txt"); assertEquals(before + 1, getRevisionsFor(myRoot).size()); - assertEquals(2, getRevisionsFor(f).size()); + assertEquals(3, getRevisionsFor(f).size()); } public void testRenamingNonFilteredFileToFiltered() throws Exception { @@ -189,7 +189,7 @@ public class FileListeningTest extends IntegrationTestCase { rename(f, "not_filtered"); assertEquals(before + 1, getRevisionsFor(myRoot).size()); - assertEquals(2, getRevisionsFor(f).size()); + assertEquals(3, getRevisionsFor(f).size()); } public void testRenamingNonFilteredDirectoriesToFiltered() throws Exception { @@ -294,7 +294,7 @@ public class FileListeningTest extends IntegrationTestCase { LocalFileSystem.getInstance().refresh(false); List revs = getRevisionsFor(myRoot); - assertEquals(4, revs.size()); + assertEquals(5, revs.size()); assertNotNull(revs.get(0).findEntry().findEntry("dir/subDir/file.txt")); assertNull(revs.get(1).findEntry().findEntry("dir/subDir/file.txt")); assertNotNull(revs.get(2).findEntry().findEntry("dir/subDir/file.txt")); @@ -317,7 +317,7 @@ public class FileListeningTest extends IntegrationTestCase { LocalFileSystem.getInstance().refresh(false); List revs = getRevisionsFor(myRoot); - assertEquals(4, revs.size()); + assertEquals(5, revs.size()); assertNotNull(revs.get(0).findEntry().findEntry("dir/subDir/file.txt")); assertNull(revs.get(1).findEntry().findEntry("dir/subDir")); assertNotNull(revs.get(2).findEntry().findEntry("dir/subDir/file.txt")); diff --git a/platform/platform-tests/testSrc/com/intellij/history/integration/IntegrationTestCase.java b/platform/platform-tests/testSrc/com/intellij/history/integration/IntegrationTestCase.java index c79d0f4bc60a..58c624882d12 100644 --- a/platform/platform-tests/testSrc/com/intellij/history/integration/IntegrationTestCase.java +++ b/platform/platform-tests/testSrc/com/intellij/history/integration/IntegrationTestCase.java @@ -37,6 +37,7 @@ import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.*; import com.intellij.testFramework.PlatformTestCase; import com.intellij.testFramework.PsiTestUtil; +import com.intellij.util.ObjectUtils; import org.jetbrains.annotations.NotNull; import java.io.File; @@ -80,7 +81,9 @@ public abstract class IntegrationTestCase extends PlatformTestCase { } protected void setUpInWriteAction() throws Exception { - myRoot = LocalFileSystem.getInstance().findFileByIoFile(createTempDirectory()); + VirtualFile tmpTestDir = + ObjectUtils.assertNotNull(LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(FileUtil.getTempDirectory()))); + myRoot = tmpTestDir.createChildDirectory(null, "idea_test_integration"); PsiTestUtil.addContentRoot(myModule, myRoot); } diff --git a/platform/platform-tests/testSrc/com/intellij/history/integration/PurgingTest.java b/platform/platform-tests/testSrc/com/intellij/history/integration/PurgingTest.java index 8366ac0b6d37..9496fae06e0e 100644 --- a/platform/platform-tests/testSrc/com/intellij/history/integration/PurgingTest.java +++ b/platform/platform-tests/testSrc/com/intellij/history/integration/PurgingTest.java @@ -33,6 +33,12 @@ public class PurgingTest extends IntegrationTestCase { getVcs().getChangeListInTests().setIntervalBetweenActivities(2); } + @Override + protected void setUpInWriteAction() throws Exception { + Clock.setTime(0); + super.setUpInWriteAction(); + } + @Test public void testPurgeWithoutGapsBetweenChanges() { createChangesWithTimestamps(1, 2, 3); @@ -51,7 +57,7 @@ public class PurgingTest extends IntegrationTestCase { public void testPurgeNothing() { createChangesWithTimestamps(1, 2, 3); getVcs().getChangeListInTests().purgeObsolete(10); - assertRemainedChangesTimestamps(3, 2, 1); + assertRemainedChangesTimestamps(3, 2, 1, 0); } @Test diff --git a/platform/platform-tests/testSrc/com/intellij/history/integration/RevisionsAndDiffsTest.java b/platform/platform-tests/testSrc/com/intellij/history/integration/RevisionsAndDiffsTest.java index 158b45ea4b5d..61b599784a7f 100644 --- a/platform/platform-tests/testSrc/com/intellij/history/integration/RevisionsAndDiffsTest.java +++ b/platform/platform-tests/testSrc/com/intellij/history/integration/RevisionsAndDiffsTest.java @@ -363,13 +363,13 @@ public class RevisionsAndDiffsTest extends IntegrationTestCase { createFile("bar.txt"); LocalHistory.getInstance().putSystemLabel(myProject, "2", -1); - assertEquals(5, getRevisionsFor(myRoot).size()); + assertEquals(6, getRevisionsFor(myRoot).size()); assertEquals(3, getRevisionsFor(myRoot, "*.txt").size()); } public void testFilteredRevisionsIfNothingFound() throws Exception { createFile("foo.txt"); - assertEquals(2, getRevisionsFor(myRoot).size()); + assertEquals(3, getRevisionsFor(myRoot).size()); assertEquals(1, getRevisionsFor(myRoot, "xxx").size()); } diff --git a/platform/platform-tests/testSrc/com/intellij/history/integration/VisitingTest.java b/platform/platform-tests/testSrc/com/intellij/history/integration/VisitingTest.java index 97d17f3e4ef0..7d11ad65a007 100644 --- a/platform/platform-tests/testSrc/com/intellij/history/integration/VisitingTest.java +++ b/platform/platform-tests/testSrc/com/intellij/history/integration/VisitingTest.java @@ -30,7 +30,7 @@ public class VisitingTest extends IntegrationTestCase { public void testSimpleVisit() throws Exception { createFile("f.txt"); createFile("dir"); - assertVisitorLog("begin create end begin create end finished "); + assertVisitorLog("begin create end begin create end begin create end finished "); } @Test @@ -40,7 +40,7 @@ public class VisitingTest extends IntegrationTestCase { createFile("dir"); getVcs().endChangeSet(null); - assertVisitorLog("begin create create end finished "); + assertVisitorLog("begin create create end begin create end finished "); } @Test @@ -49,7 +49,7 @@ public class VisitingTest extends IntegrationTestCase { createFile("f.txt"); createFile("dir"); - assertVisitorLog("begin create create end finished "); + assertVisitorLog("begin create create end begin create end finished "); } @Test @@ -61,7 +61,7 @@ public class VisitingTest extends IntegrationTestCase { getVcs().beginChangeSet(); rename(dir, "newDir"); - assertVisitorLog("begin rename end begin create end begin create end finished "); + assertVisitorLog("begin rename end begin create end begin create end begin create end finished "); } @Test @@ -104,8 +104,8 @@ public class VisitingTest extends IntegrationTestCase { } }; - assertVisitorLog("begin create create end finished ", visitor); - assertEquals(2, count[0]); + assertVisitorLog("begin create create end begin create end finished ", visitor); + assertEquals(3, count[0]); } @Test @@ -122,7 +122,7 @@ public class VisitingTest extends IntegrationTestCase { TestVisitor visitor = new TestVisitor(); getVcs().accept(visitor); - assertEquals("begin create end begin create end finished ", visitor.log); + assertEquals("begin create end begin create end begin create end finished ", visitor.log); visitor = new TestVisitor() { @Override diff --git a/platform/platform-tests/testSrc/com/intellij/history/integration/ui/DirectoryHistoryDialogPatchCreationTest.java b/platform/platform-tests/testSrc/com/intellij/history/integration/ui/DirectoryHistoryDialogPatchCreationTest.java index bb31fd193cd3..442beaf48444 100644 --- a/platform/platform-tests/testSrc/com/intellij/history/integration/ui/DirectoryHistoryDialogPatchCreationTest.java +++ b/platform/platform-tests/testSrc/com/intellij/history/integration/ui/DirectoryHistoryDialogPatchCreationTest.java @@ -29,8 +29,7 @@ public class DirectoryHistoryDialogPatchCreationTest extends PatchingTestCase { createChildDataWithContent(myRoot, "f1.txt"); createChildDataWithContent(myRoot, "f2.txt"); createChildDataWithContent(myRoot, "f3.txt"); - - assertSize(6, m.getRevisions()); + assertSize(7, m.getRevisions()); m.selectRevisions(0, 5); m.createPatch(patchFilePath, myProject.getBasePath(), false, Charset.defaultCharset());