console: fix blank console bug caused by invoking "clear(); print();" while previous...
authorSergey Simonchik <sergey.simonchik@jetbrains.com>
Fri, 27 Nov 2015 11:53:32 +0000 (14:53 +0300)
committerSergey Simonchik <sergey.simonchik@jetbrains.com>
Fri, 27 Nov 2015 11:53:32 +0000 (14:53 +0300)
platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java
platform/lang-impl/src/com/intellij/unscramble/AnalyzeStacktraceUtil.java
platform/platform-tests/testSrc/com/intellij/execution/impl/ConsoleViewImplTest.java

index 9ca7f59dfa44fba2a93927e1895c2c31fd060f1b..c2cfb318ce81c5af8ac6d4bcacdd6402e1caa7f5 100644 (file)
@@ -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");
 
-  static final int DEFAULT_FLUSH_DELAY = SystemProperties.getIntProperty("console.flush.delay.ms", 200);
+  private static final int DEFAULT_FLUSH_DELAY = SystemProperties.getIntProperty("console.flush.delay.ms", 200);
 
   private static final CharMatcher NEW_LINE_MATCHER = CharMatcher.anyOf("\n\r");
 
@@ -715,6 +715,7 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo
           }
         }, null, DocCommandGroupId.noneGroupId(document));
       }
+      return;
     }
 
 
index 820c9a75a6d3952e22d944c172de456cb26eac97..72011c729963faa1cd0707a8a4468744d1c1ce52 100644 (file)
@@ -60,30 +60,14 @@ public class AnalyzeStacktraceUtil {
   private AnalyzeStacktraceUtil() {
   }
 
-  public static void printStacktrace(@NotNull final ConsoleView consoleView, @NotNull String unscrambledTrace) {
+  public static void printStacktrace(@NotNull ConsoleView consoleView, @NotNull String unscrambledTrace) {
     ApplicationManager.getApplication().assertIsDispatchThread();
-    final String text = unscrambledTrace + "\n";
-    final String consoleText = ((ConsoleViewImpl)consoleView).getText();
+    String text = unscrambledTrace + "\n";
+    String consoleText = ((ConsoleViewImpl)consoleView).getText();
     if (!text.equals(consoleText)) {
       consoleView.clear();
-      // make sure other "clear" requests stuck in EDT are performed before our print next stacktrace
-      ApplicationManager.getApplication().invokeLater(new Runnable() {
-        @Override
-        public void run() {
-          try {
-            consoleView.print(text, ConsoleViewContentType.ERROR_OUTPUT);
-            consoleView.scrollTo(0);
-          }
-          catch (Exception e) {
-            throw new RuntimeException(e);
-          }
-        }
-      }, new Condition() {
-        @Override
-        public boolean value(Object o) {
-          return !((ConsoleViewImpl)consoleView).isVisible();
-        }
-      });
+      consoleView.print(text, ConsoleViewContentType.ERROR_OUTPUT);
+      consoleView.scrollTo(0);
     }
   }
 
index 7ccffa1af04dff8bdb2f5dd68cce86cecdf25621..0fa5f5fb7e4ac768f060ec0931b46bff9ad32f0c 100644 (file)
@@ -76,10 +76,10 @@ public class ConsoleViewImplTest extends LightPlatformTestCase {
       latch.countDown();
     }, 0);
     latch.await();
-    UIUtil.dispatchAllInvocationEvents();
-    TimeoutUtil.sleep(ConsoleViewImpl.DEFAULT_FLUSH_DELAY);
-    UIUtil.dispatchAllInvocationEvents();
-    assertFalse(console.hasDeferredOutput());
+    while (console.hasDeferredOutput()) {
+      UIUtil.dispatchAllInvocationEvents();
+      TimeoutUtil.sleep(5);
+    }
     assertEquals("Test", console.getText());
   }
 
@@ -99,15 +99,11 @@ public class ConsoleViewImplTest extends LightPlatformTestCase {
       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();
+        TimeoutUtil.sleep(5);
       }
-      //uncomment the next assertion to see probably failing test
-      //assertEquals("Test", console.getText());
+      assertEquals("Test", console.getText());
     }
   }