Sep 6, 2013 at 9:36 AM
Edited Sep 6, 2013 at 9:37 AM
Hello all, I'm having problems with the reliability of our spec (integration) tests. At the core lies a problem with resetting the DB file to an initial state (from right after executing setup).
What we're doing: at the beginning of a test run we run setup on a clean Orchard installation and afterwards save a copy of the DB, which then at the beginning of some of our tests we restore to its original location. The problem is that we're getting anywhere
from 1 to several tens of exceptions of this type:
[TestRunnerThread] Orchard.Environment.DefaultOrchardHost - A tenant could not be started: Default
System.Data.SqlServerCe.SqlCeException (0x80004005): The database file may be corrupted. Run the repair utility to check the database file. [Database name = C:\TeamCity\buildAgent\temp\buildTmp\DZ.Specs\deterministicInstance\App_Data\Sites\Default\Orchard.sdf]
at Orchard.Environment.ShellBuilders.ShellContextFactory.CreateShellContext(ShellSettings settings)
The problem seems to lie in replacing the DB file. We've already tried a few things to avoid this problem:
- add a Thread.Sleep(1000) after putting the clean DB in place - this helped a few tests
- copy the DB file before initializing the remote AppDomain instance hosting the application that will use that DB
- after setup (and thus creation of the initial DB file), shut down the AppDomain hosting the application before backing up the DB file
We've been down to a single instance of the exception during a whole test run, but it's simply put not predictable.
Could anybody advise on how to avoid corruption of the DB in this kind of setup?