@@ -84,6 +84,8 @@ async_test!(test_journal_mode);
8484async_test ! ( test_concurrency) ;
8585async_test ! ( test_pool) ;
8686async_test ! ( test_pool_conn_for_each) ;
87+ async_test ! ( test_pool_close_concurrent) ;
88+ async_test ! ( test_pool_num_conns_zero_clamps) ;
8789
8890async fn test_journal_mode ( ) {
8991 let tmp_dir = tempfile:: tempdir ( ) . unwrap ( ) ;
@@ -227,3 +229,36 @@ async fn test_pool_conn_for_each() {
227229 // cleanup
228230 pool. close ( ) . await . expect ( "closing client conn" ) ;
229231}
232+
233+ async fn test_pool_close_concurrent ( ) {
234+ let tmp_dir = tempfile:: tempdir ( ) . unwrap ( ) ;
235+ let pool = PoolBuilder :: new ( )
236+ . path ( tmp_dir. path ( ) . join ( "sqlite.db" ) )
237+ . num_conns ( 2 )
238+ . open ( )
239+ . await
240+ . expect ( "pool unable to be opened" ) ;
241+
242+ let c1 = pool. close ( ) ;
243+ let c2 = pool. close ( ) ;
244+ futures_util:: future:: join_all ( [ c1, c2] )
245+ . await
246+ . into_iter ( )
247+ . collect :: < Result < Vec < _ > , Error > > ( )
248+ . expect ( "closing concurrently" ) ;
249+
250+ let res = pool. conn ( |c| c. execute ( "SELECT 1" , ( ) ) ) . await ;
251+ assert ! ( matches!( res, Err ( Error :: Closed ) ) ) ;
252+ }
253+
254+ async fn test_pool_num_conns_zero_clamps ( ) {
255+ let tmp_dir = tempfile:: tempdir ( ) . unwrap ( ) ;
256+ let pool = PoolBuilder :: new ( )
257+ . path ( tmp_dir. path ( ) . join ( "clamp.db" ) )
258+ . num_conns ( 0 )
259+ . open ( )
260+ . await
261+ . expect ( "pool unable to be opened" ) ;
262+ let results = pool. conn_for_each ( |_| Ok ( ( ) ) ) . await ;
263+ assert_eq ! ( results. len( ) , 1 ) ;
264+ }
0 commit comments