diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:34:30 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:34:30 +0000 |
commit | 4fc2f55f761d71aae1f145d5aa94ba929cc39676 (patch) | |
tree | 5c1e1db3b46dd4edbe11f612d93cb94b96891ce3 /test-connectionmanagement_hh.cc | |
parent | Initial commit. (diff) | |
download | dnsdist-4fc2f55f761d71aae1f145d5aa94ba929cc39676.tar.xz dnsdist-4fc2f55f761d71aae1f145d5aa94ba929cc39676.zip |
Adding upstream version 1.7.3.upstream/1.7.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test-connectionmanagement_hh.cc')
-rw-r--r-- | test-connectionmanagement_hh.cc | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/test-connectionmanagement_hh.cc b/test-connectionmanagement_hh.cc new file mode 100644 index 0000000..34432f2 --- /dev/null +++ b/test-connectionmanagement_hh.cc @@ -0,0 +1,93 @@ + +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_NO_MAIN + +#include <boost/test/unit_test.hpp> + +#include "connection-management.hh" + +BOOST_AUTO_TEST_SUITE(connectionmanagement_hh) + +BOOST_AUTO_TEST_CASE(test_ConnectionManagementEnabled) { + size_t maxConns = 10; + + ConcurrentConnectionManager manager(maxConns); + + for (size_t idx = 0; idx < maxConns; idx++) { + BOOST_CHECK_EQUAL(manager.registerConnection(), true); + } + + /* we are full */ + BOOST_CHECK_EQUAL(manager.registerConnection(), false); + + manager.releaseConnection(); + /* we can register one additional connection now that we released one */ + BOOST_CHECK_EQUAL(manager.registerConnection(), true); + /* but not two */ + BOOST_CHECK_EQUAL(manager.registerConnection(), false); + + /* raise the number of slots */ + maxConns = 12; + manager.setMaxConcurrentConnections(maxConns); + BOOST_CHECK_EQUAL(manager.registerConnection(), true); + BOOST_CHECK_EQUAL(manager.registerConnection(), true); + BOOST_CHECK_EQUAL(manager.registerConnection(), false); + + /* release everything */ + for (size_t idx = 0; idx < maxConns; idx++) { + manager.releaseConnection(); + } + + /* decrease the number of slots */ + maxConns = 2; + manager.setMaxConcurrentConnections(maxConns); + BOOST_CHECK_EQUAL(manager.registerConnection(), true); + BOOST_CHECK_EQUAL(manager.registerConnection(), true); + BOOST_CHECK_EQUAL(manager.registerConnection(), false); + + /* decrease the number of slots with some connections still registered */ + maxConns = 1; + manager.setMaxConcurrentConnections(maxConns); + + BOOST_CHECK_EQUAL(manager.registerConnection(), false); + for (size_t idx = 0; idx < 2; idx++) { + manager.releaseConnection(); + } + + BOOST_CHECK_EQUAL(manager.registerConnection(), true); + BOOST_CHECK_EQUAL(manager.registerConnection(), false); +} + +BOOST_AUTO_TEST_CASE(test_ConnectionManagementDisabledThenEnabled) { + /* 0 means no limit */ + size_t maxConns = 0; + ConcurrentConnectionManager manager(maxConns); + + for (size_t idx = 0; idx < 10; idx++) { + BOOST_CHECK_EQUAL(manager.registerConnection(), true); + } + + /* set a limit to 5 connections */ + maxConns = 5; + manager.setMaxConcurrentConnections(maxConns); + /* we can no longer register new sessions */ + BOOST_CHECK_EQUAL(manager.registerConnection(), false); + + /* release all of them */ + for (size_t idx = 0; idx < 10; idx++) { + manager.releaseConnection(); + } + + /* register as many as we now can */ + for (size_t idx = 0; idx < maxConns; idx++) { + BOOST_CHECK_EQUAL(manager.registerConnection(), true); + } + + BOOST_CHECK_EQUAL(manager.registerConnection(), false); + + manager.releaseConnection(); + + BOOST_CHECK_EQUAL(manager.registerConnection(), true); +} + +BOOST_AUTO_TEST_SUITE_END() |