Skip to content

Commit d74a9fe

Browse files
use using
1 parent 6eaa4a0 commit d74a9fe

File tree

1 file changed

+23
-32
lines changed

1 file changed

+23
-32
lines changed

src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ConnectionPoolTest/ConnectionPoolStressTest.cs

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -160,44 +160,35 @@ private void RunStressTest(
160160
bool async = false)
161161
{
162162
var threads = new Thread[ConcurrentConnections];
163-
var barrier = new Barrier(ConcurrentConnections);
164-
var countdown = new CountdownEvent(ConcurrentConnections);
163+
using Barrier barrier = new(ConcurrentConnections);
164+
using CountdownEvent countdown = new(ConcurrentConnections);
165165

166-
try
167-
{
168-
var command = string.IsNullOrWhiteSpace(WaitForDelay)
169-
? "SELECT GETDATE()"
170-
: $"WAITFOR DELAY '{WaitForDelay}'; SELECT GETDATE()";
171-
172-
// Create regular threads (don't doom connections)
173-
for (int i = 0; i < ConcurrentConnections - 1; i++)
174-
{
175-
threads[i] = CreateWorkerThread(
176-
connectionString, command, barrier, countdown, doomConnections: false, async);
177-
}
178-
179-
// Create special thread that dooms connections (if we have multiple threads)
180-
if (ConcurrentConnections > 1)
181-
{
182-
threads[ConcurrentConnections - 1] = CreateWorkerThread(
183-
connectionString, command, barrier, countdown, doomConnections: true, async, doomAction);
184-
}
166+
var command = string.IsNullOrWhiteSpace(WaitForDelay)
167+
? "SELECT GETDATE()"
168+
: $"WAITFOR DELAY '{WaitForDelay}'; SELECT GETDATE()";
185169

186-
// Start all threads
187-
foreach (Thread thread in threads.Where(t => t != null))
188-
{
189-
thread.Start();
190-
}
170+
// Create regular threads (don't doom connections)
171+
for (int i = 0; i < ConcurrentConnections - 1; i++)
172+
{
173+
threads[i] = CreateWorkerThread(
174+
connectionString, command, barrier, countdown, doomConnections: false, async);
175+
}
191176

192-
// Wait for completion
193-
countdown.Wait();
177+
// Create special thread that dooms connections (if we have multiple threads)
178+
if (ConcurrentConnections > 1)
179+
{
180+
threads[ConcurrentConnections - 1] = CreateWorkerThread(
181+
connectionString, command, barrier, countdown, doomConnections: true, async, doomAction);
194182
}
195-
finally
183+
184+
// Start all threads
185+
foreach (Thread thread in threads.Where(t => t != null))
196186
{
197-
// Clean up synchronization objects
198-
barrier?.Dispose();
199-
countdown?.Dispose();
187+
thread.Start();
200188
}
189+
190+
// Wait for completion
191+
countdown.Wait();
201192
}
202193

203194
/// <summary>

0 commit comments

Comments
 (0)