Skip to content

Commit fcffd64

Browse files
Fix more threads test
1 parent 9bec52a commit fcffd64

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

src/NHibernate.Test/Async/NHSpecificTest/Logs/LogsFixture.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,15 @@ public async Task WillGetSessionIdFromSessionLogsConcurrentAsync()
159159
var semaphore = new SemaphoreSlim(0);
160160
var failures = new ConcurrentBag<Exception>();
161161
var sessionIds = new ConcurrentDictionary<int, Guid>();
162+
var threadCount = 10;
163+
if (threadCount > TestDialect.MaxNumberOfConnections)
164+
threadCount = TestDialect.MaxNumberOfConnections.Value;
162165
using (var spy = new TextLogSpy("NHibernate.SQL", "%message | SessionId: %property{sessionId}"))
163166
{
164167
await (Task.WhenAll(
165-
Enumerable.Range(1, 12 - 1).Select(async i =>
168+
Enumerable.Range(1, threadCount + 2 - 1).Select(async i =>
166169
{
167-
if (i > 10)
170+
if (i > threadCount)
168171
{
169172
// Give some time to threads for reaching the wait, having all of them ready to do most of their job concurrently.
170173
await (Task.Delay(100));
@@ -198,7 +201,7 @@ public async Task WillGetSessionIdFromSessionLogsConcurrentAsync()
198201
Assert.That(failures, Is.Empty, $"{failures.Count} task(s) failed.");
199202

200203
var loggingEvent = spy.GetWholeLog();
201-
for (var i = 1; i < 11; i++)
204+
for (var i = 1; i < threadCount + 1; i++)
202205
for (var j = 0; j < 10; j++)
203206
{
204207
var sessionId = sessionIds[i];

src/NHibernate.Test/NHSpecificTest/Logs/LogsFixture.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,16 @@ public void WillGetSessionIdFromSessionLogsConcurrent()
148148
var semaphore = new SemaphoreSlim(0);
149149
var failures = new ConcurrentBag<Exception>();
150150
var sessionIds = new ConcurrentDictionary<int, Guid>();
151+
var threadCount = 10;
152+
if (threadCount > TestDialect.MaxNumberOfConnections)
153+
threadCount = TestDialect.MaxNumberOfConnections.Value;
151154
using (var spy = new TextLogSpy("NHibernate.SQL", "%message | SessionId: %property{sessionId}"))
152155
{
153156
Parallel.For(
154-
1, 12,
157+
1, threadCount + 2,
155158
i =>
156159
{
157-
if (i > 10)
160+
if (i > threadCount)
158161
{
159162
// Give some time to threads for reaching the wait, having all of them ready to do most of their job concurrently.
160163
Thread.Sleep(100);
@@ -188,7 +191,7 @@ public void WillGetSessionIdFromSessionLogsConcurrent()
188191
Assert.That(failures, Is.Empty, $"{failures.Count} task(s) failed.");
189192

190193
var loggingEvent = spy.GetWholeLog();
191-
for (var i = 1; i < 11; i++)
194+
for (var i = 1; i < threadCount + 1; i++)
192195
for (var j = 0; j < 10; j++)
193196
{
194197
var sessionId = sessionIds[i];

src/NHibernate.Test/NHSpecificTest/NH3436/Fixture.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ public void TestQueryWithContainsInParallel()
6464
Guid.NewGuid(),
6565
Guid.NewGuid(),
6666
};
67-
const int threadsToRun = 32;
67+
var threadsToRun = 32;
68+
if (threadsToRun > TestDialect.MaxNumberOfConnections)
69+
threadsToRun = TestDialect.MaxNumberOfConnections.Value;
70+
6871
var events = new WaitHandle[threadsToRun];
6972
var exceptions = new List<Exception>();
7073
for (var i = 0; i < threadsToRun; i++)

0 commit comments

Comments
 (0)