Skip to content

Commit 2dcfca5

Browse files
Fix xUnit1031 Errors (#1024)
1 parent 781c2f6 commit 2dcfca5

File tree

2 files changed

+38
-42
lines changed

2 files changed

+38
-42
lines changed

test/.editorconfig

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22

33
[*.cs]
44

5-
# xUnit1031: Do not use blocking task operations in test method
6-
# Temporary - will be fixed and set back to error
7-
dotnet_diagnostic.xUnit1031.severity = none
8-
95
# Disabled
106
dotnet_diagnostic.CA1309.severity = silent # Use ordinal StringComparison - this isn't important for tests and just adds clutter
117
dotnet_diagnostic.CA1305.severity = silent # Specify IFormatProvider - this isn't important for tests and just adds clutter

test/Integration/SqlOutputBindingIntegrationTests.cs

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public SqlOutputBindingIntegrationTests(ITestOutputHelper output) : base(output)
2828
[SqlInlineData(1, "Test", 5)]
2929
[SqlInlineData(0, "", 0)]
3030
[SqlInlineData(-500, "ABCD", 580)]
31-
public void AddProductTest(int id, string name, int cost, SupportedLanguages lang)
31+
public async Task AddProductTest(int id, string name, int cost, SupportedLanguages lang)
3232
{
3333
var query = new Dictionary<string, object>()
3434
{
@@ -37,7 +37,7 @@ public void AddProductTest(int id, string name, int cost, SupportedLanguages lan
3737
{ "Cost", cost }
3838
};
3939

40-
this.SendOutputPostRequest("addproduct", Utils.JsonSerializeObject(query), TestUtils.GetPort(lang)).Wait();
40+
await this.SendOutputPostRequest("addproduct", Utils.JsonSerializeObject(query), TestUtils.GetPort(lang));
4141

4242
// Verify result
4343
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
5151
// Currently Java functions return null when the parameter for name is an empty string
5252
// Issue link: https://github.com/Azure/azure-functions-sql-extension/issues/517
5353
[UnsupportedLanguages(SupportedLanguages.Java)]
54-
public void AddProductParamsTest(int id, string name, int cost, SupportedLanguages lang)
54+
public async Task AddProductParamsTest(int id, string name, int cost, SupportedLanguages lang)
5555
{
5656
var query = new Dictionary<string, string>()
5757
{
@@ -60,7 +60,7 @@ public void AddProductParamsTest(int id, string name, int cost, SupportedLanguag
6060
{ "cost", cost.ToString() }
6161
};
6262

63-
this.SendOutputGetRequest("addproduct-params", query, TestUtils.GetPort(lang)).Wait();
63+
await this.SendOutputGetRequest("addproduct-params", query, TestUtils.GetPort(lang));
6464

6565
// Verify result
6666
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
6969

7070
[Theory]
7171
[SqlInlineData()]
72-
public void AddProductArrayTest(SupportedLanguages lang)
72+
public async Task AddProductArrayTest(SupportedLanguages lang)
7373
{
7474
// First insert some test data
7575
this.ExecuteNonQuery("INSERT INTO Products VALUES (1, 'test', 100)");
@@ -92,7 +92,7 @@ public void AddProductArrayTest(SupportedLanguages lang)
9292
}
9393
};
9494

95-
this.SendOutputPostRequest("addproducts-array", Utils.JsonSerializeObject(prods), TestUtils.GetPort(lang)).Wait();
95+
await this.SendOutputPostRequest("addproducts-array", Utils.JsonSerializeObject(prods), TestUtils.GetPort(lang));
9696

9797
// Function call changes first 2 rows to (1, 'Cup', 2) and (2, 'Glasses', 12)
9898
Assert.Equal(1, this.ExecuteScalar("SELECT COUNT(1) FROM Products WHERE Cost = 100"));
@@ -107,41 +107,41 @@ public void AddProductArrayTest(SupportedLanguages lang)
107107
/// <param name="lang">The language to run the test against</param>
108108
[Theory]
109109
[SqlInlineData()]
110-
public void AddProductColumnTypesTest(SupportedLanguages lang)
110+
public async Task AddProductColumnTypesTest(SupportedLanguages lang)
111111
{
112112
var queryParameters = new Dictionary<string, string>()
113113
{
114114
{ "productId", "999" }
115115
};
116116

117-
this.SendOutputGetRequest("addproduct-columntypes", queryParameters, TestUtils.GetPort(lang, true)).Wait();
117+
await this.SendOutputGetRequest("addproduct-columntypes", queryParameters, TestUtils.GetPort(lang, true));
118118

119119
// If we get here then the test is successful - an exception will be thrown if there were any problems
120120
}
121121

122122
[Theory]
123123
[SqlInlineData()]
124124
[UnsupportedLanguages(SupportedLanguages.JavaScript, SupportedLanguages.PowerShell, SupportedLanguages.Java, SupportedLanguages.OutOfProc, SupportedLanguages.Python)] // Collectors are only available in C#
125-
public void AddProductsCollectorTest(SupportedLanguages lang)
125+
public async Task AddProductsCollectorTest(SupportedLanguages lang)
126126
{
127127
this.StartFunctionHost(nameof(AddProductsCollector), lang);
128128

129129
// Function should add 5000 rows to the table
130-
this.SendOutputGetRequest("addproducts-collector").Wait();
130+
await this.SendOutputGetRequest("addproducts-collector");
131131

132132
Assert.Equal(5000, this.ExecuteScalar("SELECT COUNT(1) FROM Products"));
133133
}
134134

135135
[Theory]
136136
[SqlInlineData()]
137-
public void QueueTriggerProductsTest(SupportedLanguages lang)
137+
public async Task QueueTriggerProductsTest(SupportedLanguages lang)
138138
{
139139
this.StartFunctionHost(nameof(QueueTriggerProducts), lang);
140140

141141
string uri = $"http://localhost:{TestUtils.DefaultPort}/admin/functions/QueueTriggerProducts";
142142
string json = /*lang=json*/ "{ 'input': 'Test Data' }";
143143

144-
this.SendPostRequest(uri, json).Wait();
144+
await this.SendPostRequest(uri, json);
145145

146146
Thread.Sleep(5000);
147147

@@ -175,11 +175,11 @@ public void AddProductExtraColumnsTest(SupportedLanguages lang)
175175

176176
[Theory]
177177
[SqlInlineData()]
178-
public void AddProductMissingColumnsTest(SupportedLanguages lang)
178+
public async Task AddProductMissingColumnsTest(SupportedLanguages lang)
179179
{
180180
// Even though the ProductMissingColumns object is missing the Cost column,
181181
// the row should still be added successfully since Cost can be null.
182-
this.SendOutputPostRequest("addproduct-missingcolumns", "", TestUtils.GetPort(lang, true)).Wait();
182+
await this.SendOutputPostRequest("addproduct-missingcolumns", "", TestUtils.GetPort(lang, true));
183183
Assert.Equal(1, this.ExecuteScalar("SELECT COUNT(*) FROM Products"));
184184
}
185185

@@ -206,7 +206,7 @@ public void AddProductNoPartialUpsertTest(SupportedLanguages lang)
206206
/// </summary>
207207
[Theory]
208208
[SqlInlineData()]
209-
public void AddProductWithIdentity(SupportedLanguages lang)
209+
public async Task AddProductWithIdentity(SupportedLanguages lang)
210210
{
211211
this.StartFunctionHost(nameof(AddProductWithIdentityColumn), lang);
212212

@@ -217,7 +217,7 @@ public void AddProductWithIdentity(SupportedLanguages lang)
217217
{ "cost", "1" }
218218
};
219219
Assert.Equal(0, this.ExecuteScalar("SELECT COUNT(*) FROM dbo.ProductsWithIdentity"));
220-
this.SendOutputGetRequest("addproductwithidentitycolumn", query).Wait();
220+
await this.SendOutputGetRequest("addproductwithidentitycolumn", query);
221221
// Product should have been inserted correctly even without an ID when there's an identity column present
222222
Assert.Equal(1, this.ExecuteScalar("SELECT COUNT(*) FROM dbo.ProductsWithIdentity"));
223223
}
@@ -227,12 +227,12 @@ public void AddProductWithIdentity(SupportedLanguages lang)
227227
/// </summary>
228228
[Theory]
229229
[SqlInlineData()]
230-
public void AddProductsWithIdentityColumnArray(SupportedLanguages lang)
230+
public async Task AddProductsWithIdentityColumnArray(SupportedLanguages lang)
231231
{
232232
this.StartFunctionHost(nameof(AddProductsWithIdentityColumnArray), lang);
233233

234234
Assert.Equal(0, this.ExecuteScalar("SELECT COUNT(*) FROM dbo.ProductsWithIdentity"));
235-
this.SendOutputGetRequest("addproductswithidentitycolumnarray", null).Wait();
235+
await this.SendOutputGetRequest("addproductswithidentitycolumnarray", null);
236236
// Multiple items should have been inserted
237237
Assert.Equal(2, this.ExecuteScalar("SELECT COUNT(*) FROM dbo.ProductsWithIdentity"));
238238
}
@@ -243,7 +243,7 @@ public void AddProductsWithIdentityColumnArray(SupportedLanguages lang)
243243
/// </summary>
244244
[Theory]
245245
[SqlInlineData()]
246-
public void AddProductWithIdentity_MultiplePrimaryColumns(SupportedLanguages lang)
246+
public async Task AddProductWithIdentity_MultiplePrimaryColumns(SupportedLanguages lang)
247247
{
248248
var query = new Dictionary<string, string>()
249249
{
@@ -252,7 +252,7 @@ public void AddProductWithIdentity_MultiplePrimaryColumns(SupportedLanguages lan
252252
{ "cost", "1" }
253253
};
254254
Assert.Equal(0, this.ExecuteScalar("SELECT COUNT(*) FROM dbo.ProductsWithMultiplePrimaryColumnsAndIdentity"));
255-
this.SendOutputGetRequest("addproductwithmultipleprimarycolumnsandidentity", query, TestUtils.GetPort(lang)).Wait();
255+
await this.SendOutputGetRequest("addproductwithmultipleprimarycolumnsandidentity", query, TestUtils.GetPort(lang));
256256
// Product should have been inserted correctly even without an ID when there's an identity column present
257257
Assert.Equal(1, this.ExecuteScalar("SELECT COUNT(*) FROM dbo.ProductsWithMultiplePrimaryColumnsAndIdentity"));
258258
}
@@ -263,7 +263,7 @@ public void AddProductWithIdentity_MultiplePrimaryColumns(SupportedLanguages lan
263263
/// </summary>
264264
[Theory]
265265
[SqlInlineData()]
266-
public void AddProductWithIdentity_SpecifyIdentityColumn(SupportedLanguages lang)
266+
public async Task AddProductWithIdentity_SpecifyIdentityColumn(SupportedLanguages lang)
267267
{
268268
this.StartFunctionHost(nameof(AddProductWithIdentityColumnIncluded), lang);
269269
var query = new Dictionary<string, string>()
@@ -273,7 +273,7 @@ public void AddProductWithIdentity_SpecifyIdentityColumn(SupportedLanguages lang
273273
{ "cost", "1" }
274274
};
275275
Assert.Equal(0, this.ExecuteScalar("SELECT COUNT(*) FROM dbo.ProductsWithIdentity"));
276-
this.SendOutputGetRequest(nameof(AddProductWithIdentityColumnIncluded), query).Wait();
276+
await this.SendOutputGetRequest(nameof(AddProductWithIdentityColumnIncluded), query);
277277
// New row should have been inserted
278278
Assert.Equal(1, this.ExecuteScalar("SELECT COUNT(*) FROM dbo.ProductsWithIdentity"));
279279
query = new Dictionary<string, string>()
@@ -282,7 +282,7 @@ public void AddProductWithIdentity_SpecifyIdentityColumn(SupportedLanguages lang
282282
{ "name", "MyProduct2" },
283283
{ "cost", "1" }
284284
};
285-
this.SendOutputGetRequest(nameof(AddProductWithIdentityColumnIncluded), query).Wait();
285+
await this.SendOutputGetRequest(nameof(AddProductWithIdentityColumnIncluded), query);
286286
// Existing row should have been updated
287287
Assert.Equal(1, this.ExecuteScalar("SELECT COUNT(*) FROM dbo.ProductsWithIdentity"));
288288
Assert.Equal(1, this.ExecuteScalar("SELECT COUNT(*) FROM dbo.ProductsWithIdentity WHERE Name='MyProduct2'"));
@@ -293,7 +293,7 @@ public void AddProductWithIdentity_SpecifyIdentityColumn(SupportedLanguages lang
293293
/// </summary>
294294
[Theory]
295295
[SqlInlineData()]
296-
public void AddProductWithIdentity_NoIdentityColumn(SupportedLanguages lang)
296+
public async Task AddProductWithIdentity_NoIdentityColumn(SupportedLanguages lang)
297297
{
298298
this.StartFunctionHost(nameof(AddProductWithIdentityColumnIncluded), lang);
299299
var query = new Dictionary<string, string>()
@@ -302,15 +302,15 @@ public void AddProductWithIdentity_NoIdentityColumn(SupportedLanguages lang)
302302
{ "cost", "1" }
303303
};
304304
Assert.Equal(0, this.ExecuteScalar("SELECT COUNT(*) FROM dbo.ProductsWithIdentity"));
305-
this.SendOutputGetRequest(nameof(AddProductWithIdentityColumnIncluded), query).Wait();
305+
await this.SendOutputGetRequest(nameof(AddProductWithIdentityColumnIncluded), query);
306306
// New row should have been inserted
307307
Assert.Equal(1, this.ExecuteScalar("SELECT COUNT(*) FROM dbo.ProductsWithIdentity"));
308308
query = new Dictionary<string, string>()
309309
{
310310
{ "name", "MyProduct2" },
311311
{ "cost", "1" }
312312
};
313-
this.SendOutputGetRequest(nameof(AddProductWithIdentityColumnIncluded), query).Wait();
313+
await this.SendOutputGetRequest(nameof(AddProductWithIdentityColumnIncluded), query);
314314
// Another new row should have been inserted
315315
Assert.Equal(2, this.ExecuteScalar("SELECT COUNT(*) FROM dbo.ProductsWithIdentity"));
316316
}
@@ -341,16 +341,16 @@ public void AddProductWithIdentity_MissingPrimaryColumn(SupportedLanguages lang)
341341
/// </summary>
342342
[Theory]
343343
[SqlInlineData()]
344-
public void AddProductWithDefaultPKTest(SupportedLanguages lang)
344+
public async Task AddProductWithDefaultPKTest(SupportedLanguages lang)
345345
{
346346
var product = new Dictionary<string, object>()
347347
{
348348
{ "Name", "MyProduct" },
349349
{ "Cost", 1 }
350350
};
351351
Assert.Equal(0, this.ExecuteScalar("SELECT COUNT(*) FROM dbo.ProductsWithDefaultPK"));
352-
this.SendOutputPostRequest("addproductwithdefaultpk", Utils.JsonSerializeObject(product), TestUtils.GetPort(lang)).Wait();
353-
this.SendOutputPostRequest("addproductwithdefaultpk", Utils.JsonSerializeObject(product), TestUtils.GetPort(lang)).Wait();
352+
await this.SendOutputPostRequest("addproductwithdefaultpk", Utils.JsonSerializeObject(product), TestUtils.GetPort(lang));
353+
await this.SendOutputPostRequest("addproductwithdefaultpk", Utils.JsonSerializeObject(product), TestUtils.GetPort(lang));
354354
Assert.Equal(2, this.ExecuteScalar("SELECT COUNT(*) FROM dbo.ProductsWithDefaultPK"));
355355
}
356356

@@ -359,7 +359,7 @@ public void AddProductWithDefaultPKTest(SupportedLanguages lang)
359359
/// </summary>
360360
[Theory]
361361
[SqlInlineData()]
362-
public void QueryTypeCachingRegressionTest(SupportedLanguages lang)
362+
public async Task QueryTypeCachingRegressionTest(SupportedLanguages lang)
363363
{
364364
// Start off by inserting an item into the database, which we'll update later
365365
this.ExecuteNonQuery("INSERT INTO Products VALUES (1, 'test', 100)");
@@ -376,7 +376,7 @@ public void QueryTypeCachingRegressionTest(SupportedLanguages lang)
376376
{ "Cost", 100 }
377377
};
378378
// Now send an output request that we expect to succeed - specifically one that will result in an update so requires the MERGE statement
379-
this.SendOutputPostRequest("addproduct", Utils.JsonSerializeObject(productWithPrimaryKey), TestUtils.GetPort(lang)).Wait();
379+
await this.SendOutputPostRequest("addproduct", Utils.JsonSerializeObject(productWithPrimaryKey), TestUtils.GetPort(lang));
380380
Assert.True(1 == (int)this.ExecuteScalar("SELECT COUNT(*) FROM dbo.Products"), "There should be one item at the end");
381381
}
382382

@@ -422,7 +422,7 @@ public async Task UnsupportedDatabaseThrows(SupportedLanguages lang)
422422
/// </summary>
423423
[Theory]
424424
[SqlInlineData()]
425-
public void AddProductToCaseSensitiveDatabase(SupportedLanguages lang)
425+
public async Task AddProductToCaseSensitiveDatabase(SupportedLanguages lang)
426426
{
427427
// Change database collation to case sensitive
428428
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)
438438
{ "Cost", 100 }
439439
};
440440

441-
this.SendOutputPostRequest("addproduct", Utils.JsonSerializeObject(query), TestUtils.GetPort(lang)).Wait();
441+
await this.SendOutputPostRequest("addproduct", Utils.JsonSerializeObject(query), TestUtils.GetPort(lang));
442442

443443
// Verify result
444444
Assert.Equal("test", this.ExecuteScalar($"select Name from Products where ProductId=0"));
@@ -465,7 +465,7 @@ public void AddProductIncorrectCasing(SupportedLanguages lang)
465465
/// </summary>
466466
[Theory]
467467
[SqlInlineData()]
468-
public void AddProductWithDifferentPropertiesTest(SupportedLanguages lang)
468+
public async Task AddProductWithDifferentPropertiesTest(SupportedLanguages lang)
469469
{
470470
var query1 = new Dictionary<string, object>()
471471
{
@@ -480,8 +480,8 @@ public void AddProductWithDifferentPropertiesTest(SupportedLanguages lang)
480480
{ "Name", "test2" }
481481
};
482482

483-
this.SendOutputPostRequest("addproduct", Utils.JsonSerializeObject(query1), TestUtils.GetPort(lang)).Wait();
484-
this.SendOutputPostRequest("addproduct", Utils.JsonSerializeObject(query2), TestUtils.GetPort(lang)).Wait();
483+
await this.SendOutputPostRequest("addproduct", Utils.JsonSerializeObject(query1), TestUtils.GetPort(lang));
484+
await this.SendOutputPostRequest("addproduct", Utils.JsonSerializeObject(query2), TestUtils.GetPort(lang));
485485

486486
// Verify result
487487
Assert.Equal("test2", this.ExecuteScalar($"select Name from Products where ProductId=0"));
@@ -543,10 +543,10 @@ public async Task AddProductUnsupportedTypesTest(SupportedLanguages lang)
543543
/// </summary>
544544
[Theory]
545545
[SqlInlineData()]
546-
public void AddProductDefaultPKAndDifferentColumnOrderTest(SupportedLanguages lang)
546+
public async Task AddProductDefaultPKAndDifferentColumnOrderTest(SupportedLanguages lang)
547547
{
548548
Assert.Equal(0, this.ExecuteScalar("SELECT COUNT(*) FROM dbo.ProductsWithDefaultPK"));
549-
this.SendOutputGetRequest("addproductdefaultpkanddifferentcolumnorder", null, TestUtils.GetPort(lang, true)).Wait();
549+
await this.SendOutputGetRequest("addproductdefaultpkanddifferentcolumnorder", null, TestUtils.GetPort(lang, true));
550550
Assert.Equal(1, this.ExecuteScalar("SELECT COUNT(*) FROM dbo.ProductsWithDefaultPK"));
551551
}
552552
}

0 commit comments

Comments
 (0)