Skip to content

Commit a65b8a4

Browse files
authored
Tests | ActiveIssues (Part 4) (#3750)
* Reenable tests in SqlCommandCancelTest: TimeoutCancelTcp, TimeoutCancelNamedPipe, TimeoutDuringReadTcp, TimeoutDuringReadNamedPipe * Reenable tests in SqlCredentialTest - SqlConnectionChangePasswordPlaintext, SqlConnectionChangePasswordSecureString * Very light cleanup of SqlCredentialTest * Reenable MarsSessionPoolingTest in MarsExecuteReader_Text_WithGC and MarsExecuteReader_StoredProcedure_WithGC # Conflicts: # src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/MARSSessionPoolingTest/MARSSessionPoolingTest.cs * Split tests into separate tests for each scenario, discover which tests are flaky * Mostly working . Except for those no close tests * Clean up old code, but the nocloses test still breaks everything - need to investigate if it's a bug * Clean up a biiiit more * Finishing test matrix, improving DisposableArray, renaming test file to match guidelines * Final iteration of tests, adding backoff to DMV queries, adding #nullable enable * Fix mistakes in MARS tests * Rewrite TimeoutCancel to use less custom utilities - hopefully this will make it easier to sort out why we have these failures * Fix session => request comment * Re-disable TimeoutCancelNamedPipe due to bug in managed SNI implementation * Remove AreConnStringsNotAzureSynapse Adding doc comments to DisposableArray
1 parent 2bb4461 commit a65b8a4

File tree

6 files changed

+589
-322
lines changed

6 files changed

+589
-322
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Collections;
7+
using System.Collections.Generic;
8+
9+
#nullable enable
10+
11+
namespace Microsoft.Data.SqlClient.Tests.Common
12+
{
13+
/// <summary>
14+
/// Utility class that enables disposal of a collection of <see cref="IDisposable"/> objects
15+
/// with a single <c>using</c> statement.
16+
/// </summary>
17+
/// <typeparam name="T">Type of the elements contained within.</typeparam>
18+
public class DisposableArray<T> : IDisposable, IEnumerable<T>
19+
where T : IDisposable?
20+
{
21+
private readonly T[] _elements;
22+
23+
/// <summary>
24+
/// Constructs a new instance with <paramref name="size"/> elements.
25+
/// </summary>
26+
/// <remarks>
27+
/// Remember when using this constructor that the underlying array will be initialized to
28+
/// <c>default(T)</c>. If <typeparamref name="T"/> is a reference type, this will be
29+
/// <c>null</c> - even if <typeparamref name="T"/> is not nullable!
30+
/// </remarks>
31+
/// <param name="size">Number of elements the new instance will contain.</param>
32+
public DisposableArray(int size)
33+
{
34+
_elements = new T[size];
35+
}
36+
37+
/// <summary>
38+
/// Constructs a new instance from an existing array of elements.
39+
/// </summary>
40+
/// <param name="elements">Array of elements to store within the current instance.</param>
41+
public DisposableArray(T[] elements)
42+
{
43+
_elements = elements;
44+
}
45+
46+
/// <summary>
47+
/// Gets or sets the element at index <see cref="i"/>.
48+
/// </summary>
49+
/// <param name="i">The element to get/set will be at this position in the array</param>
50+
public T this[int i]
51+
{
52+
get => _elements[i];
53+
set => _elements[i] = value;
54+
}
55+
56+
/// <summary>
57+
/// Gets the number of elements in the array.
58+
/// </summary>
59+
public int Length => _elements.Length;
60+
61+
/// <summary>
62+
/// Disposes all elements in the current instance. Each element will be checked for
63+
/// <c>null</c> before disposing it.
64+
/// </summary>
65+
public void Dispose()
66+
{
67+
foreach (T element in _elements)
68+
{
69+
element?.Dispose();
70+
}
71+
72+
GC.SuppressFinalize(this);
73+
}
74+
75+
/// <inheritdoc/>
76+
public IEnumerator<T> GetEnumerator() =>
77+
((IEnumerable<T>)_elements).GetEnumerator();
78+
79+
/// <inheritdoc/>
80+
IEnumerator IEnumerable.GetEnumerator() =>
81+
_elements.GetEnumerator();
82+
}
83+
}

src/Microsoft.Data.SqlClient/tests/ManualTests/Microsoft.Data.SqlClient.ManualTesting.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@
181181
<Compile Include="SQL\KerberosTests\KerberosTest.cs" />
182182
<Compile Include="SQL\KerberosTests\KerberosTicketManager\KerberosTicketManager.cs" />
183183
<Compile Include="SQL\LocalDBTest\LocalDBTest.cs" />
184-
<Compile Include="SQL\MARSSessionPoolingTest\MARSSessionPoolingTest.cs" />
184+
<Compile Include="SQL\MARSSessionPoolingTest\MarsSessionPoolingTest.cs" />
185185
<Compile Include="SQL\MARSTest\MARSTest.cs" />
186186
<Compile Include="SQL\MirroringTest\ConnectionOnMirroringTest.cs" />
187187
<Compile Include="SQL\ParallelTransactionsTest\ParallelTransactionsTest.cs" />

0 commit comments

Comments
 (0)