Fix/issue 826 support cross thread minimal api (#827)

* remove repository global variable to suuport muliple thread (call by handle method)

* add parallel call tests

Co-authored-by: cedri <cedri@BAS>
This commit is contained in:
Cédric Michel
2022-12-20 04:24:46 +01:00
committed by GitHub
parent a72dd775ee
commit 707f8696f9
8 changed files with 64 additions and 54 deletions

View File

@@ -2,7 +2,10 @@
using Microsoft.eShopWeb.PublicApi.CatalogItemEndpoints;
using Microsoft.eShopWeb.Web.ViewModels;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net;
using System.Threading.Tasks;
namespace PublicApiIntegrationTests.CatalogItemEndpoints
@@ -45,5 +48,26 @@ namespace PublicApiIntegrationTests.CatalogItemEndpoints
Assert.AreEqual(totalExpected, model2.CatalogItems.Count());
}
[DataTestMethod]
[DataRow("catalog-items")]
[DataRow("catalog-brands")]
[DataRow("catalog-types")]
[DataRow("catalog-items/1")]
public async Task SuccessFullMutipleParallelCall(string endpointName)
{
var client = ProgramTest.NewClient;
var tasks = new List<Task<HttpResponseMessage>>();
for (int i = 0; i < 100; i++)
{
var task = client.GetAsync($"/api/{endpointName}");
tasks.Add(task);
}
await Task.WhenAll(tasks.ToList());
var totalKO = tasks.Count(t => t.Result.StatusCode != HttpStatusCode.OK);
Assert.AreEqual(0, totalKO);
}
}
}