Skip to content

Commit

Permalink
first
Browse files Browse the repository at this point in the history
  • Loading branch information
Davoud Eshtehari committed Apr 23, 2021
1 parent 1d4522a commit 9643853
Showing 1 changed file with 15 additions and 18 deletions.
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

0 comments on commit 9643853

Please sign in to comment.