6

To work around another problem (EAI_AGAIN errors when pushing or running unit tests in a newly created scratch org from Jenkins CI using SFDX), I'd like to (gently) poll for the test results produced by sfdx force:apex:test:run to see if that helps. But the following command does not appear to be designed for that purpose.

The closest I can get is:

sfdx force:apex:test:report --testrunid 707K000001JUhgY --json --wait 2

but the result of that isn't JSON but rather the message:

Socket timeout occurred while listening for results.

and the exit status is 1, just as it is for other error conditions.

Is there an alternate, clean way, to poll say once every 30 seconds?

(Unanswered here Waiting for Test Report from Salesforce DX CLI.)

2
  • What about running an sfdx force:data:soql:query -t against ApexTestRunResult and doing a sleep between invocations?
    – David Reed
    Commented Feb 8, 2019 at 16:32
  • @DavidReed Yes. Will give it a go (and expect it to work so if you post it as an answer +1 from me).
    – Keith C
    Commented Feb 8, 2019 at 16:39

1 Answer 1

3

Here's my suggestion:

sfdx force:data:soql:query can run a Tooling API query with -t. Run something like

sfdx force:data:soql:query -t -q "SELECT Status FROM ApexTestRunResult WHERE Id = '$TEST_RUN_ID'" --json

Check the Status value, and sleep 30s if it's not 'Completed', iterating until that Status is reached.

5
  • Thanks David - works well! Note no rows returned until finished.
    – Keith C
    Commented Feb 8, 2019 at 18:27
  • Interesting. Based on the available Status values and the use of an AsyncApexJob Id I was expecting it to return while processing. Glad the strategy worked nonetheless.
    – David Reed
    Commented Feb 8, 2019 at 18:30
  • I didn't look this carefully enough; the query needs to be e.g. sfdx force:data:soql:query -t -q "SELECT Status FROM ApexTestRunResult where AsyncApexJobId = '707K000001JVY3v'" and that does return a row with a status of "Processing" then "Completed". That is TEST_RUN_ID is the AsyncApexJobId.
    – Keith C
    Commented Feb 9, 2019 at 13:01
  • Thanks for running with it, @KeithC; apologies for not checking the exact semantics first!
    – David Reed
    Commented Feb 11, 2019 at 2:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .