Applied linting rules to tests within the Umbraco.Tests.Integration project.
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
// Copyright (c) Umbraco.
|
||||
// See LICENSE for more details.
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
@@ -19,7 +22,7 @@ namespace Umbraco.Tests.Integration.Testing
|
||||
protected IUmbracoDatabaseFactory _databaseFactory;
|
||||
protected IList<TestDbMeta> _testDatabases;
|
||||
|
||||
protected const int _threadCount = 2;
|
||||
protected const int ThreadCount = 2;
|
||||
|
||||
protected UmbracoDatabase.CommandInfo[] _cachedDatabaseInitCommands = new UmbracoDatabase.CommandInfo[0];
|
||||
|
||||
@@ -54,45 +57,43 @@ namespace Umbraco.Tests.Integration.Testing
|
||||
_prepareQueue.TryAdd(meta);
|
||||
}
|
||||
|
||||
protected void PrepareDatabase()
|
||||
{
|
||||
protected void PrepareDatabase() =>
|
||||
Retry(10, () =>
|
||||
{
|
||||
while (_prepareQueue.IsCompleted == false)
|
||||
{
|
||||
TestDbMeta meta;
|
||||
try
|
||||
while (_prepareQueue.IsCompleted == false)
|
||||
{
|
||||
meta = _prepareQueue.Take();
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
TestDbMeta meta;
|
||||
try
|
||||
{
|
||||
meta = _prepareQueue.Take();
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
using (var conn = new SqlConnection(meta.ConnectionString))
|
||||
using (var cmd = conn.CreateCommand())
|
||||
{
|
||||
conn.Open();
|
||||
ResetTestDatabase(cmd);
|
||||
using (var conn = new SqlConnection(meta.ConnectionString))
|
||||
using (SqlCommand cmd = conn.CreateCommand())
|
||||
{
|
||||
conn.Open();
|
||||
ResetTestDatabase(cmd);
|
||||
|
||||
if (!meta.IsEmpty)
|
||||
{
|
||||
RebuildSchema(cmd, meta);
|
||||
}
|
||||
}
|
||||
|
||||
if (!meta.IsEmpty)
|
||||
{
|
||||
RebuildSchema(cmd, meta);
|
||||
_readySchemaQueue.TryAdd(meta);
|
||||
}
|
||||
else
|
||||
{
|
||||
_readyEmptyQueue.TryAdd(meta);
|
||||
}
|
||||
}
|
||||
|
||||
if (!meta.IsEmpty)
|
||||
{
|
||||
_readySchemaQueue.TryAdd(meta);
|
||||
}
|
||||
else
|
||||
{
|
||||
_readyEmptyQueue.TryAdd(meta);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
private void RebuildSchema(IDbCommand command, TestDbMeta meta)
|
||||
{
|
||||
@@ -100,12 +101,12 @@ namespace Umbraco.Tests.Integration.Testing
|
||||
{
|
||||
if (!_cachedDatabaseInitCommands.Any())
|
||||
{
|
||||
RebuildSchemaFirstTime(command, meta);
|
||||
RebuildSchemaFirstTime(meta);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var dbCommand in _cachedDatabaseInitCommands)
|
||||
foreach (UmbracoDatabase.CommandInfo dbCommand in _cachedDatabaseInitCommands)
|
||||
{
|
||||
if (dbCommand.Text.StartsWith("SELECT "))
|
||||
{
|
||||
@@ -115,7 +116,7 @@ namespace Umbraco.Tests.Integration.Testing
|
||||
command.CommandText = dbCommand.Text;
|
||||
command.Parameters.Clear();
|
||||
|
||||
foreach (var parameterInfo in dbCommand.Parameters)
|
||||
foreach (UmbracoDatabase.ParameterInfo parameterInfo in dbCommand.Parameters)
|
||||
{
|
||||
AddParameter(command, parameterInfo);
|
||||
}
|
||||
@@ -124,7 +125,7 @@ namespace Umbraco.Tests.Integration.Testing
|
||||
}
|
||||
}
|
||||
|
||||
private void RebuildSchemaFirstTime(IDbCommand command, TestDbMeta meta)
|
||||
private void RebuildSchemaFirstTime(TestDbMeta meta)
|
||||
{
|
||||
_databaseFactory.Configure(meta.ConnectionString, Core.Constants.DatabaseProviders.SqlServer);
|
||||
|
||||
@@ -132,7 +133,7 @@ namespace Umbraco.Tests.Integration.Testing
|
||||
{
|
||||
database.LogCommands = true;
|
||||
|
||||
using (var transaction = database.GetTransaction())
|
||||
using (NPoco.ITransaction transaction = database.GetTransaction())
|
||||
{
|
||||
var schemaCreator = new DatabaseSchemaCreator(database, _loggerFactory.CreateLogger<DatabaseSchemaCreator>(), _loggerFactory, new UmbracoVersion());
|
||||
schemaCreator.InitializeDatabaseSchema();
|
||||
@@ -150,7 +151,7 @@ namespace Umbraco.Tests.Integration.Testing
|
||||
command.CommandText = sql;
|
||||
command.Parameters.Clear();
|
||||
|
||||
for (var i = 0; i < args.Length; i++)
|
||||
for (int i = 0; i < args.Length; i++)
|
||||
{
|
||||
command.Parameters.AddWithValue("@" + i, args[i]);
|
||||
}
|
||||
@@ -158,7 +159,7 @@ namespace Umbraco.Tests.Integration.Testing
|
||||
|
||||
protected static void AddParameter(IDbCommand cmd, UmbracoDatabase.ParameterInfo parameterInfo)
|
||||
{
|
||||
var p = cmd.CreateParameter();
|
||||
IDbDataParameter p = cmd.CreateParameter();
|
||||
p.ParameterName = parameterInfo.Name;
|
||||
p.Value = parameterInfo.Value;
|
||||
p.DbType = parameterInfo.DbType;
|
||||
@@ -169,7 +170,6 @@ namespace Umbraco.Tests.Integration.Testing
|
||||
protected static void ResetTestDatabase(IDbCommand cmd)
|
||||
{
|
||||
// https://stackoverflow.com/questions/536350
|
||||
|
||||
cmd.CommandType = CommandType.Text;
|
||||
cmd.CommandText = @"
|
||||
declare @n char(1);
|
||||
@@ -196,7 +196,7 @@ namespace Umbraco.Tests.Integration.Testing
|
||||
|
||||
protected static void Retry(int maxIterations, Action action)
|
||||
{
|
||||
for (var i = 0; i < maxIterations; i++)
|
||||
for (int i = 0; i < maxIterations; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -205,8 +205,7 @@ namespace Umbraco.Tests.Integration.Testing
|
||||
}
|
||||
catch (SqlException)
|
||||
{
|
||||
|
||||
//Console.Error.WriteLine($"SqlException occured, but we try again {i+1}/{maxIterations}.\n{e}");
|
||||
// Console.Error.WriteLine($"SqlException occured, but we try again {i+1}/{maxIterations}.\n{e}");
|
||||
// This can occur when there's a transaction deadlock which means (i think) that the database is still in use and hasn't been closed properly yet
|
||||
// so we need to just wait a little bit
|
||||
Thread.Sleep(100 * i);
|
||||
|
||||
Reference in New Issue
Block a user