Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I'm facing a very annoying issue with the new Spring 13 release. Now all tests run asynchronously by default. Which would be fine except for the fact that a test locks all records it's using until it finishes (then it rolls back whatever changes it made) and that one of the records being locked is the standard pricebook record.

The standard pricebook record exists by default in the platform (you cannot create it and have to use the @isTest(SeeAllData=true) annotation to work with it in your tests), there's only one instance of it, and is used any time you want to create a product (and then add it to an opportunity or a quote).

Since the tests are running now asynchronously by default, all those that interact with the standard pricebook record fail because all of them are trying to put a lock on it (only the first one to get the lock succeeds).

I'm afraid of what it's going to happen when we deploy new changes to production. Are all tests going to run asynchronously? Since this mayor change has been done with the tests, is there now a way to go around the (very annoying) fact that you cannot insert a standard pricebook? (IsStandard field in Pricebook2 is not createable or updateable.)

Edit: I plan to validate the deployment, this at least should allow me see whether the tests are going to be run asynchronously by default when deploying.

share|improve this question
2  
According to the Spring '13 Release notes, page 109: Note that Apex tests that are run as part of a deployment, a package install, or a package upload, still run synchronously. You should be fine for your production deployments. –  Peter Knolle Jan 30 '13 at 22:53
1  
Thanks, Peter. I will still validate deployment (just in case), but that makes me feel a little better. (Still kind of annoyed with the standard pricebook, since it seems like I will never be able to take advantage of the async feature.) –  ceiroa Jan 30 '13 at 23:04
add comment

1 Answer

Your tests are being executed in Parallel which is causing these failures to occur as two or more tests try to create locks on the same objects. In your case the Pricebook.

This problem could be avoided if tests were written with SeeAllData=fase, as they would be isolated from each other but this isn't always possible and certainly not possible with Pricebooks as we can't create a standard pricebook.

So your only option is to disable Parallel Apex Testing

Running tests one at a time helps prevent test interference on shared data when tests run at the same time and access the same data. This only occurs when tests don’t create their own data and turn off data isolation to access the organization’s data.

To disable Parallel Apex Testing:

  1. Your Name > Setup > Develop > Apex Test Execution
  2. Click Options... button
  3. Check the Disable Parallel Apex Testing checkbox
  4. Click OK

http://login.salesforce.com/help/doc/en/code_test_execution.htm

share|improve this answer
    
Yep, this is what I'm doing. What I'm looking for is a way to run these tests in parallel, and still get them to pass. –  ceiroa Feb 11 '13 at 20:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.