Fix NewSchemaPerFixture

I don't know if this is a hacky fix, someone might have to take a look at it
This commit is contained in:
Mole
2020-10-02 14:16:36 +02:00
parent 8c5e348437
commit e4dd5abd3e
4 changed files with 26 additions and 2 deletions

View File

@@ -20,7 +20,6 @@ using Umbraco.Tests.Testing;
namespace Umbraco.Tests.Packaging
{
[TestFixture]
[Explicit] // TODO: find out why tests only run one at at time, the tests get blocked after the first test
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerFixture)]
public class CreatedPackagesRepositoryTests : UmbracoIntegrationTest
{

View File

@@ -9,7 +9,6 @@ using Umbraco.Tests.Testing;
namespace Umbraco.Tests.Services
{
[TestFixture]
[Explicit]
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerFixture)]
public class ConsentServiceTests : UmbracoIntegrationTest
{

View File

@@ -25,6 +25,14 @@ namespace Umbraco.Tests.Integration.Testing
public const string InstanceName = "UmbracoTests";
public const string DatabaseName = "UmbracoTests";
public bool HasSchema
{
get
{
return !(_schemaPool is null) && !_schemaPool.CanAttach;
}
}
private readonly ILogger _logger;
private readonly LocalDb _localDb;
private readonly IUmbracoVersion _umbracoVersion;
@@ -254,6 +262,7 @@ namespace Umbraco.Tests.Integration.Testing
private class DatabasePool
{
public bool CanAttach => _readyQueue.Count > 0;
private readonly LocalDb _localDb;
private readonly LocalDb.Instance _instance;
private readonly string _filesPath;

View File

@@ -365,6 +365,23 @@ namespace Umbraco.Tests.Integration.Testing
break;
case UmbracoTestOptions.Database.NewSchemaPerFixture:
// If we try to AttachSchema before the old schema has been detached
// the process will be blocked since readyQueue remain empty
// Probably because the DB is blocked because it hasn't been detached
// Also if we attach a new schema for every test isn't it just essentially
// the same as NewSchemaPerTest?
if (db.HasSchema)
{
// We must re-configure our current factory since attaching a new LocalDb from the pool changes connection strings
if (!databaseFactory.Configured)
{
databaseFactory.Configure(db.ConnectionString, Constants.DatabaseProviders.SqlServer);
}
// re-run the runtime level check
runtimeState.DetermineRuntimeLevel();
return;
}
// New DB + Schema
var newSchemaFixtureDbId = db.AttachSchema();