console: add testClearAndPrintWhileAnotherClearExecution to hunt down concurrent... appcode/144.1523 clion/144.1519 dbe/144.1514 idea/144.1517 phpstorm/144.1516 pycharm/144.1522 rubymine/144.1521 webstorm/144.1525
authorSergey Simonchik <sergey.simonchik@jetbrains.com>
Thu, 26 Nov 2015 22:26:46 +0000 (01:26 +0300)
committerSergey Simonchik <sergey.simonchik@jetbrains.com>
Thu, 26 Nov 2015 22:26:46 +0000 (01:26 +0300)
platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java
platform/platform-tests/testSrc/com/intellij/execution/impl/ConsoleViewImplTest.java

index 4c3181f92741917bcadee160aefe8cfa63e28c41..9ca7f59dfa44fba2a93927e1895c2c31fd060f1b 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");
 
-  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");
 
index bfbce06ed7b8e4dadbd1de03fc1849537302e962..7ccffa1af04dff8bdb2f5dd68cce86cecdf25621 100644 (file)
@@ -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();