-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Update SqlClient manual test feature detection #34040
Conversation
…ases by name and attributes to use them
@Wraith2 This should help you setup the UdtTestDb, let me know if you encounter any issues or have questions. |
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.
Comments are around using ConditionalFact instead of creating new attributes.
E.g.
corefx/src/System.Diagnostics.PerformanceCounter/tests/PerformanceCounterTests.cs
Line 15 in a10890f
[ConditionalFact(typeof(Helpers), nameof(Helpers.IsElevatedAndCanWriteToPerfCounters))] |
|
||
namespace System.Data.SqlClient.ManualTesting.Tests | ||
{ | ||
public class CheckDatabaseIsPresentFactAttribute : FactAttribute |
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.
The general recommendation in CoreFx is to use ConditionalFact
CheckConnStrSetupFact
was setup before ConditionalFact
was introduced.
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 particular check needs a parameter. You could add a static in the test files which need to check for the IsDatabasePresent(string) , and pass in the Database name in the test specific static method.
|
||
namespace System.Data.SqlClient.ManualTesting.Tests | ||
{ | ||
public class CheckServiceBrokerEnabledFactAttribute : FactAttribute |
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.
Use ConditionalFact over new FactAttributes
|
||
public static bool IsDatabasePresent(string name) | ||
{ | ||
if (databasesAvailable == null) |
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.
Nit: Could be databasesAvailable = databasesAvailable ?? new Dictionary<string, bool>();
All feedback addressed, new attributes are gone replaced with ConditionalFacts |
That's a good idea |
src/System.Data.SqlClient/tests/ManualTests/SQL/SqlNotificationTest/SqlNotificationTest.cs
Outdated
Show resolved
Hide resolved
src/System.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs
Outdated
Show resolved
Hide resolved
src/System.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs
Outdated
Show resolved
Hide resolved
src/System.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs
Show resolved
Hide resolved
string database = builder.InitialCatalog; | ||
builder.ConnectTimeout = 2; | ||
using (var connection = new SqlConnection(builder.ToString())) | ||
using (var command = new SqlCommand("SELECT is_service_broker_enabled FROM sys.sys.databases WHERE name=@name", connection)) |
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.
Here's a bug. The name of the DB is hardcoded to @name. When I try to run the tests on my server where SB is enabled, the tests are skipped. Please fix this to pass in the correct DB name
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.
Please fix the check for the Service Broker to pass in the DB name and to surface the exception if the Service Broker query fails.
Ok, but how? the sql dependency test don't use a specific database which is why the current code tried to pull the database name out of the connection string, it failed due to other bugs but i'll fix those as suggested. |
I looked at the notifications tests, the constructor is supposed to setup the required infra for query notification |
The more I think about this change, I feel you should remove |
That should fix it. The connection string has northwind in it so anything not using northwind will have to specify the database for itself, on that basis it'll either work or throw as you suggested indicating the setup is incorrect. |
If the setup of the notification test changes to create a new database and tables for the Notification tests, then they will continue to be skipped because the Northwind database is being checked for Service Broker enablement. Right now this is what is happening.
The problem is that we are hiding the shortcomings of step 2. I would much rather fix that, than skipping the tests because the setup failed. What errors do you get when you try to run the above SQL Statements in SSMS or any other tool that can work with SQL Server?? |
The tests run and pass as of the fix I pushed this morning. I just tried those statements, they work as expected. If the test changes to use a specific database then it would need to pass the constr being used as a parameter, which I can do with a local static function similar to the ones I removed yesterday. |
This is good to know. I don't understand what part of the fix, alleviated the issue for you? The way I see it, is that the test is self contained. We shouldn't need this check. If the setup in the test fails, then that's something worth look into. Can we get rid of this check for |
Ok, shall I leave the utility function in DataTestUtility in case someone else needs it or get rid of everything? |
You should get rid of everything related to |
Done. |
src/System.Data.SqlClient/tests/ManualTests/SQL/SqlNotificationTest/SqlNotificationTest.cs
Outdated
Show resolved
Hide resolved
@@ -21,6 +25,10 @@ public static class DataTestUtility | |||
".database.cloudapi.de", | |||
".database.usgovcloudapi.net", | |||
".database.chinacloudapi.cn"}; | |||
|
|||
private static bool? serviceBrokerEnabled; |
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.
Not needed anymore.
@Wraith2 The CI is failing on a warning being treated as error
|
Fixed, I had to wait for tests to finish on another branch before I could switch and fix. |
Can be merged once the CI is green |
* add DataUtility functions to detect service broker and specific databases by name and attributes to use them * change UDT tests to use database detection fact for UDTTestDatabase * change service broker tests to use conditional fact * add the new attribute files to the project * address feedback * remember to open connection before running query * address feedback * fixup IsServiceBrokerEnabled * remove IsServiceBrokerEnabled * re-enabled tests * remove unused variable
* add DataUtility functions to detect service broker and specific databases by name and attributes to use them * change UDT tests to use database detection fact for UDTTestDatabase * change service broker tests to use conditional fact * add the new attribute files to the project * address feedback * remember to open connection before running query * address feedback * fixup IsServiceBrokerEnabled * remove IsServiceBrokerEnabled * re-enabled tests * remove unused variable Commit migrated from dotnet/corefx@202c98a
This changes to the ManualTests to add conditional facts on Udt and ServiceBroker reliant test cases so they won't run if the resources required aren't present or enabled. Without these changes local test runs have many errors and it can be difficult to see real problems for the noise.
Can a script or bak file for the
UdtTestDb
database be provided by someone who has it? It isn't possible to run a full set of manual tests without it.This PR was split from #33155 and into multiple commits for easier review.
/cc @keeratsingh @afsanehr @saurabh500 @David-Engel