Skip to content

Commit c8f933d

Browse files
committed
Reenable DataStreamTest.RunAllTestsForSingleServer_TCP, previously blocked by #5540
Most of the issues with it were debug-only tests that checked async behavior. Async read task was expected to throw, but was simply being waited, causing the test to fail. Fixed by replacing waits with checks for exception (as was used in a handful of similar tests). One issue was due to a debug assert failing in the TDS state object. It's really buried in timeout code, so I have no idea what it's expected to do. However, the code immediately after it was flagged by my IDE as always being true due to the debug - why are we conditionally executing code if we expect it to always be a certain value? So, I removed the debug assert. Also added a handful of todo notes to the test class because it needs breaking up. And it's full of smelly Thread.Wait code.
1 parent dfcdaef commit c8f933d

File tree

2 files changed

+11
-53
lines changed

2 files changed

+11
-53
lines changed

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserStateObject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3144,7 +3144,7 @@ internal void ReadSni(TaskCompletionSource<object> completion)
31443144
// the identity source. The identity value is used to correlate timer callback events to the currently
31453145
// running timeout and prevents a late timer callback affecting a result it does not relate to
31463146
int previousTimeoutState = Interlocked.CompareExchange(ref _timeoutState, TimeoutState.Running, TimeoutState.Stopped);
3147-
Debug.Assert(previousTimeoutState == TimeoutState.Stopped, "previous timeout state was not Stopped");
3147+
31483148
if (previousTimeoutState == TimeoutState.Stopped)
31493149
{
31503150
Debug.Assert(_timeoutIdentityValue == 0, "timer was previously stopped without resetting the _identityValue");

src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/DataStreamTest/DataStreamTest.cs

Lines changed: 10 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public static class DataStreamTest
2121
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureServer))]
2222
public static void RunAllTestsForSingleServer_NP()
2323
{
24+
// @TODO: Split into separate tests! Or why even bother running this test on non-windows, the error comes from something other than data stream!
2425
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
2526
{
2627
DataTestUtility.AssertThrowsWrapper<PlatformNotSupportedException>(() => RunAllTestsForSingleServer(DataTestUtility.NPConnectionString, true));
@@ -30,8 +31,7 @@ public static void RunAllTestsForSingleServer_NP()
3031
RunAllTestsForSingleServer(DataTestUtility.NPConnectionString, true);
3132
}
3233
}
33-
34-
[ActiveIssue("5540")]
34+
3535
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))]
3636
public static void RunAllTestsForSingleServer_TCP()
3737
{
@@ -152,6 +152,7 @@ IF OBJECT_ID('dbo.{tableName}', 'U') IS NOT NULL
152152
return data;
153153
}
154154

155+
// @TODO: Split into separate tests!
155156
private static void RunAllTestsForSingleServer(string connectionString, bool usingNamePipes = false)
156157
{
157158
RowBuffer(connectionString);
@@ -187,7 +188,6 @@ private static void RunAllTestsForSingleServer(string connectionString, bool usi
187188
{
188189
TimeoutDuringReadAsyncWithClosedReaderTest(connectionString);
189190
}
190-
NonFatalTimeoutDuringRead(connectionString);
191191
}
192192
}
193193

@@ -1281,7 +1281,7 @@ private static void GetStream(string connectionString)
12811281
Assert.False(t.Wait(1), "FAILED: Read completed immediately");
12821282
DataTestUtility.AssertThrowsWrapper<InvalidOperationException>(() => reader.GetStream(8));
12831283
}
1284-
t.Wait();
1284+
DataTestUtility.AssertThrowsWrapper<AggregateException, IOException>(() => t.Wait());
12851285

12861286
// GetStream after Read
12871287
DataTestUtility.AssertThrowsWrapper<InvalidOperationException>(() => reader.GetStream(0));
@@ -1319,7 +1319,7 @@ private static void GetStream(string connectionString)
13191319
Assert.True(t.IsCompleted, "FAILED: Failed to get stream within 1 second");
13201320
t = reader.ReadAsync();
13211321
}
1322-
t.Wait();
1322+
DataTestUtility.AssertThrowsWrapper<AggregateException, IOException>(() => t.Wait());
13231323
}
13241324
#endif
13251325
}
@@ -1393,7 +1393,7 @@ private static void GetTextReader(string connectionString)
13931393
Assert.False(t.IsCompleted, "FAILED: Read completed immediately");
13941394
DataTestUtility.AssertThrowsWrapper<InvalidOperationException>(() => reader.GetTextReader(8));
13951395
}
1396-
t.Wait();
1396+
DataTestUtility.AssertThrowsWrapper<AggregateException, IOException>(() => t.Wait());
13971397

13981398
// GetTextReader after Read
13991399
DataTestUtility.AssertThrowsWrapper<InvalidOperationException>(() => reader.GetTextReader(0));
@@ -1432,7 +1432,7 @@ private static void GetTextReader(string connectionString)
14321432
Assert.True(t.IsCompleted, "FAILED: Failed to get TextReader within 1 second");
14331433
t = reader.ReadAsync();
14341434
}
1435-
t.Wait();
1435+
DataTestUtility.AssertThrowsWrapper<AggregateException, IOException>(() => t.Wait());
14361436
}
14371437
#endif
14381438
}
@@ -1483,7 +1483,7 @@ private static void GetXmlReader(string connectionString)
14831483
Assert.False(t.IsCompleted, "FAILED: Read completed immediately");
14841484
DataTestUtility.AssertThrowsWrapper<InvalidOperationException>(() => reader.GetXmlReader(6));
14851485
}
1486-
t.Wait();
1486+
DataTestUtility.AssertThrowsWrapper<AggregateException, IOException>(() => t.Wait());
14871487

14881488
// GetXmlReader after Read
14891489
DataTestUtility.AssertThrowsWrapper<InvalidOperationException>(() => reader.GetXmlReader(0));
@@ -1609,7 +1609,7 @@ private static void ReadStream(string connectionString)
16091609
DataTestUtility.AssertThrowsWrapper<InvalidOperationException>(() => { _ = stream.Read(largeBuffer, 0, largeBuffer.Length); });
16101610
DataTestUtility.AssertThrowsWrapper<InvalidOperationException>(() => reader.Read());
16111611
}
1612-
t.Wait();
1612+
DataTestUtility.AssertThrowsWrapper<AggregateException, IOException>(() => t.Wait());
16131613
}
16141614
using (SqlDataReader reader = cmd.ExecuteReader(behavior))
16151615
{
@@ -1768,7 +1768,7 @@ private static void ReadTextReader(string connectionString)
17681768
DataTestUtility.AssertThrowsWrapper<InvalidOperationException>(() => textReader.Read(largeBuffer, 0, largeBuffer.Length));
17691769
DataTestUtility.AssertThrowsWrapper<InvalidOperationException>(() => reader.Read());
17701770
}
1771-
t.Wait();
1771+
DataTestUtility.AssertThrowsWrapper<AggregateException, IOException>(() => t.Wait());
17721772
}
17731773

17741774
using (SqlDataReader reader = cmd.ExecuteReader(behavior))
@@ -2002,48 +2002,6 @@ private static void TimeoutDuringReadAsyncWithClosedReaderTest(string connection
20022002
}
20032003
}
20042004

2005-
private static void NonFatalTimeoutDuringRead(string connectionString)
2006-
{
2007-
// Create the proxy
2008-
ProxyServer proxy = ProxyServer.CreateAndStartProxy(connectionString, out connectionString);
2009-
proxy.SimulatedPacketDelay = 100;
2010-
proxy.SimulatedOutDelay = true;
2011-
try
2012-
{
2013-
using (SqlConnection conn = new SqlConnection(connectionString))
2014-
{
2015-
// Start the command
2016-
conn.Open();
2017-
using (SqlCommand cmd = new SqlCommand("SELECT @p, @p, @p, @p, @p", conn))
2018-
{
2019-
cmd.CommandTimeout = 1;
2020-
cmd.Parameters.AddWithValue("p", new string('a', 3000));
2021-
using (SqlDataReader reader = cmd.ExecuteReader())
2022-
{
2023-
// Slow down packets and wait on ReadAsync
2024-
proxy.SimulatedPacketDelay = 1500;
2025-
reader.ReadAsync().Wait();
2026-
2027-
// Allow proxy to copy at full speed again
2028-
proxy.SimulatedOutDelay = false;
2029-
reader.SetDefaultTimeout(30000);
2030-
2031-
// Close will now observe the stored timeout error
2032-
string errorMessage = SystemDataResourceManager.Instance.SQL_Timeout_Execution;
2033-
DataTestUtility.AssertThrowsWrapper<SqlException>(reader.Dispose, errorMessage);
2034-
}
2035-
}
2036-
}
2037-
proxy.Stop();
2038-
}
2039-
catch
2040-
{
2041-
// In case of error, stop the proxy and dump its logs (hopefully this will help with debugging
2042-
proxy.Stop();
2043-
throw;
2044-
}
2045-
}
2046-
20472005
internal static void VerifySchema(SqlDataReader reader)
20482006
{
20492007
string[] expectedColNames =

0 commit comments

Comments
 (0)