File tree Expand file tree Collapse file tree
src/EntityFrameworkCore.SqlServer.SimpleBulks.Tests/DbContextExtensions Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -51,4 +51,31 @@ public void GetProperties_ShouldReturnFromCache()
5151 // Assert
5252 Assert . Equal ( properties1 , properties2 ) ;
5353 }
54+
55+ [ Fact ]
56+ public async Task GetProperties_MultiThreads_ShoudReturnFromCache ( )
57+ {
58+ // Arrange && Act
59+ var tasks = new List < Task < IList < ColumnInfor > > > ( ) ;
60+ for ( int i = 0 ; i < 100 ; i ++ )
61+ {
62+ tasks . Add ( Task . Run ( ( ) =>
63+ {
64+ using var dbct = new TestDbContext ( "" , "" ) ;
65+ return dbct . GetProperties ( typeof ( ConfigurationEntry ) ) ;
66+ } ) ) ;
67+ }
68+
69+ await Task . WhenAll ( tasks . ToArray ( ) ) ;
70+
71+ var dbContext = new TestDbContext ( "" , "" ) ;
72+
73+ var properties = dbContext . GetProperties ( typeof ( ConfigurationEntry ) ) ;
74+
75+ foreach ( var task in tasks )
76+ {
77+ // Assert
78+ Assert . Equal ( properties , task . Result ) ;
79+ }
80+ }
5481}
Original file line number Diff line number Diff line change @@ -32,4 +32,31 @@ public void GetTableInfor_ReturnsFromCache()
3232 // Assert
3333 Assert . Equal ( tableInfor1 , tableInfor2 ) ;
3434 }
35+
36+ [ Fact ]
37+ public async Task GetTableInfor_MultiThreads_ShoudReturnFromCache ( )
38+ {
39+ // Arrange && Act
40+ var tasks = new List < Task < TableInfor > > ( ) ;
41+ for ( int i = 0 ; i < 100 ; i ++ )
42+ {
43+ tasks . Add ( Task . Run ( ( ) =>
44+ {
45+ using var dbct = new TestDbContext ( "" , "" ) ;
46+ return dbct . GetTableInfor ( typeof ( ConfigurationEntry ) ) ;
47+ } ) ) ;
48+ }
49+
50+ await Task . WhenAll ( tasks . ToArray ( ) ) ;
51+
52+ var dbContext = new TestDbContext ( "" , "" ) ;
53+
54+ var tableInfor = dbContext . GetTableInfor ( typeof ( ConfigurationEntry ) ) ;
55+
56+ foreach ( var task in tasks )
57+ {
58+ // Assert
59+ Assert . Equal ( tableInfor , task . Result ) ;
60+ }
61+ }
3562}
You can’t perform that action at this time.
0 commit comments