From 6255bd1e6cb5eb85192162b31a4c70d07db383f0 Mon Sep 17 00:00:00 2001 From: Charles Gagnon Date: Mon, 22 Jan 2024 16:24:30 -0800 Subject: [PATCH] Fix xUnit1031 Errors (#1024) --- test/.editorconfig | 4 - .../SqlOutputBindingIntegrationTests.cs | 76 +++++++++---------- 2 files changed, 38 insertions(+), 42 deletions(-) diff --git a/test/.editorconfig b/test/.editorconfig index 173fa7c2..513daeea 100644 --- a/test/.editorconfig +++ b/test/.editorconfig @@ -2,10 +2,6 @@ [*.cs] -# xUnit1031: Do not use blocking task operations in test method -# Temporary - will be fixed and set back to error -dotnet_diagnostic.xUnit1031.severity = none - # Disabled dotnet_diagnostic.CA1309.severity = silent # Use ordinal StringComparison - this isn't important for tests and just adds clutter dotnet_diagnostic.CA1305.severity = silent # Specify IFormatProvider - this isn't important for tests and just adds clutter diff --git a/test/Integration/SqlOutputBindingIntegrationTests.cs b/test/Integration/SqlOutputBindingIntegrationTests.cs index 8ed34409..27dbe35e 100644 --- a/test/Integration/SqlOutputBindingIntegrationTests.cs +++ b/test/Integration/SqlOutputBindingIntegrationTests.cs @@ -28,7 +28,7 @@ public SqlOutputBindingIntegrationTests(ITestOutputHelper output) : base(output) [SqlInlineData(1, "Test", 5)] [SqlInlineData(0, "", 0)] [SqlInlineData(-500, "ABCD", 580)] - public void AddProductTest(int id, string name, int cost, SupportedLanguages lang) + public async Task AddProductTest(int id, string name, int cost, SupportedLanguages lang) { var query = new Dictionary() { @@ -37,7 +37,7 @@ public void AddProductTest(int id, string name, int cost, SupportedLanguages lan { "Cost", cost } }; - this.SendOutputPostRequest("addproduct", Utils.JsonSerializeObject(query), TestUtils.GetPort(lang)).Wait(); + await this.SendOutputPostRequest("addproduct", Utils.JsonSerializeObject(query), TestUtils.GetPort(lang)); // Verify result Assert.Equal(name, this.ExecuteScalar($"select Name from Products where ProductId={id}")); @@ -51,7 +51,7 @@ public void AddProductTest(int id, string name, int cost, SupportedLanguages lan // Currently Java functions return null when the parameter for name is an empty string // Issue link: https://github.com/Azure/azure-functions-sql-extension/issues/517 [UnsupportedLanguages(SupportedLanguages.Java)] - public void AddProductParamsTest(int id, string name, int cost, SupportedLanguages lang) + public async Task AddProductParamsTest(int id, string name, int cost, SupportedLanguages lang) { var query = new Dictionary() { @@ -60,7 +60,7 @@ public void AddProductParamsTest(int id, string name, int cost, SupportedLanguag { "cost", cost.ToString() } }; - this.SendOutputGetRequest("addproduct-params", query, TestUtils.GetPort(lang)).Wait(); + await this.SendOutputGetRequest("addproduct-params", query, TestUtils.GetPort(lang)); // Verify result Assert.Equal(name, this.ExecuteScalar($"select Name from Products where ProductId={id}")); @@ -69,7 +69,7 @@ public void AddProductParamsTest(int id, string name, int cost, SupportedLanguag [Theory] [SqlInlineData()] - public void AddProductArrayTest(SupportedLanguages lang) + public async Task AddProductArrayTest(SupportedLanguages lang) { // First insert some test data this.ExecuteNonQuery("INSERT INTO Products VALUES (1, 'test', 100)"); @@ -92,7 +92,7 @@ public void AddProductArrayTest(SupportedLanguages lang) } }; - this.SendOutputPostRequest("addproducts-array", Utils.JsonSerializeObject(prods), TestUtils.GetPort(lang)).Wait(); + await this.SendOutputPostRequest("addproducts-array", Utils.JsonSerializeObject(prods), TestUtils.GetPort(lang)); // Function call changes first 2 rows to (1, 'Cup', 2) and (2, 'Glasses', 12) Assert.Equal(1, this.ExecuteScalar("SELECT COUNT(1) FROM Products WHERE Cost = 100")); @@ -107,14 +107,14 @@ public void AddProductArrayTest(SupportedLanguages lang) /// The language to run the test against [Theory] [SqlInlineData()] - public void AddProductColumnTypesTest(SupportedLanguages lang) + public async Task AddProductColumnTypesTest(SupportedLanguages lang) { var queryParameters = new Dictionary() { { "productId", "999" } }; - this.SendOutputGetRequest("addproduct-columntypes", queryParameters, TestUtils.GetPort(lang, true)).Wait(); + await this.SendOutputGetRequest("addproduct-columntypes", queryParameters, TestUtils.GetPort(lang, true)); // If we get here then the test is successful - an exception will be thrown if there were any problems } @@ -122,26 +122,26 @@ public void AddProductColumnTypesTest(SupportedLanguages lang) [Theory] [SqlInlineData()] [UnsupportedLanguages(SupportedLanguages.JavaScript, SupportedLanguages.PowerShell, SupportedLanguages.Java, SupportedLanguages.OutOfProc, SupportedLanguages.Python)] // Collectors are only available in C# - public void AddProductsCollectorTest(SupportedLanguages lang) + public async Task AddProductsCollectorTest(SupportedLanguages lang) { this.StartFunctionHost(nameof(AddProductsCollector), lang); // Function should add 5000 rows to the table - this.SendOutputGetRequest("addproducts-collector").Wait(); + await this.SendOutputGetRequest("addproducts-collector"); Assert.Equal(5000, this.ExecuteScalar("SELECT COUNT(1) FROM Products")); } [Theory] [SqlInlineData()] - public void QueueTriggerProductsTest(SupportedLanguages lang) + public async Task QueueTriggerProductsTest(SupportedLanguages lang) { this.StartFunctionHost(nameof(QueueTriggerProducts), lang); string uri = $"http://localhost:{TestUtils.DefaultPort}/admin/functions/QueueTriggerProducts"; string json = /*lang=json*/ "{ 'input': 'Test Data' }"; - this.SendPostRequest(uri, json).Wait(); + await this.SendPostRequest(uri, json); Thread.Sleep(5000); @@ -175,11 +175,11 @@ public void AddProductExtraColumnsTest(SupportedLanguages lang) [Theory] [SqlInlineData()] - public void AddProductMissingColumnsTest(SupportedLanguages lang) + public async Task AddProductMissingColumnsTest(SupportedLanguages lang) { // Even though the ProductMissingColumns object is missing the Cost column, // the row should still be added successfully since Cost can be null. - this.SendOutputPostRequest("addproduct-missingcolumns", "", TestUtils.GetPort(lang, true)).Wait(); + await this.SendOutputPostRequest("addproduct-missingcolumns", "", TestUtils.GetPort(lang, true)); Assert.Equal(1, this.ExecuteScalar("SELECT COUNT(*) FROM Products")); } @@ -206,7 +206,7 @@ public void AddProductNoPartialUpsertTest(SupportedLanguages lang) /// [Theory] [SqlInlineData()] - public void AddProductWithIdentity(SupportedLanguages lang) + public async Task AddProductWithIdentity(SupportedLanguages lang) { this.StartFunctionHost(nameof(AddProductWithIdentityColumn), lang); @@ -217,7 +217,7 @@ public void AddProductWithIdentity(SupportedLanguages lang) { "cost", "1" } }; Assert.Equal(0, this.ExecuteScalar("SELECT COUNT(*) FROM dbo.ProductsWithIdentity")); - this.SendOutputGetRequest("addproductwithidentitycolumn", query).Wait(); + await this.SendOutputGetRequest("addproductwithidentitycolumn", query); // Product should have been inserted correctly even without an ID when there's an identity column present Assert.Equal(1, this.ExecuteScalar("SELECT COUNT(*) FROM dbo.ProductsWithIdentity")); } @@ -227,12 +227,12 @@ public void AddProductWithIdentity(SupportedLanguages lang) /// [Theory] [SqlInlineData()] - public void AddProductsWithIdentityColumnArray(SupportedLanguages lang) + public async Task AddProductsWithIdentityColumnArray(SupportedLanguages lang) { this.StartFunctionHost(nameof(AddProductsWithIdentityColumnArray), lang); Assert.Equal(0, this.ExecuteScalar("SELECT COUNT(*) FROM dbo.ProductsWithIdentity")); - this.SendOutputGetRequest("addproductswithidentitycolumnarray", null).Wait(); + await this.SendOutputGetRequest("addproductswithidentitycolumnarray", null); // Multiple items should have been inserted Assert.Equal(2, this.ExecuteScalar("SELECT COUNT(*) FROM dbo.ProductsWithIdentity")); } @@ -243,7 +243,7 @@ public void AddProductsWithIdentityColumnArray(SupportedLanguages lang) /// [Theory] [SqlInlineData()] - public void AddProductWithIdentity_MultiplePrimaryColumns(SupportedLanguages lang) + public async Task AddProductWithIdentity_MultiplePrimaryColumns(SupportedLanguages lang) { var query = new Dictionary() { @@ -252,7 +252,7 @@ public void AddProductWithIdentity_MultiplePrimaryColumns(SupportedLanguages lan { "cost", "1" } }; Assert.Equal(0, this.ExecuteScalar("SELECT COUNT(*) FROM dbo.ProductsWithMultiplePrimaryColumnsAndIdentity")); - this.SendOutputGetRequest("addproductwithmultipleprimarycolumnsandidentity", query, TestUtils.GetPort(lang)).Wait(); + await this.SendOutputGetRequest("addproductwithmultipleprimarycolumnsandidentity", query, TestUtils.GetPort(lang)); // Product should have been inserted correctly even without an ID when there's an identity column present Assert.Equal(1, this.ExecuteScalar("SELECT COUNT(*) FROM dbo.ProductsWithMultiplePrimaryColumnsAndIdentity")); } @@ -263,7 +263,7 @@ public void AddProductWithIdentity_MultiplePrimaryColumns(SupportedLanguages lan /// [Theory] [SqlInlineData()] - public void AddProductWithIdentity_SpecifyIdentityColumn(SupportedLanguages lang) + public async Task AddProductWithIdentity_SpecifyIdentityColumn(SupportedLanguages lang) { this.StartFunctionHost(nameof(AddProductWithIdentityColumnIncluded), lang); var query = new Dictionary() @@ -273,7 +273,7 @@ public void AddProductWithIdentity_SpecifyIdentityColumn(SupportedLanguages lang { "cost", "1" } }; Assert.Equal(0, this.ExecuteScalar("SELECT COUNT(*) FROM dbo.ProductsWithIdentity")); - this.SendOutputGetRequest(nameof(AddProductWithIdentityColumnIncluded), query).Wait(); + await this.SendOutputGetRequest(nameof(AddProductWithIdentityColumnIncluded), query); // New row should have been inserted Assert.Equal(1, this.ExecuteScalar("SELECT COUNT(*) FROM dbo.ProductsWithIdentity")); query = new Dictionary() @@ -282,7 +282,7 @@ public void AddProductWithIdentity_SpecifyIdentityColumn(SupportedLanguages lang { "name", "MyProduct2" }, { "cost", "1" } }; - this.SendOutputGetRequest(nameof(AddProductWithIdentityColumnIncluded), query).Wait(); + await this.SendOutputGetRequest(nameof(AddProductWithIdentityColumnIncluded), query); // Existing row should have been updated Assert.Equal(1, this.ExecuteScalar("SELECT COUNT(*) FROM dbo.ProductsWithIdentity")); Assert.Equal(1, this.ExecuteScalar("SELECT COUNT(*) FROM dbo.ProductsWithIdentity WHERE Name='MyProduct2'")); @@ -293,7 +293,7 @@ public void AddProductWithIdentity_SpecifyIdentityColumn(SupportedLanguages lang /// [Theory] [SqlInlineData()] - public void AddProductWithIdentity_NoIdentityColumn(SupportedLanguages lang) + public async Task AddProductWithIdentity_NoIdentityColumn(SupportedLanguages lang) { this.StartFunctionHost(nameof(AddProductWithIdentityColumnIncluded), lang); var query = new Dictionary() @@ -302,7 +302,7 @@ public void AddProductWithIdentity_NoIdentityColumn(SupportedLanguages lang) { "cost", "1" } }; Assert.Equal(0, this.ExecuteScalar("SELECT COUNT(*) FROM dbo.ProductsWithIdentity")); - this.SendOutputGetRequest(nameof(AddProductWithIdentityColumnIncluded), query).Wait(); + await this.SendOutputGetRequest(nameof(AddProductWithIdentityColumnIncluded), query); // New row should have been inserted Assert.Equal(1, this.ExecuteScalar("SELECT COUNT(*) FROM dbo.ProductsWithIdentity")); query = new Dictionary() @@ -310,7 +310,7 @@ public void AddProductWithIdentity_NoIdentityColumn(SupportedLanguages lang) { "name", "MyProduct2" }, { "cost", "1" } }; - this.SendOutputGetRequest(nameof(AddProductWithIdentityColumnIncluded), query).Wait(); + await this.SendOutputGetRequest(nameof(AddProductWithIdentityColumnIncluded), query); // Another new row should have been inserted Assert.Equal(2, this.ExecuteScalar("SELECT COUNT(*) FROM dbo.ProductsWithIdentity")); } @@ -341,7 +341,7 @@ public void AddProductWithIdentity_MissingPrimaryColumn(SupportedLanguages lang) /// [Theory] [SqlInlineData()] - public void AddProductWithDefaultPKTest(SupportedLanguages lang) + public async Task AddProductWithDefaultPKTest(SupportedLanguages lang) { var product = new Dictionary() { @@ -349,8 +349,8 @@ public void AddProductWithDefaultPKTest(SupportedLanguages lang) { "Cost", 1 } }; Assert.Equal(0, this.ExecuteScalar("SELECT COUNT(*) FROM dbo.ProductsWithDefaultPK")); - this.SendOutputPostRequest("addproductwithdefaultpk", Utils.JsonSerializeObject(product), TestUtils.GetPort(lang)).Wait(); - this.SendOutputPostRequest("addproductwithdefaultpk", Utils.JsonSerializeObject(product), TestUtils.GetPort(lang)).Wait(); + await this.SendOutputPostRequest("addproductwithdefaultpk", Utils.JsonSerializeObject(product), TestUtils.GetPort(lang)); + await this.SendOutputPostRequest("addproductwithdefaultpk", Utils.JsonSerializeObject(product), TestUtils.GetPort(lang)); Assert.Equal(2, this.ExecuteScalar("SELECT COUNT(*) FROM dbo.ProductsWithDefaultPK")); } @@ -359,7 +359,7 @@ public void AddProductWithDefaultPKTest(SupportedLanguages lang) /// [Theory] [SqlInlineData()] - public void QueryTypeCachingRegressionTest(SupportedLanguages lang) + public async Task QueryTypeCachingRegressionTest(SupportedLanguages lang) { // Start off by inserting an item into the database, which we'll update later this.ExecuteNonQuery("INSERT INTO Products VALUES (1, 'test', 100)"); @@ -376,7 +376,7 @@ public void QueryTypeCachingRegressionTest(SupportedLanguages lang) { "Cost", 100 } }; // Now send an output request that we expect to succeed - specifically one that will result in an update so requires the MERGE statement - this.SendOutputPostRequest("addproduct", Utils.JsonSerializeObject(productWithPrimaryKey), TestUtils.GetPort(lang)).Wait(); + await this.SendOutputPostRequest("addproduct", Utils.JsonSerializeObject(productWithPrimaryKey), TestUtils.GetPort(lang)); Assert.True(1 == (int)this.ExecuteScalar("SELECT COUNT(*) FROM dbo.Products"), "There should be one item at the end"); } @@ -422,7 +422,7 @@ public async Task UnsupportedDatabaseThrows(SupportedLanguages lang) /// [Theory] [SqlInlineData()] - public void AddProductToCaseSensitiveDatabase(SupportedLanguages lang) + public async Task AddProductToCaseSensitiveDatabase(SupportedLanguages lang) { // Change database collation to case sensitive this.ExecuteNonQuery($"ALTER DATABASE {this.DatabaseName} SET Single_User WITH ROLLBACK IMMEDIATE; ALTER DATABASE {this.DatabaseName} COLLATE Latin1_General_CS_AS; ALTER DATABASE {this.DatabaseName} SET Multi_User;"); @@ -438,7 +438,7 @@ public void AddProductToCaseSensitiveDatabase(SupportedLanguages lang) { "Cost", 100 } }; - this.SendOutputPostRequest("addproduct", Utils.JsonSerializeObject(query), TestUtils.GetPort(lang)).Wait(); + await this.SendOutputPostRequest("addproduct", Utils.JsonSerializeObject(query), TestUtils.GetPort(lang)); // Verify result Assert.Equal("test", this.ExecuteScalar($"select Name from Products where ProductId=0")); @@ -465,7 +465,7 @@ public void AddProductIncorrectCasing(SupportedLanguages lang) /// [Theory] [SqlInlineData()] - public void AddProductWithDifferentPropertiesTest(SupportedLanguages lang) + public async Task AddProductWithDifferentPropertiesTest(SupportedLanguages lang) { var query1 = new Dictionary() { @@ -480,8 +480,8 @@ public void AddProductWithDifferentPropertiesTest(SupportedLanguages lang) { "Name", "test2" } }; - this.SendOutputPostRequest("addproduct", Utils.JsonSerializeObject(query1), TestUtils.GetPort(lang)).Wait(); - this.SendOutputPostRequest("addproduct", Utils.JsonSerializeObject(query2), TestUtils.GetPort(lang)).Wait(); + await this.SendOutputPostRequest("addproduct", Utils.JsonSerializeObject(query1), TestUtils.GetPort(lang)); + await this.SendOutputPostRequest("addproduct", Utils.JsonSerializeObject(query2), TestUtils.GetPort(lang)); // Verify result Assert.Equal("test2", this.ExecuteScalar($"select Name from Products where ProductId=0")); @@ -543,10 +543,10 @@ public async Task AddProductUnsupportedTypesTest(SupportedLanguages lang) /// [Theory] [SqlInlineData()] - public void AddProductDefaultPKAndDifferentColumnOrderTest(SupportedLanguages lang) + public async Task AddProductDefaultPKAndDifferentColumnOrderTest(SupportedLanguages lang) { Assert.Equal(0, this.ExecuteScalar("SELECT COUNT(*) FROM dbo.ProductsWithDefaultPK")); - this.SendOutputGetRequest("addproductdefaultpkanddifferentcolumnorder", null, TestUtils.GetPort(lang, true)).Wait(); + await this.SendOutputGetRequest("addproductdefaultpkanddifferentcolumnorder", null, TestUtils.GetPort(lang, true)); Assert.Equal(1, this.ExecuteScalar("SELECT COUNT(*) FROM dbo.ProductsWithDefaultPK")); } }