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-delaypipe_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-delaypipe_hh.cc')
-rw-r--r-- | test-delaypipe_hh.cc | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/test-delaypipe_hh.cc b/test-delaypipe_hh.cc new file mode 100644 index 0000000..9e678ee --- /dev/null +++ b/test-delaypipe_hh.cc @@ -0,0 +1,80 @@ +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_NO_MAIN +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#include <boost/test/unit_test.hpp> +#include "delaypipe.hh" + +BOOST_AUTO_TEST_SUITE(test_delaypipe_hh); + +BOOST_AUTO_TEST_CASE(test_object_pipe) { + ObjectPipe<int> op; + for(int n=0; n < 100; ++n) + op.write(n); + + int i; + for(int n=0; n < 100; ++n) { + int res=op.readTimeout(&i, -1); + BOOST_CHECK_EQUAL(res, 1); + BOOST_CHECK_EQUAL(n, i); + } + + op.close(); + BOOST_CHECK_EQUAL(op.readTimeout(&i, 1), 0); + +}; + +std::atomic<int> done = 0; +BOOST_AUTO_TEST_CASE(test_delay_pipe_small) { + done = 0; + struct Work + { + int i; + void operator()() + { + ++done; + } + }; + DelayPipe<Work> dp; + int n; + for(n=0; n < 5; ++n) { + Work w{n}; + dp.submit(w, 500); + } + BOOST_CHECK_EQUAL(done, 0); + + for(; n < 10; ++n) { + Work w{n}; + dp.submit(w, 1200); + } + sleep(1); + BOOST_CHECK_EQUAL(done, 5); + sleep(1); + BOOST_CHECK_EQUAL(done, n); + +}; + +BOOST_AUTO_TEST_CASE(test_delay_pipe_big) { + done=0; + struct Work + { + int i; + void operator()() + { + ++done; + } + }; + DelayPipe<Work> dp; + int n; + for(n=0; n < 1000000; ++n) { + Work w{n}; + dp.submit(w, 100); + } + + sleep(1); + BOOST_CHECK_EQUAL(done, n); +}; + + +BOOST_AUTO_TEST_SUITE_END(); |