Skip to content

Commit

Permalink
add memory leak tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali-YousefiTelori committed Sep 28, 2023
1 parent eafae23 commit df54946
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
using CodeReviewer.Engine;
using EasyMicroservices.ContentsMicroservice.Contracts.Common;
using EasyMicroservices.ContentsMicroservice.Database.Entities;
using EasyMicroservices.ContentsMicroservice.Helpers;
using EasyMicroservices.ContentsMicroservice.WebApi.Controllers;
using EasyMicroservices.Tests;
using System;
using System.IO;
using System.Linq;

namespace EasyMicroservices.ContentsMicroservice.Tests
{
Expand All @@ -16,8 +12,8 @@ static CodeReviewerCheckTests()
{
//types to check (this will check all of types in assembly so no need to add all of types of assembly)
AssemblyManager.AddAssemblyToReview(
typeof(ApplicationManager),
typeof(StartUp),
typeof(DatabaseBuilder),
//typeof(CompileTimeClassesMappers),
typeof(CategoryEntity),
typeof(CategoryContract),
typeof(CategoryController));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
using EasyMicroservices.ContentsMicroservice.Contracts.Common;
using EasyMicroservices.ContentsMicroservice.Contracts.Requests;
using EasyMicroservices.ContentsMicroservice.Database.Contexts;
using EasyMicroservices.ContentsMicroservice.Database.Entities;
using EasyMicroservices.ContentsMicroservice.WebApi.Controllers;
using EasyMicroservices.Cores.AspEntityFrameworkCoreApi;
using EasyMicroservices.Cores.AspEntityFrameworkCoreApi.Interfaces;
using EasyMicroservices.Cores.Relational.EntityFrameworkCore;
using EasyMicroservices.Cores.Relational.EntityFrameworkCore.Intrerfaces;
using Microsoft.AspNetCore.Mvc.ApplicationParts;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.Threading.Tasks;

namespace EasyMicroservices.ContentsMicroservice.Tests
{
public class ContentMemoryLeakTest
{
static bool IsStarted = false;

static async Task StartServer()
{
if (IsStarted)
return;
IsStarted = true;
_ = Task.Run(async () =>
{
await EasyMicroservices.ContentsMicroservice.WebApi.Program.Run(null, (s) =>
{
s.AddControllers().PartManager.ApplicationParts.Add(new AssemblyPart(typeof(CategoryController).Assembly));
});
});
await Task.Delay(2000);
}

//[Fact]
//public async Task CheckMemoryLeakAddContentTest()
//{
// await StartServer();
// Contents.GeneratedServices.CategoryClient client = new Contents.GeneratedServices.CategoryClient("http://localhost:2003", new System.Net.Http.HttpClient());
// var categoryResult = await client.AddAsync(new Contents.GeneratedServices.CreateCategoryRequestContract()
// {
// Key = $"1-1-Title{Guid.NewGuid()}",
// UniqueIdentity = "1-2"
// });
// Assert.True(categoryResult.IsSuccess);
// Contents.GeneratedServices.ContentClient contentClient = new Contents.GeneratedServices.ContentClient("http://localhost:2003", new System.Net.Http.HttpClient());
// for (int i = 0; i < 5000; i++)
// {
// var contentResult = await contentClient.AddAsync(new Contents.GeneratedServices.CreateContentRequestContract()
// {
// CategoryId = categoryResult.Result,
// UniqueIdentity = "1-2",
// Data = i.ToString(),
// LanguageId = 1
// });
// Assert.True(contentResult.IsSuccess);
// }

// while (true)
// {
// GC.Collect();
// await Task.Delay(1000);
// }
//}

//[Fact]
//public async Task MemoryLeackTest()
//{
// HostApplicationBuilder builder = Host.CreateApplicationBuilder(null);
// UnitOfWork.DefaultUniqueIdentity = "1-1";
// UnitOfWork.MicroserviceId = 10;
// builder.Services.AddTransient<IEntityFrameworkCoreDatabaseBuilder, DatabaseBuilder>();
// builder.Services.AddTransient<RelationalCoreContext, ContentContext>();
// builder.Services.AddTransient<ContentContext>();
// //builder.Services.AddTransient<IUnitOfWork, UnitOfWork>();

// using IHost host = builder.Build();

// for (int i = 0; i < 5000; i++)
// {
// using var scope = host.Services.CreateScope();
// using var uow = scope.ServiceProvider.GetService<RelationalCoreContext>();
// //using var logic = uow.GetLongContractLogic<ContentEntity, CreateContentRequestContract, UpdateContentRequestContract, ContentContract>();
// }
//}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,32 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EasyMicroservices.Tests" Version="0.0.0.7" />
<None Remove="appsettings.json" />
</ItemGroup>

<ItemGroup>
<Content Include="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</Content>
</ItemGroup>

<ItemGroup>
<PackageReference Include="EasyMicroservices.ContentsMicroservice.Clients" Version="0.0.0.14" />
<PackageReference Include="EasyMicroservices.Tests" Version="0.0.0.9" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="xunit" Version="2.5.1" />
<PackageReference Include="xunit.runner.console" Version="2.5.0">
<PackageReference Include="xunit.runner.console" Version="2.5.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing">
<Version>7.0.11</Version>
</PackageReference>
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"local": "Server=testtt;Database=Contents;User ID=TrustServerCertificate=True;", // Test
},
"RootAddresses": {
"WhiteLabel": "http://localhost:1041"
},
"Urls": "http://*:2003"
}

0 comments on commit df54946

Please sign in to comment.