forcedotcom / cli

Salesforce CLI
https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/
BSD 3-Clause "New" or "Revised" License
494 stars 78 forks source link

Unexpected behavior in sf run apex test #3019

Closed Cerelius closed 1 month ago

Cerelius commented 2 months ago

Hello, I use a custom GitHub action to execute apex tests in my CI/CD pipeline that wraps the sf/cli and I've just made an update that uncovered some unexpected behavior for me and I wanted to ask if it's intended or not. And, potentially improve my understanding or put eyes on it.

In most asynchronous commands on the sf-cli I'm expecting to enqueue the operation through the command and then be able to reach out to check on the status using the job-id. For example, with a package install request the install is queued and then I am provided an id to let me check the status of the job. It will tell if it's in progress, completed, failed, etc. Providing a wait param will instead poll and wait for me until the job is complete or the wait times out.

I've had to update my action because we found that the --wait parameter on this command does not throw a failure when the waiting period times out. It provides an exit 0 and no indication that it timed out so it provides a false positive when using only the wait parameter.

Okay, to account for that we can just run without a wait and call out to get the current status of the test run. We've done that previously when creating a 2GP package version through a local polling system until the status is complete. However, I found that the sf apex get test command will sit and wait until the tests results are back to return a result. I've only been able to get it to return a complete pass or fail, never an in progress status. I've tried to catch an in-progress status with several different size packages and it's waited until the test completes every time. Curiously, this approach also looks to be significantly faster than running sf apex run test with a wait included.

Running the same set of tests using a test-suite, we received test results in 5-8 minutes using sf apex run test with no wait and immediately requesting sf apex get test. Compared to 18-35 minutes when running sf apex run tests with a sufficient wait time.

There's no blocker present here but the behavior is surprising and appears to contrast other behavior within the CLI in my experience.

Is this intentional? Is this performance difference real or am I missing something here?

github-actions[bot] commented 2 months ago

Hello @Cerelius :wave: It looks like you didn't include the full Salesforce CLI version information in your issue. Please provide the output of version --verbose --json for the CLI you're using (sf or sfdx).

A few more things to check:

Thank you!

github-actions[bot] commented 2 months ago

Thank you for filing this issue. We appreciate your feedback and will review the issue as soon as possible. Remember, however, that GitHub isn't a mechanism for receiving support under any agreement or SLA. If you require immediate assistance, contact Salesforce Customer Support.

Cerelius commented 2 months ago

I've personally observed the described behavior from @salesforce/cli/2.48.6 darwin-arm64 node-v20.15.0 up to latest.

iowillhoit commented 2 months ago

Hey @Cerelius 👋 Lot to unpack here. Going to do my best to summarize it.

We will need more details on that one and ideally a repository that allows us to easily reproduce the issue. This might be best to create a new Issue if you are able to get us those details.

Thanks!

github-actions[bot] commented 1 month ago

This issue has not received a response in 7 days. It will auto-close in 7 days unless a response is posted.