]>
git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/test-distributor_hh.cc
1 #ifndef BOOST_TEST_DYN_LINK
2 #define BOOST_TEST_DYN_LINK
5 #define BOOST_TEST_NO_MAIN
11 #include <boost/test/unit_test.hpp>
12 #include "distributor.hh"
13 #include "dnspacket.hh"
14 #include "namespaces.hh"
16 bool g_doGssTSIG
= false;
18 BOOST_AUTO_TEST_SUITE(test_distributor_hh
)
26 std::unique_ptr
<DNSPacket
> replyPacket()
28 return make_unique
<DNSPacket
>(false);
30 void cleanupGSS(int){}
35 std::unique_ptr
<DNSPacket
> question(Question
&)
37 return make_unique
<DNSPacket
>(true);
41 static std::atomic
<int> g_receivedAnswers
;
42 static void report(std::unique_ptr
<DNSPacket
>& /* A */, int /* B */)
47 BOOST_AUTO_TEST_CASE(test_distributor_basic
) {
48 ::arg().set("overload-queue-length","Maximum queuelength moving to packetcache only")="0";
49 ::arg().set("max-queue-length","Maximum queuelength before considering situation lost")="5000";
50 ::arg().set("queue-limit","Maximum number of milliseconds to queue a query")="1500";
51 S
.declare("servfail-packets","Number of times a server-failed packet was sent out");
52 S
.declare("timedout-packets", "timedout-packets");
54 auto d
=Distributor
<DNSPacket
, Question
, Backend
>::Create(2);
57 for(n
=0; n
< 100; ++n
) {
60 d
->question(q
, report
);
63 BOOST_CHECK_EQUAL(n
, g_receivedAnswers
);
68 std::unique_ptr
<DNSPacket
> question(Question
&)
71 return make_unique
<DNSPacket
>(true);
75 static std::atomic
<int> g_receivedAnswers1
;
76 static void report1(std::unique_ptr
<DNSPacket
>& /* A */, int /* B */)
81 BOOST_AUTO_TEST_CASE(test_distributor_queue
) {
82 ::arg().set("overload-queue-length","Maximum queuelength moving to packetcache only")="0";
83 ::arg().set("max-queue-length","Maximum queuelength before considering situation lost")="1000";
84 ::arg().set("queue-limit","Maximum number of milliseconds to queue a query")="1500";
85 S
.declare("servfail-packets","Number of times a server-failed packet was sent out");
86 S
.declare("timedout-packets", "timedout-packets");
88 auto d
=Distributor
<DNSPacket
, Question
, BackendSlow
>::Create(2);
90 BOOST_CHECK_EXCEPTION( {
92 // bound should be higher than max-queue-length
93 for(n
=0; n
< 2000; ++n
) {
96 d
->question(q
, report1
);
98 }, DistributorFatal
, [](DistributorFatal
) { return true; });
105 d_ourcount
=s_count
++;
110 std::unique_ptr
<DNSPacket
> question(Question
& /* q */)
112 // cout<<"Q: "<<q->qdomain<<endl;
113 if(!d_ourcount
&& ++d_count
== 10) {
114 // cerr<<"Going.. down!"<<endl;
115 throw runtime_error("kill");
117 return make_unique
<DNSPacket
>(true);
119 static std::atomic
<int> s_count
;
124 std::atomic
<int> BackendDies::s_count
;
126 std::atomic
<int> g_receivedAnswers2
;
128 static void report2(std::unique_ptr
<DNSPacket
>& /* A */, int /* B */)
130 g_receivedAnswers2
++;
134 BOOST_AUTO_TEST_CASE(test_distributor_dies
) {
135 ::arg().set("overload-queue-length","Maximum queuelength moving to packetcache only")="0";
136 ::arg().set("max-queue-length","Maximum queuelength before considering situation lost")="5000";
137 ::arg().set("queue-limit","Maximum number of milliseconds to queue a query")="1500";
138 S
.declare("servfail-packets","Number of times a server-failed packet was sent out");
139 S
.declare("timedout-packets", "timedout-packets");
141 auto d
=Distributor
<DNSPacket
, Question
, BackendDies
>::Create(10);
144 for(int n
=0; n
< 100; ++n
) {
147 q
.qdomain
=DNSName(std::to_string(n
));
148 q
.qtype
= QType(QType::A
);
149 d
->question(q
, report2
);
153 cerr
<<"Queued: "<<d
->getQueueSize()<<endl
;
154 cerr
<<"Received: "<<g_receivedAnswers2
<<endl
;
156 catch(std::exception
& e
) {
157 cerr
<<e
.what()<<endl
;
159 catch(PDNSException
&pe
) {
160 cerr
<<pe
.reason
<<endl
;
166 BOOST_AUTO_TEST_SUITE_END();