Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Update SqlClient manual test feature detection #34040

Merged
merged 11 commits into from
Dec 15, 2018

Conversation

Wraith2
Copy link
Contributor

@Wraith2 Wraith2 commented Dec 12, 2018

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

@keeratsingh
Copy link

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.

@Wraith2 This should help you setup the UdtTestDb, let me know if you encounter any issues or have questions.
https://gist.github.com/keeratsingh/d2d222340041569aedb5b892d5e15aad

Copy link
Contributor

@saurabh500 saurabh500 left a 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.

[ConditionalFact(typeof(Helpers), nameof(Helpers.IsElevatedAndCanWriteToPerfCounters))]


namespace System.Data.SqlClient.ManualTesting.Tests
{
public class CheckDatabaseIsPresentFactAttribute : FactAttribute
Copy link
Contributor

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.

Copy link
Contributor

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
Copy link
Contributor

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)
Copy link
Contributor

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>();

@Wraith2
Copy link
Contributor Author

Wraith2 commented Dec 13, 2018

All feedback addressed, new attributes are gone replaced with ConditionalFacts
Would it be ok to add the udt database script to the project next to the readme so others can get to it easily? I'm intending to update the readme with the information I've gathered in another PR later.

@saurabh500
Copy link
Contributor

That's a good idea

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))
Copy link
Contributor

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

Copy link
Contributor

@saurabh500 saurabh500 left a 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.

@Wraith2
Copy link
Contributor Author

Wraith2 commented Dec 14, 2018

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.

@saurabh500
Copy link
Contributor

I looked at the notifications tests, the constructor is supposed to setup the required infra for query notification
https://github.com/dotnet/corefx/blob/master/src/System.Data.SqlClient/tests/ManualTests/SQL/SqlNotificationTest/SqlNotificationTest.cs#L312
Is that not working for you? The check for query notification is not needed.

@saurabh500
Copy link
Contributor

The more I think about this change, I feel you should remove public static bool IsServiceBrokerEnabled from the change along with its usage and update the PR. The rest of it looks good.
I would like to know why Sql Notification tests are failing for you. Setup issue/server configuration etc. Perhaps it warrants an issue where this could be discussed further?

@Wraith2
Copy link
Contributor Author

Wraith2 commented Dec 14, 2018

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.

@saurabh500
Copy link
Contributor

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.
This doesn't look right.
I still think that you should figure out where the setup for the notification tests is failing. The setup doesn't need any external scripts. Its embedded in the test itself.

Right now this is what is happening.

  1. The Service Broker test is doing some the setup.
tring.Format("CREATE TABLE {0}(a INT NOT NULL, b NVARCHAR(10), c INT NOT NULL)", tableName),
                string.Format("INSERT INTO {0} (a, b, c) VALUES (1, 'foo', 0)", tableName),
                string.Format("CREATE QUEUE {0}", queueName),
                string.Format("CREATE SERVICE [{0}] ON QUEUE {1} ([http://schemas.microsoft.com/SQL/Notifications/PostQueryNotification])", serviceName, queueName)
  1. The setup is failing for you
  2. The ConditionalFact returns false for Northwind database's broker enablement
  3. The test is skipped.

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??

@Wraith2
Copy link
Contributor Author

Wraith2 commented Dec 14, 2018

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.

@saurabh500
Copy link
Contributor

saurabh500 commented Dec 14, 2018

The tests run and pass as of the fix I pushed this morning.

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 IsServiceBrokerEnabled now?

@Wraith2
Copy link
Contributor Author

Wraith2 commented Dec 14, 2018

Ok, shall I leave the utility function in DataTestUtility in case someone else needs it or get rid of everything?

@saurabh500
Copy link
Contributor

You should get rid of everything related to IsServiceBrokerEnabled including the implementation. The lesser the code, the better.

@Wraith2
Copy link
Contributor Author

Wraith2 commented Dec 14, 2018

Done.

@@ -21,6 +25,10 @@ public static class DataTestUtility
".database.cloudapi.de",
".database.usgovcloudapi.net",
".database.chinacloudapi.cn"};

private static bool? serviceBrokerEnabled;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed anymore.

@saurabh500
Copy link
Contributor

saurabh500 commented Dec 14, 2018

@Wraith2 The CI is failing on a warning being treated as error

D:\j\workspace\windows-TGrou---f8ac6754\src\System.Data.SqlClient\tests\ManualTests\DataCommon\DataTestUtility.cs(29,30): error CS0169: The field 'DataTestUtility.serviceBrokerEnabled' is never used [D:\j\workspace\windows-TGrou---f8ac6754\src\System.Data.SqlClient\tests\FunctionalTests\System.Data.SqlClient.Tests.csproj]

@Wraith2
Copy link
Contributor Author

Wraith2 commented Dec 14, 2018

Fixed, I had to wait for tests to finish on another branch before I could switch and fix.

@saurabh500
Copy link
Contributor

Can be merged once the CI is green

@saurabh500 saurabh500 merged commit 202c98a into dotnet:master Dec 15, 2018
@Wraith2 Wraith2 deleted the sqltest-manualskips branch December 15, 2018 11:26
jlennox pushed a commit to jlennox/corefx that referenced this pull request Dec 16, 2018
* 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
@karelz karelz added this to the 3.0 milestone Dec 21, 2018
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
* 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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants