Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions src/NHibernate.Test/NHSpecificTest/NH2192/Fixture.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using NUnit.Framework;

namespace NHibernate.Test.NHSpecificTest.NH2192
Expand Down Expand Up @@ -73,7 +74,9 @@ public void HqlIsThreadsafe_UsingThreads()
threads.ForEach(t => t.Join());

if (exceptions.Count > 0)
{
throw exceptions[0];
}

results.ForEach(r => Assert.That(r, Is.EqualTo(2)));
}
Expand All @@ -83,25 +86,29 @@ public void HqlIsThreadsafe_UsingPool()
{
List<Exception> exceptions = new List<Exception>();
Func<int> result = FetchRowResults;
List<IAsyncResult> results = new List<IAsyncResult>();
List<Task<int>> tasks = new List<Task<int>>();

for (int i=0; i<_threadCount; i++)
results.Add(result.BeginInvoke(null, null));
for (int i = 0; i < _threadCount; i++)
{
tasks.Add(Task.Run<int>(result));
}

results.ForEach(r =>
tasks.ForEach(r =>
{
try
{
try
{
Assert.That(result.EndInvoke(r), Is.EqualTo(2));
}
catch (Exception e)
{
exceptions.Add(e);
}
});
Assert.That(r.Result, Is.EqualTo(2));
}
catch (Exception e)
{
exceptions.Add(e);
}
});

if (exceptions.Count > 0)
{
throw exceptions[0];
}
}

private int FetchRowResults()
Expand Down
9 changes: 5 additions & 4 deletions src/NHibernate.Test/NHSpecificTest/NH3050/Fixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;

using NHibernate.Engine.Query;
using NHibernate.Linq;
Expand Down Expand Up @@ -144,11 +145,11 @@ where personIds.Contains(person.Id)
}
};

var queryExecutorAsyncResult = queryExecutor.BeginInvoke(null, null);
var cacheCleanerAsyncResult = cacheCleaner.BeginInvoke(null, null);
var queryExecutorTask = Task.Run(queryExecutor);
var cacheCleanerTask = Task.Run(cacheCleaner);

queryExecutor.EndInvoke(queryExecutorAsyncResult);
cacheCleaner.EndInvoke(cacheCleanerAsyncResult);
queryExecutorTask.Wait();
cacheCleanerTask.Wait();

Assert.IsTrue(allLinqQueriesSucceeded);
}
Expand Down