From 48b8e07a46bff81ebd92b7f3c900d05aeeec4d15 Mon Sep 17 00:00:00 2001 From: ph1 Date: Tue, 12 Oct 2021 09:29:34 -0600 Subject: [PATCH] test case --- pdns/dnsdistdist/test-dnsdistrules_cc.cc | 44 ++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/pdns/dnsdistdist/test-dnsdistrules_cc.cc b/pdns/dnsdistdist/test-dnsdistrules_cc.cc index 70ccbd0020..aed5ee4b53 100644 --- a/pdns/dnsdistdist/test-dnsdistrules_cc.cc +++ b/pdns/dnsdistdist/test-dnsdistrules_cc.cc @@ -7,6 +7,23 @@ #include "dnsdist-rules.hh" +static DNSQuestion getDQ(const DNSName* providedName = nullptr) +{ + static const DNSName qname("powerdns.com."); + static const ComboAddress lc("127.0.0.1:53"); + static const ComboAddress rem("192.0.2.1:42"); + static struct timespec queryRealTime; + static PacketBuffer packet(sizeof(dnsheader)); + + uint16_t qtype = QType::A; + uint16_t qclass = QClass::IN; + auto proto = dnsdist::Protocol::DoUDP; + gettime(&queryRealTime, true); + + DNSQuestion dq(providedName ? providedName : &qname, qtype, qclass, &lc, &rem, packet, proto, &queryRealTime); + return dq; +} + BOOST_AUTO_TEST_SUITE(dnsdistluarules_cc) BOOST_AUTO_TEST_CASE(test_MaxQPSIPRule) { @@ -101,5 +118,32 @@ BOOST_AUTO_TEST_CASE(test_MaxQPSIPRule) { BOOST_CHECK_EQUAL(scanned, 0U); } +BOOST_AUTO_TEST_CASE(test_poolOutstandingRule) { + auto dq = getDQ(); + + ServerPool sp{}; + auto ds1 = std::make_shared(ComboAddress("192.0.2.1:53")); + auto ds2 = std::make_shared(ComboAddress("192.0.2.2:53")); + + /* increase the outstanding count of both */ + ds1->outstanding = 400; + ds2->outstanding = 30; + + sp.addServer(ds1); + sp.addServer(ds2); + + BOOST_CHECK_EQUAL(sp.poolLoad(), 400+30); + + auto localPool = g_pools.getCopy(); + addServerToPool(localPool, "test", ds1); + addServerToPool(localPool, "test", ds2); + g_pools.setState(localPool); + + PoolOutstandingRule pOR1("test", 10); + BOOST_CHECK_EQUAL(pOR1.matches(&dq), true); + + PoolOutstandingRule pOR2("test", 1000); + BOOST_CHECK_EQUAL(pOR2.matches(&dq), false); +} BOOST_AUTO_TEST_SUITE_END() -- 2.47.2