From f6692acc20cd49f4444cc43cc39ba632dc1fadb5 Mon Sep 17 00:00:00 2001 From: Oleksandr Liemiahov Date: Fri, 27 Nov 2026 17:37:22 +0100 Subject: [PATCH] Write YAML configs before the test that needs them on a cold start AddNewItemYamlTest failed with an NPE at line 57 when it was the first test of a JVM with empty IDE caches, as on CI: the task config was missing. createConfigFiles schedules the writes with invokeLater, and UIUtil.dispatchAllInvocationEvents didn't run them there, even when called for 5 seconds; they ran only after the test. PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue releases the write-intent lock while it dispatches and waits for an invokeLater scheduled after them, so the configs are written before it returns. --- .../hyperskill/academy/coursecreator/yaml/YamlTestUtils.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/intellij-plugin/hs-core/testSrc/org/hyperskill/academy/coursecreator/yaml/YamlTestUtils.kt b/intellij-plugin/hs-core/testSrc/org/hyperskill/academy/coursecreator/yaml/YamlTestUtils.kt index a34055912..50c8db769 100644 --- a/intellij-plugin/hs-core/testSrc/org/hyperskill/academy/coursecreator/yaml/YamlTestUtils.kt +++ b/intellij-plugin/hs-core/testSrc/org/hyperskill/academy/coursecreator/yaml/YamlTestUtils.kt @@ -2,7 +2,7 @@ package org.hyperskill.academy.coursecreator.yaml import com.intellij.openapi.fileEditor.FileDocumentManager import com.intellij.openapi.project.Project -import com.intellij.util.ui.UIUtil +import com.intellij.testFramework.PlatformTestUtil import org.hyperskill.academy.learning.yaml.YamlFormatSettings import org.hyperskill.academy.learning.yaml.YamlFormatSynchronizer @@ -10,5 +10,8 @@ fun createConfigFiles(project: Project) { project.putUserData(YamlFormatSettings.YAML_TEST_PROJECT_READY, true) YamlFormatSynchronizer.saveAll(project) FileDocumentManager.getInstance().saveAllDocuments() - UIUtil.dispatchAllInvocationEvents() + // `saveAll` writes the files in `invokeLater`. `UIUtil.dispatchAllInvocationEvents` doesn't always run them: in the first + // test of a JVM with empty IDE caches, they ran only after the test. This one releases the write-intent lock while it + // dispatches events, and returns only after an `invokeLater` scheduled after them has run. + PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue() }