Removed the uow ctor from the SaveEventArgs for testing as the test will still prove that

multi-threading works with the services without proving access to a single uow, the db will error first anyways.
This commit is contained in:
Shannon Deminick
2012-12-11 22:56:34 +05:00
parent 43e74fa7a4
commit cfa8fc2bba
4 changed files with 9 additions and 71 deletions

View File

@@ -42,30 +42,7 @@ namespace Umbraco.Core
/// </summary>
public int Id { get; set; }
}
public class SaveEventArgs : System.ComponentModel.CancelEventArgs
{
/// <summary>
/// public constructor
/// </summary>
public SaveEventArgs()
{
}
/// <summary>
/// internal constructor used for unit testing
/// </summary>
/// <param name="unitOfWork"></param>
internal SaveEventArgs(IUnitOfWork unitOfWork)
{
UnitOfWork = unitOfWork;
}
/// <summary>
/// Used for unit testing
/// </summary>
internal IUnitOfWork UnitOfWork { get; private set; }
}
public class SaveEventArgs : System.ComponentModel.CancelEventArgs { }
public class NewEventArgs : System.ComponentModel.CancelEventArgs
{
/// <summary>

View File

@@ -430,7 +430,7 @@ namespace Umbraco.Core.Services
var uow = _uowProvider.GetUnitOfWork();
using (var repository = RepositoryResolver.Current.Factory.CreateContentRepository(uow))
{
var e = new SaveEventArgs(uow);
var e = new SaveEventArgs();
if (Saving != null)
Saving(content, e);
@@ -490,7 +490,7 @@ namespace Umbraco.Core.Services
var uow = _uowProvider.GetUnitOfWork();
using (var repository = RepositoryResolver.Current.Factory.CreateContentRepository(uow))
{
var e = new SaveEventArgs(uow);
var e = new SaveEventArgs();
if (Saving != null)
Saving(content, e);
@@ -524,7 +524,7 @@ namespace Umbraco.Core.Services
{
var containsNew = contents.Any(x => x.HasIdentity == false);
var e = new SaveEventArgs(uow);
var e = new SaveEventArgs();
if (Saving != null)
Saving(contents, e);
@@ -573,7 +573,7 @@ namespace Umbraco.Core.Services
var uow = _uowProvider.GetUnitOfWork();
using (var repository = RepositoryResolver.Current.Factory.CreateContentRepository(uow))
{
var e = new SaveEventArgs(uow);
var e = new SaveEventArgs();
if (Saving != null)
Saving(contents, e);

View File

@@ -204,7 +204,7 @@ namespace Umbraco.Core.Services
{
var repository = _mediaRepository;
var e = new SaveEventArgs(_unitOfWork);
var e = new SaveEventArgs();
if (Saving != null)
Saving(media, e);

View File

@@ -59,7 +59,7 @@ namespace Umbraco.Tests.Services
private Tuple<int, Guid> _lastUowIdWithThread = null;
[Test]
public void Ensure_All_Threads_Reference_Different_Units_Of_Work_Content_Service()
public void Ensure_All_Threads_Execute_Successfully_Content_Service()
{
//we will mimick the ServiceContext in that each repository in a service (i.e. ContentService) is a singleton
var contentService = (ContentService)ServiceContext.ContentService;
@@ -68,9 +68,6 @@ namespace Umbraco.Tests.Services
Debug.WriteLine("Starting test...");
//bind to event to determine what is going on during the saving process
ContentService.Saving += HandleSaving;
for (var i = 0; i < _maxThreadCount; i++)
{
var t = new Thread(() =>
@@ -124,7 +121,7 @@ namespace Umbraco.Tests.Services
}
[Test]
public void Ensure_All_Threads_Reference_Different_Units_Of_Work_Media_Service()
public void Ensure_All_Threads_Execute_Successfully_Media_Service()
{
//we will mimick the ServiceContext in that each repository in a service (i.e. ContentService) is a singleton
var mediaService = (MediaService)ServiceContext.MediaService;
@@ -133,9 +130,6 @@ namespace Umbraco.Tests.Services
Debug.WriteLine("Starting test...");
//bind to event to determine what is going on during the saving process
ContentService.Saving += HandleSaving;
for (var i = 0; i < _maxThreadCount; i++)
{
var t = new Thread(() =>
@@ -189,40 +183,7 @@ namespace Umbraco.Tests.Services
}
}
private void HandleSaving(object sender, SaveEventArgs args)
{
if (_error == null)
{
lock (_locker)
{
//get the instance id of the unit of work
var uowId = ((PetaPocoUnitOfWork)args.UnitOfWork).InstanceId;
if (_lastUowIdWithThread == null)
{
Debug.WriteLine("Initial UOW found = " + uowId + " with thread id " + Thread.CurrentThread.ManagedThreadId);
_lastUowIdWithThread = new Tuple<int, Guid>(
Thread.CurrentThread.ManagedThreadId, uowId);
}
else
{
Debug.WriteLine("Next thread running. UOW found = " + uowId + " with thread id " + Thread.CurrentThread.ManagedThreadId);
var newTuple = new Tuple<int, Guid>(
Thread.CurrentThread.ManagedThreadId, uowId);
//check if the uowId is the same as the last and if the thread Id's are different then we have a problem
if (newTuple.Item2 == _lastUowIdWithThread.Item2
&& newTuple.Item1 != _lastUowIdWithThread.Item1)
{
_error = new Exception("The threads: " + newTuple.Item1 + " and " + _lastUowIdWithThread.Item1 + " are both referencing the Unit of work: " + _lastUowIdWithThread.Item2);
}
}
}
}
}
public void CreateTestData()
{
//Create and Save ContentType "umbTextpage" -> 1045