Skip to content

Commit 762af05

Browse files
authored
Fix CanCancelContentUploadHttps flakiness (Azure#21849)
1 parent 4af3cf4 commit 762af05

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

sdk/core/Azure.Core/src/RequestContent.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,10 @@ public override void WriteTo(Stream stream, CancellationToken cancellationToken)
142142
{
143143
while (true)
144144
{
145-
cancellationToken.ThrowIfCancellationRequested();
145+
CancellationHelper.ThrowIfCancellationRequested(cancellationToken);
146146
var read = _stream.Read(buffer, 0, buffer.Length);
147147
if (read == 0) { break; }
148-
cancellationToken.ThrowIfCancellationRequested();
148+
CancellationHelper.ThrowIfCancellationRequested(cancellationToken);
149149
stream.Write(buffer, 0, read);
150150
}
151151
}

sdk/core/Azure.Core/tests/HttpPipelineRequestContentTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Text;
77
using System.Text.Json;
88
using System.Threading;
9+
using System.Threading.Tasks;
910
using NUnit.Framework;
1011

1112
namespace Azure.Core.Tests
@@ -21,7 +22,7 @@ public void StreamCopyToCancellation()
2122
var content = RequestContent.Create(source);
2223
var cancellation = new CancellationTokenSource();
2324
cancellation.Cancel();
24-
Assert.Throws<OperationCanceledException>(() => { content.WriteTo(destination, cancellation.Token); });
25+
Assert.Throws<TaskCanceledException>(() => { content.WriteTo(destination, cancellation.Token); });
2526
}
2627

2728
[Test]

0 commit comments

Comments
 (0)