From f0d707adef6bf5f1b2ec4e2cd6569fc77566b47e Mon Sep 17 00:00:00 2001 From: Danil Tereshchenko Date: Fri, 30 Jan 2026 14:29:10 +0000 Subject: [PATCH] BAZEL-2843 [bazel]: make unit tests runnable with Bazel This change addresses multiple interconnected test failures that occur when running Bazel plugin tests in the Bazel test environment. Problem: When JUnit 5 tests with @BazelTestApplication run alongside JUnit 4 BasePlatformTestCase tests in Bazel, cascading failures occur because: 1. JUnit 5 global store cleanup disposes the test application 2. This permanently shuts down AppScheduledExecutorService singleton 3. Subsequent JUnit 4 tests fail with "Already shutdown" errors Some tests are failing due to different isolation issues in Bazel sendbox. Changes: 1. Skip test application disposal under Bazel (TestApplicationExtension.kt) - The JVM terminates after tests complete anyway - cleanApplicationState() is still called after each test - Aligns with JUnit 4's TestApplicationManager behavior 2. Fix BazelGlobalFunctions test isolation (BazelGlobalFunctions.kt) - Change companion object properties from static initialization to dynamic getters - Prevents stale extension point data when tests mask the extension point 3. Add missing test dependencies (intellij.bazel.pluginTests.iml, BUILD.bazel) - Add platform dependencies (settings-local, backend-main) for service resolution - Add Kotlin plugin dependencies (plugin/common, plugin/k2) for stub indexing in completion tests - Configure test target with Kotlin's all_test_dep_targets data 4. Fix ProjectViewDirectoriesActionTest (ProjectViewDirectoriesActionTestCase.kt) - Replace android.databinding.tool.ext.mapEach with standard Kotlin - Fixes NoClassDefFoundError in Bazel environment 5. Fix KotlinModuleInternalManglingTest (MODULE.bazel, BazelRunner.kt) - Add hermetic_cc_toolchain - Update rules_kotlin to 2.2.2 - Add .bazeliskrc to set BAZELISK_HOME value Merge-request: IJ-MR-189586 Merged-by: Danil Tereshchenko GitOrigin-RevId: e5edb753314fcc87fa06227325985403ff5328a3 --- .../junit5/src/impl/TestApplicationExtension.kt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/platform/testFramework/junit5/src/impl/TestApplicationExtension.kt b/platform/testFramework/junit5/src/impl/TestApplicationExtension.kt index 742610d4d5f3..4f47015b603c 100644 --- a/platform/testFramework/junit5/src/impl/TestApplicationExtension.kt +++ b/platform/testFramework/junit5/src/impl/TestApplicationExtension.kt @@ -7,6 +7,7 @@ import com.intellij.ide.AppLifecycleListener import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.application.EDT import com.intellij.testFramework.common.* +import com.intellij.testFramework.common.BazelTestUtil import com.intellij.util.ui.EDT import kotlinx.coroutines.* import org.jetbrains.annotations.TestOnly @@ -45,6 +46,14 @@ private class TestApplicationResource(val initializationResult: Result) : return } + // In Bazel test environment, don't dispose the application. + // The JVM will terminate after all tests complete anyway, and + // disposing here would break JUnit 4 tests that run after JUnit 5 tests. + // See BAZEL-2843 for details. + if (BazelTestUtil.isUnderBazelTest) { + return + } + runBlocking { withTimeout(Duration.ofSeconds(20).toMillis()) { withContext(Dispatchers.EDT) {