diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 21:11:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 21:11:59 +0000 |
commit | 3cd01b932e1c85394272ae64fae67ebeda92fb00 (patch) | |
tree | c5a3115d710afc1879ddea5349362a2bc651733c /test-delaypipe_hh.cc | |
parent | Initial commit. (diff) | |
download | dnsdist-3cd01b932e1c85394272ae64fae67ebeda92fb00.tar.xz dnsdist-3cd01b932e1c85394272ae64fae67ebeda92fb00.zip |
Adding upstream version 1.8.3.upstream/1.8.3
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(); |