This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Enable BeginExecuteReader methods #33660
Merged
AfsanehR-zz
merged 9 commits into
dotnet:master
from
galakt:Enable__ExecuteReader_methods
Dec 20, 2018
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
595a1f6
Enable *ExecuteReader methods
6064218
Fix return type
4820e5f
Fix ExecuteReaderAsync
31a4944
Add test for BeginExecuteReader
d3440c0
Add test with callback
860ef7c
Move Api definition to NetCoreApp
6d286d3
Revert "Move Api definition to NetCoreApp"
e64f019
Merge branch 'master' of https://github.com/dotnet/corefx into Enable…
d6a4710
Replace CheckConnStrSetupFact
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/System.Data.SqlClient/tests/ManualTests/SQL/AsyncTest/BeginExecReaderAsyncTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using Xunit; | ||
|
||
namespace System.Data.SqlClient.ManualTesting.Tests | ||
{ | ||
public static class BeginExecReaderAsyncTest | ||
{ | ||
private static string GenerateCommandText() | ||
{ | ||
int suffix = (new Random()).Next(5000); | ||
string companyName = "M Inc."; | ||
string phone = "777-1111"; | ||
|
||
string commandText = | ||
$"CREATE TABLE #Shippers{suffix}(" + | ||
$"[ShipperID][int] NULL," + | ||
$"[CompanyName] [nvarchar] (40) NOT NULL," + | ||
$"[Phone] [nvarchar] (24) NULL )" + | ||
$"INSERT INTO #Shippers{suffix}" + | ||
$"([CompanyName] " + | ||
$",[Phone])" + | ||
$"VALUES " + | ||
$"('{companyName}' " + | ||
$",'{phone}'); " + | ||
$"WAITFOR DELAY '0:0:3'; " + | ||
$"select s.ShipperID, s.CompanyName, s.Phone " + | ||
$"from #Shippers{suffix} s; "; | ||
|
||
return commandText; | ||
} | ||
|
||
[CheckConnStrSetupFact] | ||
public static void ExecuteTest() | ||
{ | ||
using (SqlConnection connection = new SqlConnection(DataTestUtility.TcpConnStr)) | ||
{ | ||
SqlCommand command = new SqlCommand(GenerateCommandText(), connection); | ||
connection.Open(); | ||
|
||
IAsyncResult result = command.BeginExecuteReader(); | ||
while (!result.IsCompleted) | ||
{ | ||
System.Threading.Thread.Sleep(100); | ||
} | ||
SqlDataReader reader = command.EndExecuteReader(result); | ||
Assert.True(reader.HasRows, $"FAILED: Reader has no rows"); | ||
} | ||
} | ||
|
||
[CheckConnStrSetupFact] | ||
public static void BeginExecuteReaderWithCallback() | ||
{ | ||
object state = new object(); | ||
bool callbackExecutedFlag = false; | ||
|
||
using (SqlConnection connection = new SqlConnection(DataTestUtility.TcpConnStr)) | ||
using (SqlCommand command = new SqlCommand(GenerateCommandText(), connection)) | ||
{ | ||
connection.Open(); | ||
|
||
Tuple<object, SqlCommand> stateAndCommand = new Tuple<object, SqlCommand>(state, command); | ||
|
||
IAsyncResult result = command.BeginExecuteReader(ar => | ||
{ | ||
Tuple<object, SqlCommand> asyncArgs = ar.AsyncState as Tuple<object, SqlCommand>; | ||
Assert.NotNull(asyncArgs); | ||
|
||
SqlDataReader reader = asyncArgs.Item2.EndExecuteReader(ar); | ||
callbackExecutedFlag = true; | ||
Assert.True(reader.HasRows, $"FAILED: Reader has no rows"); | ||
Assert.Equal(state, asyncArgs.Item1); | ||
}, stateAndCommand); | ||
|
||
System.Threading.Thread.Sleep(TimeSpan.FromSeconds(10)); | ||
|
||
Assert.True(callbackExecutedFlag, $"FAILED: Callback did not executed"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is supposed to throwInvalidOperationException
whenThe name/value pair "Asynchronous Processing=true" was not included within the connection string defining the connection for this SqlCommand.
Doc Link
Can you check for that condition? If the connection string that is passed in doesn't have Asynchronous Processing set to true, then the test should add the parameter to the connection string.Instead of testing BeginExecuteReader with a Sleep statement, could you test an overload which takes in a callback, which is called when the execution finishes? This way you can test EndExecuteReader in the same function and it could provide more branch coverage.
Alternatively, could you add a test which tests the callback paths?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And I read more documentation
https://docs.microsoft.com/en-us/dotnet/api/system.data.sqlclient.sqlconnection.connectionstring?view=netframework-4.7.2
Please ignore the struck out comment above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was confused with "Asynchronous Processing" too. I have added test with callback.