Reputation: 3890
I have a tests written in c#
, I am using SpecRun
version 1.5.2.
Part of my Default.srprofile
looks as follows:
<Execution stopAfterFailures="20" testThreadCount="5" testSchedulingMode="Sequential" retryFor="Failing" retryCount="3" />
There is a bunch of tests that are using some data from the db, so the tests are creating that data first. Unfortunately when 5 threads are running parallel, I am occasionally getting a sql deadlock error
which is fine, as those threads try to write data in same time.
Is there any chance to add a delay of thread execution? Something to say than threads should start within 5s seconds interval or something similar?
Upvotes: 0
Views: 832
Reputation: 21
In addition to previous answer, if you go with catching deadlocks and retries, I'd also add some random time interval between attempts so that you don't get the same deadlock on each retry iteration. We do that for API/DB concurrent requests and it works fine for us, since multiple databases/environments would require more resources and money to be involved.
Upvotes: 1
Reputation: 5835
There is no option for a delayed start and I wouldn't go with this idea. It is only a quick fix. You will get this error again when later test are executed simultaneous.
2 options to fix your problem come to my mind:
Catch the Deadlock exception and try to add your data again.
Use different databases for every thread. You can use a ConfigTransformation Deployment step to change your connection string to access a separate database for every thread. Docu is here: http://specflow.org/plus/documentation/SpecFlowPlus-Runner-Profiles/#DeploymentTransformation There are placeholders for different values: http://specflow.org/plus/documentation/SpecFlowPlus-Runner-Profiles/#Placeholders
Full Disclosure: I am one of the developers of SpecFlow and SpecFlow+.
Upvotes: 2