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?
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+.