From 77e4dc986f3b19aa3f3c9ba0798d61afee291506 Mon Sep 17 00:00:00 2001 From: Sergey Simonchik Date: Fri, 27 Nov 2015 01:26:46 +0300 Subject: [PATCH] console: add testClearAndPrintWhileAnotherClearExecution to hunt down concurrent bug in ConsoleViewImpl --- .../execution/impl/ConsoleViewImpl.java | 2 +- .../execution/impl/ConsoleViewImplTest.java | 31 +++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java b/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java index 4c3181f92741..9ca7f59dfa44 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java +++ b/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java @@ -92,7 +92,7 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo @NonNls private static final String CONSOLE_VIEW_POPUP_MENU = "ConsoleView.PopupMenu"; private static final Logger LOG = Logger.getInstance("#com.intellij.execution.impl.ConsoleViewImpl"); - private static final int DEFAULT_FLUSH_DELAY = SystemProperties.getIntProperty("console.flush.delay.ms", 200); + static final int DEFAULT_FLUSH_DELAY = SystemProperties.getIntProperty("console.flush.delay.ms", 200); private static final CharMatcher NEW_LINE_MATCHER = CharMatcher.anyOf("\n\r"); diff --git a/platform/platform-tests/testSrc/com/intellij/execution/impl/ConsoleViewImplTest.java b/platform/platform-tests/testSrc/com/intellij/execution/impl/ConsoleViewImplTest.java index bfbce06ed7b8..7ccffa1af04d 100644 --- a/platform/platform-tests/testSrc/com/intellij/execution/impl/ConsoleViewImplTest.java +++ b/platform/platform-tests/testSrc/com/intellij/execution/impl/ConsoleViewImplTest.java @@ -28,7 +28,6 @@ import com.intellij.psi.search.GlobalSearchScope; import com.intellij.testFramework.LightPlatformTestCase; import com.intellij.testFramework.TestDataProvider; import com.intellij.util.Alarm; -import com.intellij.util.SystemProperties; import com.intellij.util.TimeoutUtil; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; @@ -78,12 +77,40 @@ public class ConsoleViewImplTest extends LightPlatformTestCase { }, 0); latch.await(); UIUtil.dispatchAllInvocationEvents(); - TimeoutUtil.sleep(SystemProperties.getIntProperty("console.flush.delay.ms", 200)); + TimeoutUtil.sleep(ConsoleViewImpl.DEFAULT_FLUSH_DELAY); UIUtil.dispatchAllInvocationEvents(); assertFalse(console.hasDeferredOutput()); assertEquals("Test", console.getText()); } + public void testClearAndPrintWhileAnotherClearExecution() throws Exception { + ConsoleViewImpl console = myConsole; + Alarm alarm = new Alarm(Alarm.ThreadToUse.SHARED_THREAD); + for (int i = 0; i < 100; i++) { + // To speed up test execution, set -Dconsole.flush.delay.ms=5 to reduce ConsoleViewImpl.DEFAULT_FLUSH_DELAY + System.out.println("Attempt #" + i); + console.clear(); // 1-st clear + CountDownLatch latch = new CountDownLatch(1); + alarm.addRequest(() -> { + console.clear(); // 2-nd clear + console.print("Test", ConsoleViewContentType.NORMAL_OUTPUT); + latch.countDown(); + }, 0); + UIUtil.dispatchAllInvocationEvents(); // flush 1-st clear request + latch.await(); + UIUtil.dispatchAllInvocationEvents(); // flush 2-nd clear request + TimeoutUtil.sleep(ConsoleViewImpl.DEFAULT_FLUSH_DELAY); + UIUtil.dispatchAllInvocationEvents(); // flush print request + // Need more investigation: sometimes console.hasDeferredOutput() is true + while (console.hasDeferredOutput()) { + TimeoutUtil.sleep(10); + UIUtil.dispatchAllInvocationEvents(); + } + //uncomment the next assertion to see probably failing test + //assertEquals("Test", console.getText()); + } + } + public void testTypeInEmptyConsole() throws Exception { ConsoleViewImpl console = myConsole; console.clear(); -- 2.23.3