@@ -166,14 +166,14 @@ public void Ping()
166166	} 
167167
168168	[ Fact ] 
169- 	public  void  PingWhenClosed ( ) 
169+ 	public  void  PingWhenReset ( ) 
170170	{ 
171171		using  var  connection  =  new  MySqlConnection ( m_csb . ConnectionString ) ; 
172172		connection . Open ( ) ; 
173173		Assert . Equal ( ConnectionState . Open ,  connection . State ) ; 
174- 		m_server . Stop ( ) ; 
174+ 		m_server . Reset ( ) ; 
175175		Assert . False ( connection . Ping ( ) ) ; 
176- 		Assert . Equal ( ConnectionState . Closed ,  connection . State ) ; 
176+ 		Assert . Equal ( ConnectionState . Broken ,  connection . State ) ; 
177177	} 
178178
179179	[ Fact ] 
@@ -277,6 +277,72 @@ public void ReplaceActiveReader()
277277		connection . Close ( ) ; 
278278	} 
279279
280+ 	[ Fact ] 
281+ 	public  async  Task  ResetServerConnectionWhileOpen ( ) 
282+ 	{ 
283+ 		var  csb  =  new  MySqlConnectionStringBuilder ( m_csb . ConnectionString ) 
284+ 		{ 
285+ 			MaximumPoolSize  =  5 , 
286+ 			ConnectionTimeout  =  5 , 
287+ 		} ; 
288+ 289+ 		List < Task >  tasks  =  [ ] ; 
290+ 		using  var  barrier  =  new  Barrier ( ( int )  csb . MaximumPoolSize ) ; 
291+ 		for  ( var  i  =  0 ;  i  <  csb . MaximumPoolSize  -  1 ;  i ++ ) 
292+ 		{ 
293+ 			var  threadId  =  i ; 
294+ 			tasks . Add ( Task . Run ( async  ( )  => 
295+ 			{ 
296+ 				using  var  connection  =  new  MySqlConnection ( csb . ConnectionString ) ; 
297+ 				await  connection . OpenAsync ( ) . ConfigureAwait ( false ) ; 
298+ 299+ 				barrier . SignalAndWait ( ) ; 
300+ 				//// wait for reset 
301+ 				barrier . SignalAndWait ( ) ; 
302+ 303+ 				switch  ( threadId  %  3 ) 
304+ 				{ 
305+ 					case  0 : 
306+ 					{ 
307+ 						using  ( var  command  =  connection . CreateCommand ( ) ) 
308+ 						{ 
309+ 							command . CommandText  =  "SELECT 1;" ; 
310+ 							var  exception  =  Assert . Throws < MySqlException > ( ( )  =>  command . ExecuteScalar ( ) ) ; 
311+ 							Assert . Equal ( "Failed to read the result set." ,  exception . Message ) ; 
312+ 						} 
313+ 						break ; 
314+ 					} 
315+ 					case  1 : 
316+ 					{ 
317+ 						// NOTE: duplicate of PingWhenReset, but included here for completeness 
318+ 						var  ping  =  await  connection . PingAsync ( ) . ConfigureAwait ( false ) ; 
319+ 						Assert . False ( ping ) ; 
320+ 						break ; 
321+ 					} 
322+ 					case  2 : 
323+ 					{ 
324+ 						await  Assert . ThrowsAnyAsync < Exception > ( async  ( )  =>  await  connection . ResetConnectionAsync ( ) . ConfigureAwait ( false ) ) ; 
325+ 						break ; 
326+ 					} 
327+ 				} 
328+ 329+ 				Assert . Equal ( ConnectionState . Broken ,  connection . State ) ; 
330+ 331+ 				await  connection . CloseAsync ( ) . ConfigureAwait ( false ) ; 
332+ 				Assert . Equal ( ConnectionState . Closed ,  connection . State ) ; 
333+ 334+ 				await  connection . OpenAsync ( ) . ConfigureAwait ( false ) ; 
335+ 				Assert . Equal ( ConnectionState . Open ,  connection . State ) ; 
336+ 			} ) ) ; 
337+ 		} 
338+ 339+ 		barrier . SignalAndWait ( ) ; 
340+ 		m_server . Reset ( ) ; 
341+ 		barrier . SignalAndWait ( ) ; 
342+ 343+ 		await  Task . WhenAll ( tasks ) ; 
344+ 	} 
345+ 280346	private  static   async  Task  WaitForConditionAsync < T > ( T  expected ,  Func < T >  getValue ) 
281347	{ 
282348		var  sw  =  Stopwatch . StartNew ( ) ; 
0 commit comments