Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests | Fix TvpTest intermittent failures #1046

Merged
merged 1 commit into from
Apr 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -457,17 +457,16 @@ private static void ImmediateCancelBin()
byte[] data = new byte[dataSize];
rand.NextBytes(data);
MemoryStream ms = new MemoryStream(data, false);
cmd.CommandText = "insert into #blobs (Id, blob) values (1, @blob)";
// Include a delay to allow time for cancellation
cmd.CommandText = "WAITFOR DELAY '00:00:05'; insert into #blobs (Id, blob) values (1, @blob)";
cmd.Parameters.Add("@blob", SqlDbType.VarBinary, dataSize);
cmd.Parameters["@blob"].Direction = ParameterDirection.Input;
cmd.Parameters["@blob"].Value = ms;
Task t = cmd.ExecuteNonQueryAsync(cts.Token);
if (!t.IsCompleted)
cts.Cancel();

try
{
t.Wait();
Console.WriteLine("FAIL: Expected AggregateException on Task wait for Cancelled Task! Task Status: " + t.Status);
Task.WaitAll(cmd.ExecuteNonQueryAsync(cts.Token), Task.Run(() => cts.Cancel()));
Console.WriteLine("FAIL: Expected AggregateException on Task wait for Cancelled Task!");
}
catch (AggregateException ae)
{
Expand Down Expand Up @@ -504,17 +503,16 @@ private static void ImmediateCancelText()
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 1000000; i++)
sb.Append(i);
cmd.CommandText = "insert into #blobs (Id, blob) values (1, @blob)";
// Include a delay to allow time for cancellation
cmd.CommandText = "WAITFOR DELAY '00:00:05'; insert into #blobs (Id, blob) values (1, @blob)";
cmd.Parameters.Add("@blob", SqlDbType.VarChar, -1);
cmd.Parameters["@blob"].Direction = ParameterDirection.Input;
cmd.Parameters["@blob"].Value = new StringReader(sb.ToString());
Task t = cmd.ExecuteNonQueryAsync(cts.Token);
if (!t.IsCompleted)
cts.Cancel();

try
{
t.Wait();
Console.WriteLine("FAIL: Expected AggregateException on Task wait for Cancelled Task! Task Status: " + t.Status);
Task.WaitAll(cmd.ExecuteNonQueryAsync(cts.Token), Task.Run(() => cts.Cancel()));
Console.WriteLine("FAIL: Expected AggregateException on Task wait for Cancelled Task!");
}
catch (AggregateException ae)
{
Expand Down Expand Up @@ -544,17 +542,16 @@ private static void ImmediateCancelXml()
{
cmd.CommandText = "create table #blobs (Id int, blob xml)";
cmd.ExecuteNonQuery();
cmd.CommandText = "insert into #blobs (Id, blob) values (1, @blob)";
// Include a delay to allow time for cancellation
cmd.CommandText = "WAITFOR DELAY '00:00:05'; insert into #blobs (Id, blob) values (1, @blob)";
cmd.Parameters.Add("@blob", SqlDbType.Xml, -1);
cmd.Parameters["@blob"].Direction = ParameterDirection.Input;
cmd.Parameters["@blob"].Value = XmlReader.Create(new StringReader(XmlStr));
Task t = cmd.ExecuteNonQueryAsync(cts.Token);
if (!t.IsCompleted)
cts.Cancel();

try
{
t.Wait();
Console.WriteLine("FAIL: Expected AggregateException on Task wait for Cancelled Task! Task Status: " + t.Status);
Task.WaitAll(cmd.ExecuteNonQueryAsync(cts.Token), Task.Run(() => cts.Cancel()));
Console.WriteLine("FAIL: Expected AggregateException on Task wait for Cancelled Task!");
}
catch (AggregateException ae)
{
Expand Down