Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Recomendations for working with local db/sqlserver
PEtter
#1 Posted : Monday, November 27, 2017 11:07:07 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 10/29/2012(UTC)
Posts: 4
Location: Norway

Thanks: 1 times
What is "best practice" for working with local db while using nCrunch..
This might be a more generic topic though..

I want to keep the data for my database inside the test project to ensure that I know the data.. I do not want a shared db solution

Any comment/ideas?
Remco
#2 Posted : Monday, November 27, 2017 11:15:32 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 5,008

Thanks: 667 times
Was thanked: 790 time(s) in 752 post(s)
The best approach I've found here is by using transactions to isolate activities in the database, making sure you roll back a transaction at the end of your test run, and never commit.

In this way, your database is always left in a known state. Some ORMs use a pattern of storing the transaction or connection object in a ThreadStatic field or a named slot on the thread, so it's possible to tie the transaction to the thread. You could also do this yourself if your are calling your way into the database manually (i.e. DSQL/custom DAL).

Issues start to arise with this approach when you have multiple tests running in parallel, each one manipulating interdependent areas of the database. This can cause deadlocks, so the tests can hang. If you mark all tests that write data to the database using ExclusivelyUses("Database"), and all tests that only read data from the database as InclusivelyUses("Database") you can significantly increase the number of tests that can run in parallel.

Another option is to have a seperate database for each processing thread (or rather, execution process). This has its own advantages by removing the parallelisation constraints but the infrastructure for setting up the databases can then add to the length of the test run.
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.022 seconds.