reader._isStreamCompleted = true;
}
}
- catch (OperationCanceledException)
+ catch (OperationCanceledException ex)
{
reader.ClearCancellationToken();
- if (tokenSource.IsCancellationRequested && !cancellationToken.IsCancellationRequested)
+ if (cancellationToken.IsCancellationRequested)
+ {
+ // Simulate an OCE triggered directly by the cancellationToken rather than the InternalTokenSource
+ throw new OperationCanceledException(ex.Message, ex, cancellationToken);
+ }
+ else if (tokenSource.IsCancellationRequested)
{
// Catch cancellation and translate it into setting isCanceled = true
isCanceled = true;
{
throw;
}
-
}
return new ReadResult(reader.GetCurrentReadOnlySequence(), isCanceled, reader._isStreamCompleted);
stream.WaitForReadTask.TrySetResult(null);
- await Assert.ThrowsAsync<OperationCanceledException>(async () => await task);
+ var oce = await Assert.ThrowsAsync<OperationCanceledException>(async () => await task);
+ Assert.Equal(cts.Token, oce.CancellationToken);
+ Assert.IsType<OperationCanceledException>(oce.InnerException);
reader.Complete();
}