ApexTestResult Record not created when a testcase fails with RunningForTooLongException
Last updated 4 days ago ·Reference W-7834236 ·Reported By 112 users
When executing Apex tests in parallel mode, unit tests sometimes deadlock and fail in multiple ways. Some tests fail with a fairly well-known "unable to obtain exclusive access to this record" message while interacting with normal sObjects ; others fail with a "connection was cancelled here" message , and do so without generating the proper Tooling API result records
This issue manifests typically when significant volume of Apex test runs in parallel mode
1.Create an org. Scratch org or developer edition should work fine. Ensure that parallel Apex testing is turned on.
2.Execute a unit test run. Any Tooling API `runAsynchronous` call should work the same provided it enqueues all of the Apex unit tests in the product in one run; doing a Run All in the Developer Console works fine for reproduction purposes.
3. Wait for the bulk of the unit test run to complete. You may see the test run spin forever, depending on the specific testing tool you utilize. The Apex Test Execution section of Setup will show the real situation with class-level failures.
Some Apex unit tests fail with messages that include the phrase "unable to obtain exclusive access to this record", related to ordinary sObject records that are being inserted by this test. These failures show up consistently across test UIs, as expected; they should have valid ApexTestQueueItem and ApexTestResult records found via the Tooling API.
Some Apex unit tests fail in a way that only shows in specific test UIs. The ApexTestQueueItem records for their parent classes will show Status = Failed and ExtendedStatus = "Could not run tests on class <01p class id> because: connection was cancelled here".
For these tests in, ApexTestResult records will usually not be created, although some may exist. It's these tests that show as in progress forever in tools like Salesforce DX and the Developer Console, which are looking for ApexTestResult records. One consequence is that many testing tools will report a different number of unit tests completed from run to run, due to monitoring ApexTestResult records
Reported By (112)
Is it Fixed?
Any unreleased services, features, statuses, or dates referenced in this or other public statements are not currently available and may not be delivered on time or at all. Customers who purchase our services should make their purchase decisions based upon features that are currently available.