In my automated tests (MSTest in a new project using Visual Studio 2017), I'm deploying a fresh database before each test case runs like so (databaseName
is random and unique, and cleaned up after each test run finishes):
[TestInitialize]
public void ConfigureEmptyDatabase()
{
var instance = new DacServices(connectionString);
using (var dacpac = DacPackage.Load(path)) {
instance.Deploy(dacpac, databaseName, upgradeExisting: true,
options: new DacDeployOptions{ CreateNewDatabase = true });
}
}
Seemingly at random, the instance.Deploy(...)
line will stall indefinitely. I implemented a timeout of 60 seconds so my tests fail in this case. When my tests succeed, they generally take 20-40 seconds.
What could be causing this delay? I'm deploying to localhost, so it shouldn't be any network latency, and I'm checking my available memory and CPU in Task Manager as the test runs, and those don't get maxed out. A restart of the machine, or just SQL Server on the machine, doesn't seem to make a difference.
So far, the one thing that seems to increase the odds of it not timing out is debugging the test case instead of running it outside the debugger. I'll update if I still get a timeout in the debugger.
Am I unwittingly triggering some sort of race condition, or deadlock?