Skip to content

Commit af85a17

Browse files
mschoenlaubhanumantmk
authored andcommitted
Adds a test for the disposal of old connections from the connection pool
1 parent e5deba5 commit af85a17

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

tests/test-mongoc-client-pool.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#include <mongoc.h>
2+
#include "mongoc-array-private.h"
3+
24

35
#include "TestSuite.h"
46

@@ -37,10 +39,44 @@ test_mongoc_client_pool_try_pop (void)
3739
mongoc_client_pool_destroy(pool);
3840
}
3941

42+
static void
43+
test_mongoc_client_pool_min_size_dispose (void)
44+
{
45+
mongoc_client_pool_t *pool;
46+
mongoc_client_t *client;
47+
mongoc_uri_t *uri;
48+
mongoc_array_t conns;
49+
int i;
50+
51+
_mongoc_array_init(&conns, sizeof client);
52+
53+
uri = mongoc_uri_new("mongodb://127.0.0.1?maxpoolsize=10&minpoolsize=3");
54+
pool = mongoc_client_pool_new(uri);
55+
56+
for (i = 0; i < 10; i++) {
57+
client = mongoc_client_pool_pop(pool);
58+
assert(client);
59+
_mongoc_array_append_val(&conns, client);
60+
assert(mongoc_client_pool_get_size(pool) == i+1);
61+
}
62+
63+
for (i = 0; i < 10; i++) {
64+
client = _mongoc_array_index(&conns,mongoc_client_t *, i);
65+
assert(client);
66+
mongoc_client_pool_push(pool, client);
67+
}
68+
69+
assert(mongoc_client_pool_get_size(pool) == 3);
70+
_mongoc_array_clear(&conns);
71+
_mongoc_array_destroy(&conns);
72+
mongoc_uri_destroy(uri);
73+
mongoc_client_pool_destroy(pool);
74+
}
4075

4176
void
4277
test_client_pool_install (TestSuite *suite)
4378
{
4479
TestSuite_Add (suite, "/ClientPool/basic", test_mongoc_client_pool_basic);
4580
TestSuite_Add (suite, "/ClientPool/try_pop", test_mongoc_client_pool_try_pop);
81+
TestSuite_Add (suite, "/ClientPool/min_size_dispose", test_mongoc_client_pool_min_size_dispose);
4682
}

0 commit comments

Comments
 (0)