fflib-apex-common icon indicating copy to clipboard operation
fflib-apex-common copied to clipboard

Enhancement - enable @isTest(isParallel=true)

Open cropredyHelix opened this issue 8 years ago • 6 comments
trafficstars

With Winter 18 (V41.0), test annotation isParallel=true is introduced. This allows orgs where parallel testing is disabled - typically because of locking issues when creating setup records in testmethods - to have faster regression test runs since most fflib testmethods can safely run with isParallel=true

To date, I have found the following situations where isParallel=true is not supported:

  • testmethod does Test.getStandardPricebookId() (sad for Opportunity/Quote/Order apps)
  • testmethod does System.schedule(..), System.enqueueJob(..)
  • testmethod uses the StubAPI (sad for ApexMocks)
  • annotation is only available at the class level

So, add @isTest(isParallel=true) to as many fflib testclasses as possible (requires version upgrade to V41.0) and we'll have faster regression tests and deployments when the whole org tests are run.

cropredyHelix avatar Sep 21 '17 22:09 cropredyHelix

Thanks @cropredyHelix for submitting this idea. The benefits seem clear, but wow thats quite a list of restrictions, is that documented some place? The standout one for me is StubAPI. 👎

afawcett avatar Nov 26 '17 01:11 afawcett

I know of no doc on these restrictions; they were discovered trial-and-error (i.e. - I added the annotation and then saw my testmethods fail if they used any of the aforementioned techniques - at least the error message tells you why). Perhaps your juice at SFDC can resolve the StubAPI limitation :)

cropredy avatar Nov 26 '17 19:11 cropredy

I'll give it a try @cropredy, it smacks of something likely to be unknown to them tbh, so i partly imagine they will be as surprised as we are! 👍

afawcett avatar Nov 26 '17 19:11 afawcett

Oh btw, @cropredy your last post here says "at least the error message tells you why", can you share that please?

afawcett avatar Nov 26 '17 19:11 afawcett

@andyinthecloud --

Well, since I created this issue, the restriction on StubAPI seems to have been fixed as I can't reproduce

So, I tried the other use cases (V41):

  • Test.getStandardPriceBookId - still fails with System.TypeException: Test.getStandardPricebookId() cannot be called from parallel Apex tests
  • System.schedule - still fails with System.UnexpectedException: In parallel Apex tests, DML operations aren't permitted on this type of object: CronJobDetail

Plus new restrictions:

  • Inserting a ContentNote - System.DmlException: Insert failed. First exception on row 0; first error: APEX_DATA_ACCESS_RESTRICTION, In parallel Apex tests, DML operations aren't permitted on this type of object: ContentWorkspace: []

cropredyHelix avatar Nov 27 '17 17:11 cropredyHelix

Ok thanks for the update.

afawcett avatar Nov 27 '17 18:11 afawcett