@@ -50,7 +50,7 @@ public void Add_String_Smaller_Than_Page_Succeeds(int pageSize)
5050 using var pool = StringPool . Utf8 ( pageSize , 1 ) ;
5151 Assert . Equal ( 0 , pool . UsedBytes ) ;
5252 Assert . Equal ( pageSize , pool . AllocatedBytes ) ;
53- var someString = new string ( 'c' , pageSize - 2 ) ;
53+ var someString = new string ( 'c' , TestSupport . GetMaxStringSizeForAllocation ( pageSize ) ) ;
5454 var pooledString = pool . Add ( someString ) ;
5555 Assert . Equal ( pageSize , pool . UsedBytes ) ;
5656 Assert . Equal ( pageSize , pool . AllocatedBytes ) ;
@@ -69,7 +69,7 @@ public void Add_String_Larger_Than_Page_Fails(int pageSize)
6969 using var pool = StringPool . Utf8 ( pageSize , 1 ) ;
7070 Assert . Equal ( 0 , pool . UsedBytes ) ;
7171 Assert . Equal ( pageSize , pool . AllocatedBytes ) ;
72- var someString = new string ( 'c' , pageSize - 1 ) ;
72+ var someString = new string ( 'c' , TestSupport . GetMaxStringSizeForAllocation ( pageSize ) + 1 ) ;
7373 var exception = Assert . Throws < ArgumentOutOfRangeException > ( ( ) => pool . Add ( someString ) ) ;
7474 Assert . Contains ( "String is too long to be pooled" , exception . Message ) ;
7575 }
@@ -86,13 +86,13 @@ public void Two_Strings_Fit_Same_Page(int pageSize)
8686 using var pool = StringPool . Utf8 ( pageSize , 1 ) ;
8787 Assert . Equal ( 0 , pool . UsedBytes ) ;
8888 Assert . Equal ( pageSize , pool . AllocatedBytes ) ;
89- var string1 = new string ( 'c' , ( pageSize / 2 ) - 2 ) ;
89+ var string1 = new string ( 'c' , TestSupport . GetMaxStringSizeForAllocation ( pageSize / 2 ) ) ;
9090 var pooledString1 = pool . Add ( string1 ) ;
9191 Assert . Equal ( pageSize / 2 , pool . UsedBytes ) ;
9292 Assert . Equal ( pageSize , pool . AllocatedBytes ) ;
93- var string2 = new string ( 'd' , pageSize - ( pageSize / 2 ) - 2 ) ;
93+ var string2 = new string ( 'd' , TestSupport . GetMaxStringSizeForAllocation ( pageSize / 2 ) ) ;
9494 var pooledString2 = pool . Add ( string2 ) ;
95- Assert . Equal ( pageSize , pool . UsedBytes ) ;
95+ Assert . InRange ( pool . UsedBytes , pageSize - 1 , pageSize ) ;
9696 Assert . Equal ( pageSize , pool . AllocatedBytes ) ;
9797 Assert . Equal ( string1 , ( string ) pooledString1 ) ;
9898 Assert . Equal ( string2 , ( string ) pooledString2 ) ;
@@ -107,17 +107,17 @@ public void Two_Strings_Fit_Same_Page(int pageSize)
107107 [ InlineData ( 65535 ) ]
108108 public void Two_Strings_Dont_Fit_Need_More_Space ( int pageSize )
109109 {
110- var stringSize = ( pageSize / 2 ) - 1 ;
110+ var stringSize = TestSupport . GetMaxStringSizeForAllocation ( pageSize / 2 ) + 1 ;
111111 using var pool = StringPool . Utf8 ( pageSize , 1 ) ;
112112 Assert . Equal ( 0 , pool . UsedBytes ) ;
113113 Assert . Equal ( pageSize , pool . AllocatedBytes ) ;
114114 var string1 = new string ( 'c' , stringSize ) ;
115115 var pooledString1 = pool . Add ( string1 ) ;
116- Assert . Equal ( stringSize + 2 , pool . UsedBytes ) ;
116+ Assert . Equal ( TestSupport . GetAllocationSize ( stringSize ) , pool . UsedBytes ) ;
117117 Assert . Equal ( pageSize , pool . AllocatedBytes ) ;
118118 var string2 = new string ( 'd' , stringSize ) ;
119119 var pooledString2 = pool . Add ( string2 ) ;
120- Assert . Equal ( ( 2 * stringSize ) + 4 , pool . UsedBytes ) ;
120+ Assert . Equal ( 2 * TestSupport . GetAllocationSize ( stringSize ) , pool . UsedBytes ) ;
121121 Assert . Equal ( 2 * pageSize , pool . AllocatedBytes ) ;
122122 Assert . Equal ( string1 , ( string ) pooledString1 ) ;
123123 Assert . Equal ( stringSize , pooledString1 . Length ) ;
@@ -269,7 +269,7 @@ public void Add_Deduplicated_Thread_Safe(int numThreads, int numPages)
269269 for ( var i = 0 ; ! stopped ; ++ i )
270270 {
271271 var str = pool . Add ( "foobar " + ( i % 1000 ) ) ;
272- Interlocked . Add ( ref stringSum , 2 + str . ToString ( ) . Length ) ;
272+ Interlocked . Add ( ref stringSum , TestSupport . GetAllocationSize ( str . ToString ( ) . Length ) ) ;
273273 if ( i == 10000 )
274274 {
275275 Interlocked . Increment ( ref numStarted ) ;
@@ -300,7 +300,7 @@ public void Add_Deduplicated_Thread_Safe(int numThreads, int numPages)
300300 var sum = 0L ;
301301 for ( var i = 0 ; i < 1000 ; ++ i )
302302 {
303- var len = 2 + ( "foobar " + i ) . Length ;
303+ var len = TestSupport . GetAllocationSize ( ( "foobar " + i ) . Length ) ;
304304 sum += len ;
305305 }
306306
0 commit comments