Running unit tests from UI hangs - tests never start

Issue #1922 resolved
Scott Ruch created an issue

I’m trying to run tests individually and they just hang, the Run window shows “Instantiating tests…” but nothing happens afterwards. There’s no indication in the org that anything is running. I tried waiting it out, restarting IntelliJ, rebooting, to no avail. Running from the command line (sfdx) works fine. Other operations are working (push/pull, etc.) from the UI, but I can’t run tests.

Comments (16)

  1. Scott Wells repo owner

    Scott, let's get some diagnostic info. First, please enable debug logging for unit testing and reproduce the issue, then either attach or email the resulting idea.log file. It sounds like the IDE itself isn't locked up, so hopefully that should be sufficient. But if the IDE itself becomes completely unresponsive, I'll probably also have you send over thread dumps.

  2. Scott Ruch reporter

    Here’s the relevant log file section. I noticed that it’s trying to use an old, expired scratch org to run the tests. I’ve long since deleted that one and the correct one is “altria-scratch4”. I just checked and the project settings show altria-scratch4 is associated with the project.

    2021-06-24 15:23:21,534 [12074078] DEBUG - .ApexUnitTestRunProcessHandler - Running tests for [ altriadx: { VendorsTest } ].
    2021-06-24 15:23:21,551 [12074095] DEBUG - .ApexUnitTestRunProcessHandler - Starting test run.
    2021-06-24 15:23:21,552 [12074096] INFO - luminatedCloudConnectionConfig - Retrieving org list from Salesforce CLI.
    2021-06-24 15:23:21,595 [12074139] INFO - luminatedCloudConnectionConfig - Retrieving org list information from Salesforce CLI.
    2021-06-24 15:23:21,600 [12074144] DEBUG - .VariableLengthPollingInterval - /usr/local/bin/sfdx force:org:list --skipconnectionstatus --json: Using polling interval 1000 ms for polling iteration 1.
    2021-06-24 15:23:22,605 [12075149] DEBUG - .VariableLengthPollingInterval - /usr/local/bin/sfdx force:org:list --skipconnectionstatus --json: Using polling interval 1000 ms for polling iteration 2.
    2021-06-24 15:23:23,608 [12076152] DEBUG - .VariableLengthPollingInterval - /usr/local/bin/sfdx force:org:list --skipconnectionstatus --json: Using polling interval 1000 ms for polling iteration 3.
    2021-06-24 15:23:24,656 [12077200] ERROR - plication.impl.ApplicationImpl - No Salesforce connection found for project altriadx with name altria-scratch and type SFDX.
    java.lang.IllegalStateException: No Salesforce connection found for project altriadx with name altria-scratch and type SFDX.
    at com.illuminatedcloud.intellij.runconfig.AbstractApexProcessHandler.getConnectionConfig(SourceFile:91)
    at com.illuminatedcloud.intellij.unittest.ApexUnitTestRunProcessHandler.lambda$startProcessing$7(SourceFile:366)
    at com.intellij.util.RunnableCallable.call(RunnableCallable.java:20)
    at com.intellij.util.RunnableCallable.call(RunnableCallable.java:11)
    at com.intellij.openapi.application.impl.ApplicationImpl$1.call(ApplicationImpl.java:265)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:668)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:665)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:665)
    at java.base/java.lang.Thread.run(Thread.java:829)
    2021-06-24 15:23:24,656 [12077200] ERROR - plication.impl.ApplicationImpl - IntelliJ IDEA 2021.1.2 Build #IU-211.7442.40
    2021-06-24 15:23:24,656 [12077200] ERROR - plication.impl.ApplicationImpl - JDK: 11.0.11; VM: Dynamic Code Evolution 64-Bit Server VM; Vendor: JetBrains s.r.o.
    2021-06-24 15:23:24,656 [12077200] ERROR - plication.impl.ApplicationImpl - OS: Mac OS X
    2021-06-24 15:23:24,657 [12077201] ERROR - plication.impl.ApplicationImpl - Plugin to blame: Illuminated Cloud 2 version: 2.1.8.1
    2021-06-24 15:23:24,657 [12077201] ERROR - plication.impl.ApplicationImpl - Last Action: Run

  3. Scott Wells repo owner

    Also, can you please provide the output of sfdx force:org:list so I can see whether perhaps there's something there that's stale?

  4. Scott Ruch reporter

    \$ sfdx force:org:list --all
    WARNING: Starting in API version 52, the JSON output of this command no longer returns the property connectedStatus for scratch orgs.
    === Orgs
    ALIAS USERNAME ORG ID CONNECTED STATUS
    ─── ────────────────────── ───────────────────────────────────────────── ────────────────── ─────────────────────
    Connexo admin@twdsum20-con.org 00D4x00000262NwEAI Connected
    FME admin@twdwin21-fme.org 00D5Y000001bSYuUAM Connected
    Mannkind twdadmin123@mannkindcorp.com.dev 00De0000005XGhZEAW Connected
    ProductionTarget scott.ruch@twd_hub.com 00D40000000MxA3EAK Connected
    Viralgen-prod apages@viralgenvc.com 00D09000000H8gCEAS Connected
    Viralgen-val apages@viralgenvc.com.val 00D1x0000008fElEAI Connected
    altria-dev sparta.admin01@altria.com.dev 00D8A000000JrvmUAC Connected
    altria-ootb sparta.admin01@altria.com.ootb 00D55000000Kt7iEAC Connected
    (D) altria-prod sparta.admin01@altria.com 00D5Y0000024chJUAQ Connected
    altria-test sparta.admin01@altria.com.test 00D7h000000Gyl2EAC Connected
    bene-dev twdadminsparta@bene.com.dev 00D1X0000000MdvUAE Connected
    bene-uat twdadminsparta@bene.com.uat 00D0E000000ApUmUAK Connected
    dna-dev brian.hilliard@spartasystems.com.adna.sandbox 00DP00000040ZfpMAE Connected
    mckesson-dev sparta.twdadmin@mckesson.com.dev 00Dc0000003lTovEAE RefreshTokenAuthError
    mckesson-test sparta.twdadmin@mckesson.com.twd.test 00D2f0000008ba3EAA RefreshTokenAuthError
    midas-prod sparta@midas.com 00D3X000001tAXPUA2 Connected
    midas-staging-internal sparta@midas.com.staging 00D7a00000052WUEAY Connected
    midas-val sparta@midas.com.dev 00D1x0000008f53EAA Connected
    nephron-dev admin@nephronpharm.dev 00D0t000000HLavEAG Connected
    nephron-prod admin@nephronpharm.prod 00D4W00000913ekUAA Connected
    nephron-val admin@nephronpharm.val 00D050000008lISEAY Connected

     ALIAS            USERNAME                       ORG ID              STATUS   EXPIRATION DATE
    

    ─── ─────────────── ───────────────────────────── ────────────────── ─────── ───────────────
    test-bzbrvvpsymdj@example.com 00D630000001YdgEAE Deleted 2019-05-30
    test-cnghtgkkdbi5@example.com 00D0v0000005BEqEAM Deleted 2019-06-30
    test-iks5sdmg9zsc@example.com 00D540000009LNzEAM Deleted 2018-08-01
    test-pkvc8hjoryuy@example.com 00D1100000Bw3zFEAR Deleted 2019-04-25
    test-saslthoynifz@example.com 00D2D000000Cn79UAC Deleted 2019-04-25
    123PlatformDX test-fxcutvfks8gi@example.com 00D1F000000GrPgUAK Deleted 2020-03-01
    EQMSDX test-rppzycyny46m@example.com 00D1D000000DM5rUAG Deleted 2019-06-30
    (U) altria-scratch4 test-glja7lnatroi@example.com 00D0x000000Hv6SEAS Active 2021-07-18
    soDEX601 test-ekynzcjbgnsi@example.com 00D2D000000CoEuUAK

  5. Scott Wells repo owner

    Oh, I see the problem. Your unit test run configuration has cached the old connection information. You can use Run>Edit Configurations and then under Apex Unit Tests find the unit test run configuration that you're launching and change the connection in the drop-down. I'll investigate why that wasn't updated when you changed the active connection for the project because it should have been. Let me know if that doesn't resolve the issue for you, though.

  6. Scott Ruch reporter

    In case this helps with debugging: The one that wasn’t launching didn’t have the old org name associated with it, it had the new (correct) one, but when I looked at some of the other tests and came back to the one that was failing, it was still showing the new org name, but it was in a red font and the username wasn’t there. I selected the org from the drop down and it reset it and then I was able to run the test.

  7. Scott Wells repo owner

    Gotcha. I'll see if I can reproduce the behavior, but minimally I'll do a last mile validation of the unit test run configuration's connection to make sure it's valid and, if not, prompt the user to correct it to use a different connection (likely the project's connection if there's only one).

  8. Scott Wells repo owner

    Scott, I've tried to reproduce this behavior a few different ways, but so far each time when I select a new connection, IC2 is properly updating all unit test run configurations for the project that used the old connection to use the new one. Do you happen to know a sequence of steps you might have taken to get into this state?

  9. Scott Ruch reporter

    If I can recall, I created the new scratch org from IC and associated it with the project. The prior scratch org had already expired, so I cleaned it out of my org list with “sfdx force:org:list --clean” prior to creating the new one. I had a bunch of old scratches in there and wanted to get rid of them. Maybe deleting it outside of the IDE caused it to get out of sync? Once I associated the new one with the project, I didn’t change anything in the unit test run configurations. I hit the error the first time I tried to run a test that was already in the list of tests. Hopefully I got the sequence of things right, I think that may be material to the problem.

  10. Scott Wells repo owner

    Ah, okay. That may be the case. IC2 caches the connection info pretty aggressively because calling the CLI to enumerate connections can be expensive. It's possible that it had a cached version of the alias against the original scratch org's username. I'll investigate that. Note that you can have IC2 run sfdx force:org:list --clean for you by clicking the trashcan toolbar icon in the connection manager, and it will immediately update its cache afterward. But if it's getting into a bad state when that's run externally, it's worth investigating. Thanks!

  11. Scott Ruch reporter

    Thanks for the tip, I bounce back and forth between the CLI and IC, so I might be shooting myself in the foot.

  12. Scott Wells repo owner

    Issue tracker grooming. If this is still an issue, please feel free to reopen, ideally with a concrete reproduction scenario.

  13. Log in to comment