test `BlockingProgressIndicator#startBlocking` continues pumping the event queue...
authorDaniil Ovchinnikov <daniil.ovchinnikov@jetbrains.com>
Tue, 4 Oct 2022 16:26:25 +0000 (18:26 +0200)
committerintellij-monorepo-bot <intellij-monorepo-bot-no-reply@jetbrains.com>
Thu, 6 Oct 2022 11:30:34 +0000 (11:30 +0000)
Original commit: 830341cc684bb4d4b883ed88435f8b85da2f7aca

GitOrigin-RevId: 9308c6e08c11c48c908b479db1ab29061cf085a3

platform/platform-tests/testSrc/com/intellij/openapi/progress/impl/ProgressRunnerTest.java
platform/platform-tests/testSrc/com/intellij/openapi/progress/util/ProgressWindowTest.kt

index b76b2143854066b90c0839635611cc9ab44cafaa..8609dcfc3749acb599a4c77c933cf94b4c8bedf6 100644 (file)
@@ -1,17 +1,16 @@
 // Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
 package com.intellij.openapi.progress.impl;
 
+import com.intellij.ide.IdeEventQueue;
 import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.application.ModalityState;
 import com.intellij.openapi.application.ex.ApplicationManagerEx;
 import com.intellij.openapi.application.impl.ApplicationImpl;
 import com.intellij.openapi.application.impl.LaterInvocator;
 import com.intellij.openapi.diagnostic.DefaultLogger;
-import com.intellij.openapi.progress.EmptyProgressIndicator;
-import com.intellij.openapi.progress.ProcessCanceledException;
-import com.intellij.openapi.progress.ProgressIndicator;
-import com.intellij.openapi.progress.ProgressManager;
+import com.intellij.openapi.progress.*;
 import com.intellij.openapi.progress.util.ProgressWindow;
+import com.intellij.openapi.progress.util.ProgressWindowTest.TestProgressWindow;
 import com.intellij.openapi.util.EmptyRunnable;
 import com.intellij.testFramework.LightPlatformTestCase;
 import com.intellij.testFramework.PlatformTestUtil;
@@ -23,11 +22,14 @@ import com.intellij.util.concurrency.Semaphore;
 import com.intellij.util.ui.EDT;
 import com.intellij.util.ui.UIUtil;
 import org.jetbrains.annotations.NotNull;
+import org.junit.Assert;
 import org.junit.Assume;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
 
+import java.awt.*;
+import java.awt.event.KeyEvent;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.CompletableFuture;
@@ -263,6 +265,33 @@ public class ProgressRunnerTest extends LightPlatformTestCase {
     task.assertNotFinished();
   }
 
+  @Test
+  public void testToPooledThreadWithProgressWindowWithCanceledInvokeAndWait() throws Throwable {
+    Assume.assumeTrue(myOnEdt);
+
+    var result = new ProgressRunner<>(() -> {
+      var progressWindow = (TestProgressWindow)ProgressIndicatorProvider.getGlobalProgressIndicator();
+      var cancelled = new Semaphore(1);
+      EventQueue.invokeLater(() -> {
+        var modalComponent = progressWindow.getDialog$intellij_platform_tests().getPanel();
+        var escapeEvent = new KeyEvent(modalComponent, KeyEvent.KEY_PRESSED, System.nanoTime(), 0, KeyEvent.VK_ESCAPE, '\e');
+        IdeEventQueue.getInstance().postEvent(escapeEvent);
+        EventQueue.invokeLater(() -> cancelled.up());
+      });
+      Assert.assertTrue(cancelled.waitFor(1000));
+    })
+      .onThread(ProgressRunner.ThreadToUse.POOLED)
+      .withProgress(new TestProgressWindow(getProject()))
+      .modal()
+      .sync()
+      .submitAndGet();
+    var throwable = result.getThrowable();
+    if (throwable != null) {
+      throw throwable;
+    }
+    assertTrue(result.isCanceled());
+  }
+
   @Test
   public void testAsyncModalPooledExecution() throws Exception {
     TestTask task = new TestTask()
index aade4e49adabbbd309fcdbf9028965a37173dce8..2f9107105d96bbed753ea199c95e45db94c77117 100644 (file)
@@ -32,7 +32,7 @@ class ProgressWindowTest : ProgressWindowTestCase<ProgressWindowTest.TestProgres
   }
 
   class TestProgressWindow internal constructor(project: Project) : ProgressWindow(true, project) {
-    internal val dialog: Any?
+    internal val dialog: ProgressDialog?
       get() = super.getDialog()
 
     public override fun showDialog(): Unit = super.showDialog()