]>
git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/test-distributor_hh.cc
1 #define BOOST_TEST_DYN_LINK
2 #define BOOST_TEST_NO_MAIN
8 #include <boost/test/unit_test.hpp>
9 #include "distributor.hh"
10 #include "dnspacket.hh"
11 #include "namespaces.hh"
13 BOOST_AUTO_TEST_SUITE(test_distributor_hh
)
20 DNSPacket
* replyPacket()
22 return new DNSPacket();
28 DNSPacket
* question(Question
*)
30 return new DNSPacket();
34 static std::atomic
<int> g_receivedAnswers
;
35 static void report(DNSPacket
* A
)
41 BOOST_AUTO_TEST_CASE(test_distributor_basic
) {
42 ::arg().set("overload-queue-length","Maximum queuelength moving to packetcache only")="0";
43 ::arg().set("max-queue-length","Maximum queuelength before considering situation lost")="5000";
44 ::arg().set("queue-limit","Maximum number of milliseconds to queue a query")="1500";
45 S
.declare("servfail-packets","Number of times a server-failed packet was sent out");
46 S
.declare("timedout-packets", "timedout-packets");
48 auto d
=Distributor
<DNSPacket
, Question
, Backend
>::Create(2);
51 for(n
=0; n
< 100; ++n
) {
52 auto q
= new Question();
54 d
->question(q
, report
);
57 BOOST_CHECK_EQUAL(n
, g_receivedAnswers
);
62 DNSPacket
* question(Question
*)
65 return new DNSPacket();
70 BOOST_AUTO_TEST_CASE(test_distributor_queue
) {
71 auto d
=Distributor
<DNSPacket
, Question
, BackendSlow
>::Create(2);
73 BOOST_CHECK_EXCEPTION( {
75 for(n
=0; n
< 6000; ++n
) {
76 auto q
= new Question();
78 d
->question(q
, report
);
80 }, DistributorFatal
, [](DistributorFatal
) { return true; });
92 DNSPacket
* question(Question
* q
)
94 // cout<<"Q: "<<q->qdomain<<endl;
95 if(!d_ourcount
&& ++d_count
== 10) {
96 // cerr<<"Going.. down!"<<endl;
97 throw runtime_error("kill");
99 return new DNSPacket();
101 static std::atomic
<int> s_count
;
106 std::atomic
<int> BackendDies::s_count
;
108 std::atomic
<int> g_receivedAnswers2
;
110 static void report2(DNSPacket
* A
)
113 g_receivedAnswers2
++;
117 BOOST_AUTO_TEST_CASE(test_distributor_dies
) {
118 auto d
=Distributor
<DNSPacket
, Question
, BackendDies
>::Create(10);
123 for(int n
=0; n
< 100; ++n
) {
124 auto q
= new Question();
126 q
->qdomain
=std::to_string(n
);
127 d
->question(q
, report2
);
131 cerr
<<"Queued: "<<d
->getQueueSize()<<endl
;
132 cerr
<<"Received: "<<g_receivedAnswers2
<<endl
;
134 catch(std::exception
& e
) {
135 cerr
<<e
.what()<<endl
;
137 catch(PDNSException
&pe
) {
138 cerr
<<pe
.reason
<<endl
;
144 BOOST_AUTO_TEST_SUITE_END();