From 70fc0a84c1124136d346ff5002b665849cbb6187 Mon Sep 17 00:00:00 2001 From: campersau Date: Fri, 7 Jun 2019 10:58:20 +0200 Subject: [PATCH 1/2] Pass CancellationToken to DbDataReader --- .../src/System/Data/DataReaderExtensions.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/System.Data.Common/src/System/Data/DataReaderExtensions.cs b/src/System.Data.Common/src/System/Data/DataReaderExtensions.cs index 05ec669ba14b..cff7b3804c5d 100644 --- a/src/System.Data.Common/src/System/Data/DataReaderExtensions.cs +++ b/src/System.Data.Common/src/System/Data/DataReaderExtensions.cs @@ -88,7 +88,7 @@ public static T GetFieldValue(this DbDataReader reader, string name) public static Task GetFieldValueAsync(this DbDataReader reader, string name, CancellationToken cancellationToken = default(CancellationToken)) { AssertNotNull(reader); - return reader.GetFieldValueAsync(reader.GetOrdinal(name)); + return reader.GetFieldValueAsync(reader.GetOrdinal(name), cancellationToken); } public static float GetFloat(this DbDataReader reader, string name) @@ -168,7 +168,7 @@ public static bool IsDBNull(this DbDataReader reader, string name) public static Task IsDBNullAsync(this DbDataReader reader, string name, CancellationToken cancellationToken = default(CancellationToken)) { AssertNotNull(reader); - return reader.IsDBNullAsync(reader.GetOrdinal(name)); + return reader.IsDBNullAsync(reader.GetOrdinal(name), cancellationToken); } private static void AssertNotNull(DbDataReader reader) From ff82747867f1290d4175458e9e1d27f9f9c8e6e3 Mon Sep 17 00:00:00 2001 From: campersau Date: Fri, 7 Jun 2019 15:50:16 +0200 Subject: [PATCH 2/2] add cancellation tests --- .../Data/Common/DbDataReaderTest.netcoreapp.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/System.Data.Common/tests/System/Data/Common/DbDataReaderTest.netcoreapp.cs b/src/System.Data.Common/tests/System/Data/Common/DbDataReaderTest.netcoreapp.cs index 74863b5d0ba7..d78b7b3e7657 100644 --- a/src/System.Data.Common/tests/System/Data/Common/DbDataReaderTest.netcoreapp.cs +++ b/src/System.Data.Common/tests/System/Data/Common/DbDataReaderTest.netcoreapp.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Threading; +using System.Threading.Tasks; using Xunit; namespace System.Data.Tests.Common @@ -319,6 +321,18 @@ public void IsDBNullByColumnNameTest() Assert.True(_dataReader.IsDBNull("dbnull_col")); } + [Fact] + public Task GetValueAsyncByColumnNameCanceledTest() + { + return Assert.ThrowsAsync(() => _dataReader.GetFieldValueAsync("text_col", new CancellationToken(true))); + } + + [Fact] + public Task IsDbNullAsyncByColumnNameCanceledTest() + { + return Assert.ThrowsAsync(() => _dataReader.IsDBNullAsync("dbnull_col", new CancellationToken(true))); + } + private void SkipRows(int rowsToSkip) { var i = 0;