@@ -79,47 +79,59 @@ test_mongoc_client_pool_min_size_dispose (void)
7979 mongoc_client_pool_t * pool ;
8080 mongoc_client_t * client ;
8181 mongoc_uri_t * uri ;
82- mongoc_array_t conns ;
83- int i ;
82+ mongoc_client_t * c0 , * c1 , * c2 , * c3 ;
8483
85- _mongoc_array_init (& conns , sizeof client );
86-
87- uri = mongoc_uri_new ("mongodb://127.0.0.1?maxpoolsize=10&minpoolsize=3" );
84+ uri = mongoc_uri_new ("mongodb://127.0.0.1?minpoolsize=2" );
8885 pool = mongoc_client_pool_new (uri );
8986
90- for (i = 0 ; i < 10 ; i ++ ) {
91- client = mongoc_client_pool_pop (pool );
92- assert (client );
93- _mongoc_array_append_val (& conns , client );
94- assert (mongoc_client_pool_get_size (pool ) == i + 1 );
95- }
87+ c0 = mongoc_client_pool_pop (pool );
88+ assert (c0 );
89+ ASSERT_CMPSIZE_T (mongoc_client_pool_get_size (pool ), = = , (size_t ) 1 );
9690
97- for (i = 0 ; i < 10 ; i ++ ) {
98- client = _mongoc_array_index (& conns , mongoc_client_t * , i );
99- assert (client );
100- mongoc_client_pool_push (pool , client );
101- }
91+ c1 = mongoc_client_pool_pop (pool );
92+ assert (c1 );
93+ ASSERT_CMPSIZE_T (mongoc_client_pool_get_size (pool ), = = , (size_t ) 2 );
10294
103- assert (mongoc_client_pool_get_size (pool ) == 3 );
95+ c2 = mongoc_client_pool_pop (pool );
96+ assert (c2 );
97+ ASSERT_CMPSIZE_T (mongoc_client_pool_get_size (pool ), = = , (size_t ) 3 );
10498
105- /* assert oldest clients were destroyed, newest were stored */
106- for (i = 9 ; i >= 7 ; i -- ) {
107- client = mongoc_client_pool_pop (pool );
108- assert (client );
109- assert (client == _mongoc_array_index (& conns , mongoc_client_t * , i ));
110- }
99+ c3 = mongoc_client_pool_pop (pool );
100+ assert (c3 );
101+ ASSERT_CMPSIZE_T (mongoc_client_pool_get_size (pool ), = = , (size_t ) 4 );
111102
112- /* clean up */
113- for (i = 7 ; i < 10 ; i ++ ) {
114- client = _mongoc_array_index (& conns , mongoc_client_t * , i );
115- assert (client );
116- mongoc_client_pool_push (pool , client );
117- }
103+ mongoc_client_pool_push (pool , c0 ); /* queue is [c0] */
104+ ASSERT_CMPSIZE_T (mongoc_client_pool_num_pushed (pool ), = = , (size_t ) 1 );
105+ ASSERT_CMPSIZE_T (mongoc_client_pool_get_size (pool ), = = , (size_t ) 4 );
118106
119- _mongoc_array_clear (& conns );
120- _mongoc_array_destroy (& conns );
121- mongoc_uri_destroy (uri );
107+ mongoc_client_pool_push (pool , c1 ); /* queue is [c1, c0] */
108+ ASSERT_CMPSIZE_T (mongoc_client_pool_num_pushed (pool ), = = , (size_t ) 2 );
109+ ASSERT_CMPSIZE_T (mongoc_client_pool_get_size (pool ), = = , (size_t ) 4 );
110+
111+ mongoc_client_pool_push (pool , c2 ); /* queue is [c2, c1] */
112+ ASSERT_CMPSIZE_T (mongoc_client_pool_num_pushed (pool ), = = , (size_t ) 2 );
113+ ASSERT_CMPSIZE_T (mongoc_client_pool_get_size (pool ), = = , (size_t ) 3 );
114+
115+ mongoc_client_pool_push (pool , c3 ); /* queue is [c3, c2] */
116+ ASSERT_CMPSIZE_T (mongoc_client_pool_num_pushed (pool ), = = , (size_t ) 2 );
117+ ASSERT_CMPSIZE_T (mongoc_client_pool_get_size (pool ), = = , (size_t ) 2 );
118+
119+ /* assert oldest client was destroyed, newest were stored */
120+ client = mongoc_client_pool_pop (pool );
121+ assert (client );
122+ assert (client == c3 );
123+
124+ client = mongoc_client_pool_pop (pool );
125+ assert (client );
126+ assert (client == c2 );
127+
128+ ASSERT_CMPSIZE_T (mongoc_client_pool_get_size (pool ), = = , (size_t ) 2 );
129+
130+ /* clean up */
131+ mongoc_client_pool_push (pool , c2 );
132+ mongoc_client_pool_push (pool , c3 );
122133 mongoc_client_pool_destroy (pool );
134+ mongoc_uri_destroy (uri );
123135}
124136
125137static void
0 commit comments