mirror of https://github.com/abpframework/abp.git
committed by
GitHub
6 changed files with 167 additions and 8 deletions
@ -0,0 +1,96 @@ |
|||
using System; |
|||
using System.Diagnostics; |
|||
using System.Linq; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Shouldly; |
|||
using Volo.Abp.Domain.Repositories; |
|||
using Volo.Abp.TestApp.Domain; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.EntityFrameworkCore; |
|||
|
|||
public class AbpEfCoreNavigationHelper_Tests : EntityFrameworkCoreTestBase |
|||
{ |
|||
private readonly IRepository<Blog, Guid> _blogRepository; |
|||
|
|||
public AbpEfCoreNavigationHelper_Tests() |
|||
{ |
|||
_blogRepository = GetRequiredService<IRepository<Blog, Guid>>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Performance_Test() |
|||
{ |
|||
//These time taken varies on different machines.
|
|||
//I used relatively large values, but it can also check for performance problem.
|
|||
var batchUpdateTime = TimeSpan.FromSeconds(30); |
|||
var queryTime = TimeSpan.FromSeconds(10); |
|||
|
|||
if (!Environment.GetEnvironmentVariable("GITHUB_ACTIONS").IsNullOrWhiteSpace()) |
|||
{ |
|||
batchUpdateTime = batchUpdateTime * 6; |
|||
queryTime = queryTime * 6; |
|||
} |
|||
|
|||
|
|||
var stopWatch = Stopwatch.StartNew(); |
|||
await WithUnitOfWorkAsync(async () => |
|||
{ |
|||
for (var i = 0; i < 5 * 1000; i++) |
|||
{ |
|||
await _blogRepository.InsertAsync( |
|||
new Blog(Guid.NewGuid()) |
|||
{ |
|||
Name = "Blog" + i, |
|||
BlogPosts = |
|||
[ |
|||
new BlogPost(Guid.NewGuid()) |
|||
{ |
|||
Title = "Post" + i |
|||
} |
|||
] |
|||
}); |
|||
} |
|||
}); |
|||
stopWatch.Stop(); |
|||
stopWatch.Elapsed.ShouldBeLessThan(batchUpdateTime); |
|||
|
|||
|
|||
stopWatch.Restart(); |
|||
var blogs = await _blogRepository.GetListAsync(includeDetails: true); |
|||
blogs.Count.ShouldBe(5 * 1000); |
|||
blogs.SelectMany(x => x.BlogPosts).Count().ShouldBe(5 * 1000); |
|||
stopWatch.Stop(); |
|||
stopWatch.Elapsed.ShouldBeLessThan(queryTime); |
|||
|
|||
|
|||
var blogId = blogs.First().Id; |
|||
stopWatch.Restart(); |
|||
await WithUnitOfWorkAsync(async () => |
|||
{ |
|||
var blog = await _blogRepository.GetAsync(blogId); |
|||
blog.ShouldNotBeNull(); |
|||
for (var i = 0; i < 5 * 1000; i++) |
|||
{ |
|||
blog.BlogPosts.Add( |
|||
new BlogPost(Guid.NewGuid()) |
|||
{ |
|||
Title = "NewPost" + i |
|||
}); |
|||
} |
|||
await _blogRepository.UpdateAsync(blog); |
|||
}); |
|||
stopWatch.Stop(); |
|||
stopWatch.Elapsed.ShouldBeLessThan(batchUpdateTime); |
|||
|
|||
|
|||
var cancellationTokenSource = new CancellationTokenSource(); |
|||
cancellationTokenSource.CancelAfter(batchUpdateTime); |
|||
stopWatch.Restart(); |
|||
var blog = await _blogRepository.GetAsync(blogId, cancellationToken: cancellationTokenSource.Token); |
|||
blog.BlogPosts.Count.ShouldBe(5 * 1000 + 1); |
|||
stopWatch.Stop(); |
|||
stopWatch.Elapsed.ShouldBeLessThan(queryTime); |
|||
} |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using Volo.Abp.Domain.Entities; |
|||
using Volo.Abp.Domain.Entities.Auditing; |
|||
|
|||
namespace Volo.Abp.TestApp.Domain; |
|||
|
|||
public class Blog : FullAuditedAggregateRoot<Guid> |
|||
{ |
|||
public Blog(Guid id) |
|||
: base(id) |
|||
{ |
|||
} |
|||
|
|||
public string Name { get; set; } |
|||
|
|||
public List<BlogPost> BlogPosts { get; set; } |
|||
} |
|||
|
|||
public class BlogPost : Entity<Guid> |
|||
{ |
|||
public BlogPost(Guid id) |
|||
: base(id) |
|||
{ |
|||
} |
|||
|
|||
public Guid BlogId { get; set; } |
|||
public Blog Blog { get; set; } |
|||
|
|||
public string Title { get; set; } |
|||
} |
|||
Loading…
Reference in new issue