Skip to content

Fix test file recreation threading issue in CheckAction #8

@meanmail

Description

@meanmail

Overview

Test file recreation (anti-cheating mechanism) blocks background threads unnecessarily during task checking, potentially causing performance issues.

Location

File: intellij-plugin/hs-core/src/org/hyperskill/academy/learning/actions/CheckAction.kt
Function: recreateTestFiles (lines 167-194)

Problem

Test file recreation is done synchronously during check with invokeAndWaitIfNeeded + runWriteAction. This blocks the background thread that's running the check operation.

override fun run(indicator: ProgressIndicator) {
    // Running on background thread
    recreateTestFiles(project, task) // But this blocks with invokeAndWaitIfNeeded
}

What needs to be fixed

  • The operation is already on a background thread (line 133 run(indicator: ProgressIndicator)) but uses invokeAndWaitIfNeeded which blocks unnecessarily
  • Consider using runWriteActionAndWait or restructuring to avoid blocking
  • Add proper error handling for individual file recreation failures (currently just logs warnings)
  • The same pattern exists in FrameworkLessonManagerImpl.recreateTestFiles (lines 219-245) - fix both locations consistently

Tests understanding of

  • Background task threading in IntelliJ Platform
  • When to use invokeAndWaitIfNeeded vs other patterns
  • Write action requirements and proper usage
  • Progress indicator usage
  • Command processor for undo/redo support
  • Anti-cheating mechanisms in educational plugins

Validation

  • Create a task with many test files
  • Run checker repeatedly and measure performance
  • Ensure smooth operation without blocking
  • Verify files are still recreated correctly

Estimated time

3-4 hours

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions