Skip to content

Make the frame activation metrics test independent of test order - #85

Open
Tsyklop wants to merge 1 commit into
mainfrom
bug/metrics-test-app-icon-order
Open

Tsyklop wants to merge 1 commit into
mainfrom
bug/metrics-test-app-icon-order

Conversation

@Tsyklop

@Tsyklop Tsyklop commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

HyperskillMetricsTest > test time spent events with frame activation fails on Windows when an earlier test in the same JVM has called AppIcon.getInstance():

java.lang.ClassCastException: class org.hyperskill.academy.learning.stepik.hyperskill.metrics.HyperskillMetricsTest$MockIdeFrame cannot be cast to class com.intellij.openapi.wm.impl.ProjectFrameHelper
	at com.intellij.ui.AppIcon$BaseIcon$1.applicationActivated(AppIcon.java:204)

The local IDE update cycle hit it on 262 with IU-2026.2.5.1 (#84). CI runs on Linux and never sees it.

Cause

The test published a fake IdeFrame on ApplicationActivationListener.TOPIC. That topic is application-wide, so every platform listener on it got the fake frame too.

On a non-headless Windows JVM with JNA loaded, AppIcon.getInstance() creates Win7AppIcon. Its BaseIcon subscribes a listener on that topic, and the listener casts the activated frame to ProjectFrameHelper. The icon is created once per JVM, by its first caller, e.g. the open-in-IDE focus in restServiceUtils.kt or ProjectUtil.focusProjectWindow. So the test failed only when such a test ran earlier in the same JVM, and only on Windows: on Linux AppIcon is EmptyIcon, which subscribes nothing. The class passes when it runs alone. AppIcon is the same in IU-2026.2.1 and IU-2026.2.5.1, so this isn't new in the platform update.

Fix

  • The test calls HyperskillMetricsApplicationActivationListener directly with the fake frame, so nothing else receives it. The assertions are unchanged: the time spent on the task grows after the IDE is activated again.
  • Before, the round trip through the bus also covered the listener's registration in Hyperskill.xml. A new test, test frame activation listener is registered, checks that in the plugin descriptor instead and publishes nothing. IdeaPluginDescriptorImpl.appContainerDescriptor is already used by EduTestServiceStateHelper; ContainerDescriptor.listeners and ListenerDescriptor.listenerClassName / topicClassName are the same public fields on 252, 253, 261, 262 and 263 (checked with javap).
  • analyze_build.py of the update-loop skill no longer classifies this failure as the windows-app-icon-order flake. If the cast comes back, the loop reports it as a new failure.

Testing

Locally on Windows, environmentName=262 (IU-2026.2.1):

  • Repro: a temporary copy of the old test body, and a call to AppIcon.getInstance() at the start of it and of the new test. The JVM got AppIcon$Win7AppIcon. The old body failed with the ClassCastException above; the new test and the registration check passed in the same JVM. The temporary code isn't in this PR.
  • HyperskillMetricsTest alone: 22 tests, no failures.
  • Full :intellij-plugin:test: 783 tests in 116 classes, no failures. HyperskillMetricsTest ran 86th. This run doesn't show whether an earlier test had created the icon; the repro above covers that order.

The frame activation test published a fake IdeFrame on the application-wide
ApplicationActivationListener topic, so platform listeners got it too. On a
non-headless Windows JVM, AppIcon.getInstance() creates Win7AppIcon, which
subscribes a listener there that casts the frame to ProjectFrameHelper. Once an
earlier test in the JVM had created the icon, the test failed with a
ClassCastException.

The test now calls HyperskillMetricsApplicationActivationListener directly, and
a separate test checks in the plugin descriptor that the listener is registered
on the topic. The update loop no longer classifies the failure as a flake.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant