Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 11b49e4

Browse files
authored
Fix the unhandled exception and test validation in manual tests (#27781)
* Fix the unhandled exception and test validation in manual tests * Use Task to run the command cancellation test * Fix Timeout * Use Tasks.WaitAll * Remove the faulted check as the WaitAll will throw before getting to the check
1 parent cc4abca commit 11b49e4

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

src/System.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public static TException AssertThrowsWrapper<TException, TInnerException, TInner
151151
return ex;
152152
}
153153

154-
public static TException ExpectFailure<TException>(Action actionThatFails, string exceptionMessage = null, bool innerExceptionMustBeNull = false, Func<TException, bool> customExceptionVerifier = null) where TException : Exception
154+
public static TException ExpectFailure<TException>(Action actionThatFails, string[] exceptionMessages, bool innerExceptionMustBeNull = false, Func<TException, bool> customExceptionVerifier = null) where TException : Exception
155155
{
156156
try
157157
{
@@ -161,14 +161,14 @@ public static TException ExpectFailure<TException>(Action actionThatFails, strin
161161
}
162162
catch (Exception ex)
163163
{
164-
if ((CheckException<TException>(ex, exceptionMessage, innerExceptionMustBeNull)) && ((customExceptionVerifier == null) || (customExceptionVerifier(ex as TException))))
164+
foreach (string exceptionMessage in exceptionMessages)
165165
{
166-
return (ex as TException);
167-
}
168-
else
169-
{
170-
throw;
166+
if ((CheckException<TException>(ex, exceptionMessage, innerExceptionMustBeNull)) && ((customExceptionVerifier == null) || (customExceptionVerifier(ex as TException))))
167+
{
168+
return (ex as TException);
169+
}
171170
}
171+
throw;
172172
}
173173
}
174174

src/System.Data.SqlClient/tests/ManualTests/SQL/CommandCancelTest/CommandCancelTest.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,17 @@ private static void MultiThreadedCancel(string constr, bool async)
125125
var command = con.CreateCommand();
126126
command.CommandText = "select * from orders; waitfor delay '00:00:08'; select * from customers";
127127

128-
Thread rThread1 = new Thread(ExecuteCommandCancelExpected);
129-
Thread rThread2 = new Thread(CancelSharedCommand);
130128
Barrier threadsReady = new Barrier(2);
131129
object state = new Tuple<bool, SqlCommand, Barrier>(async, command, threadsReady);
132130

133-
rThread1.Start(state);
134-
rThread2.Start(state);
135-
rThread1.Join();
136-
rThread2.Join();
131+
Task[] tasks = new Task[2];
132+
tasks[0] = new Task(ExecuteCommandCancelExpected, state);
133+
tasks[1] = new Task(CancelSharedCommand, state);
134+
tasks[0].Start();
135+
tasks[1].Start();
137136

137+
Task.WaitAll(tasks, 15 * 1000);
138+
138139
CommandCancelTest.VerifyConnection(command);
139140
}
140141
}
@@ -149,7 +150,7 @@ private static void TimeoutCancel(string constr)
149150
cmd.CommandText = "WAITFOR DELAY '00:00:30';select * from Customers";
150151

151152
string errorMessage = SystemDataResourceManager.Instance.SQL_Timeout;
152-
DataTestUtility.ExpectFailure<SqlException>(() => cmd.ExecuteReader(), errorMessage);
153+
DataTestUtility.ExpectFailure<SqlException>(() => cmd.ExecuteReader(), new string[] { errorMessage });
153154

154155
VerifyConnection(cmd);
155156
}
@@ -208,6 +209,8 @@ private static void ExecuteCommandCancelExpected(object state)
208209
Barrier threadsReady = stateTuple.Item3;
209210

210211
string errorMessage = SystemDataResourceManager.Instance.SQL_OperationCancelled;
212+
string errorMessageSevereFailure = SystemDataResourceManager.Instance.SQL_SevereError;
213+
211214
DataTestUtility.ExpectFailure<SqlException>(() =>
212215
{
213216
threadsReady.SignalAndWait();
@@ -220,7 +223,8 @@ private static void ExecuteCommandCancelExpected(object state)
220223
}
221224
} while (r.NextResult());
222225
}
223-
}, errorMessage);
226+
}, new string[] { errorMessage, errorMessageSevereFailure });
227+
224228
}
225229

226230
private static void CancelSharedCommand(object state)

0 commit comments

Comments
 (0)